4 * Copyright (C) 2008 Adam Williams <broadcast at earthling dot net>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #include "bcdisplayinfo.h"
26 #include "scaleratio.h"
27 #include "scaleratiowin.h"
31 ScaleRatioWin::ScaleRatioWin(ScaleRatioMain *client)
32 : PluginClientWindow(client, xS(400), yS(320), xS(400), yS(320), 0)
34 this->client = client;
37 ScaleRatioWin::~ScaleRatioWin()
41 void ScaleRatioWin::create_objects()
43 int xs10 = xS(10), xs50 = xS(50);
44 int ys5 = yS(5), ys8 = yS(8), ys10 = yS(10), ys30 = yS(30);
45 int x = xs10, y = ys10;
46 int x0 = x, x1 = x0 + xs50;
48 client->load_configuration();
50 add_tool(new BC_Title(x0, y0, _("In R:")));
51 add_tool(in_r = new ScaleRatioRatio(this, client, x1, y0, &client->config.in_r));
52 in_r->create_objects();
53 y0 += in_r->get_th() + ys10;
55 add_tool(new BC_Title(x0, y0, _("In W:")));
56 in_w = new ScaleRatioCoord(this, client, x1, y0, 0, &client->config.in_w);
57 in_w->create_objects();
58 y0 += in_w->get_h() + ys8;
60 add_tool(new BC_Title(x0, y0, _("In H:")));
61 in_h = new ScaleRatioCoord(this, client, x1, y0, 0, &client->config.in_h);
62 in_h->create_objects();
64 x0 = get_w()/2; y0 = y;
67 add_tool(new BC_Title(x0, y0, _("Out R:")));
68 add_tool(out_r = new ScaleRatioRatio(this, client, x1, y0, &client->config.out_r));
69 out_r->create_objects();
70 y0 += out_r->get_th() + ys10;
72 add_tool(new BC_Title(x0, y0, _("Out W:")));
73 out_w = new ScaleRatioCoord(this, client, x1, y0, 0, &client->config.out_w);
74 out_w->create_objects();
75 y0 += out_w->get_h() + ys8;
77 add_tool(new BC_Title(x0, y0, _("Out H:")));
78 out_h = new ScaleRatioCoord(this, client, x1, y0, 0, &client->config.out_h);
79 out_h->create_objects();
80 y0 += out_h->get_h() + ys8;
83 add_tool(apply_button = new ScaleRatioApply(this, x, y));
84 int x2 = x + apply_button->get_w() + xs50;
85 add_tool(type_popup = new ScaleRatioType(this, x2, y, &client->config.type));
86 type_popup->create_objects();
87 y += apply_button->get_h() + ys30;
92 add_tool(new BC_Title(x0, y0, _("Src X:")));
93 src_x = new ScaleRatioCoord(this, client, x1, y0, 1, &client->config.src_x);
94 src_x->create_objects();
97 add_tool(new BC_Title(x0, y0, _("Src Y:")));
98 src_y = new ScaleRatioCoord(this, client, x1, y0, 1, &client->config.src_y);
99 src_y->create_objects();
103 add_tool(new BC_Title(x0, y0, _("Src W:")));
104 src_w = new ScaleRatioCoord(this, client, x1, y0, 0, &client->config.src_w);
105 src_w->create_objects();
108 add_tool(new BC_Title(x0, y0, _("Src H:")));
109 src_h = new ScaleRatioCoord(this, client, x1, y0, 0, &client->config.src_h);
110 src_h->create_objects();
116 add_tool(new BC_Title(x0, y0, _("Dst X:")));
117 dst_x = new ScaleRatioCoord(this, client, x1, y0, 1, &client->config.dst_x);
118 dst_x->create_objects();
121 add_tool(new BC_Title(x0, y0, _("Dst Y:")));
122 dst_y = new ScaleRatioCoord(this, client, x1, y0, 1, &client->config.dst_y);
123 dst_y->create_objects();
126 add_tool(new BC_Title(x0, y0, _("Dst W:")));
127 dst_w = new ScaleRatioCoord(this, client, x1, y0, 0, &client->config.dst_w);
128 dst_w->create_objects();
131 add_tool(new BC_Title(x0, y0, _("Dst H:")));
132 dst_h = new ScaleRatioCoord(this, client, x1, y0, 0, &client->config.dst_h);
133 dst_h->create_objects();
142 ScaleRatioCoord::ScaleRatioCoord(ScaleRatioWin *win,
143 ScaleRatioMain *client, int x, int y, int s, float *value)
144 : BC_TumbleTextBox(win, (int)*value, (int)-10000*s, (int)10000, x, y, xS(100))
146 this->client = client;
151 ScaleRatioCoord::~ScaleRatioCoord()
155 int ScaleRatioCoord::handle_event()
157 *value = atof(get_text());
158 client->send_configure_change();
163 ScaleRatioTumbler::ScaleRatioTumbler(ScaleRatioRatio *ratio, int value, int x, int y)
164 : BC_TumbleTextBox(ratio->win, value, 0, 10000, x, y, xS(45))
169 ScaleRatioTumbler::~ScaleRatioTumbler()
173 int ScaleRatioTumbler::handle_event()
175 ratio->update_ratio();
179 ScaleRatioRatio::ScaleRatioRatio(ScaleRatioWin *win,
180 ScaleRatioMain *client, int x, int y, float *value)
181 : BC_TextBox(x, y, xS(100), 1, *value)
183 this->client = client;
190 ScaleRatioRatio::~ScaleRatioRatio()
196 int ScaleRatioRatio::handle_event()
198 *value = atof(get_text());
199 float fah = 0, faw = 0;
200 MWindow::create_aspect_ratio(faw, fah, *value*1000000, 1000000);
201 ah->update((int64_t)fah);
202 aw->update((int64_t)faw);
203 win->update_config();
208 void ScaleRatioRatio::create_objects()
210 int tx = BC_TextBox::get_x();
211 int ty = BC_TextBox::get_y();
213 int y = ty + BC_TextBox::get_h() + yS(5);
214 float faw = 0, fah = 0;
215 MWindow::create_aspect_ratio(faw, fah, *value*1000000, 1000000);
216 aw = new ScaleRatioTumbler(this, faw, x, y);
217 aw->create_objects();
218 x += aw->get_w() + xS(5);
219 ah = new ScaleRatioTumbler(this, fah, x, y);
220 ah->create_objects();
224 int w = BC_TextBox::get_w();
229 void ScaleRatioRatio::update_ratio()
231 float fah = atof(ah->get_text());
232 float faw = atof(aw->get_text());
233 *value = fah > 0 ? faw / fah : 1.f;
234 win->update_config();
238 ScaleRatioTypeItem::ScaleRatioTypeItem(ScaleRatioType *popup, int type, const char *text)
245 ScaleRatioTypeItem::~ScaleRatioTypeItem()
249 int ScaleRatioTypeItem::handle_event()
251 popup->win->client->config.type = type;
252 popup->set_value(type);
253 return popup->handle_event();
257 ScaleRatioType::ScaleRatioType(ScaleRatioWin *win, int x, int y, int *value)
258 : BC_PopupMenu(x, y, xS(180), "", 1)
264 ScaleRatioType::~ScaleRatioType()
268 void ScaleRatioType::create_objects()
270 for( int i=1; i<Rescale::n_scale_types; ++i )
271 add_item(new ScaleRatioTypeItem(this, i, Rescale::scale_types[i]));
275 void ScaleRatioType::update(int v)
277 set_value(*value = v);
280 int ScaleRatioType::handle_event()
282 win->update_config();
287 int ScaleRatioApply::handle_event()
289 win->update_config();
291 win->client->send_configure_change();
295 void ScaleRatioWin::update_config()
297 ScaleRatioConfig *conf = &client->config;
298 Rescale in(conf->in_w, conf->in_h, conf->in_r);
299 Rescale out(conf->out_w, conf->out_h, conf->out_r);
300 in.rescale(out,conf->type, conf->src_w,conf->src_h, conf->dst_w,conf->dst_h);
303 void ScaleRatioWin::update_gui()
305 ScaleRatioConfig *conf = &client->config;
306 type_popup->update(conf->type);
307 in_r->update(conf->in_r);
308 out_r->update(conf->out_r);
309 in_w->update(conf->in_w);
310 in_h->update(conf->in_h);
311 src_x->update(conf->src_x);
312 src_y->update(conf->src_y);
313 src_w->update(conf->src_w);
314 src_h->update(conf->src_h);
315 out_w->update(conf->out_w);
316 out_h->update(conf->out_h);
317 dst_x->update(conf->dst_x);
318 dst_y->update(conf->dst_y);
319 dst_w->update(conf->dst_w);
320 dst_h->update(conf->dst_h);