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, 400, 320, 400, 320, 0)
34 this->client = client;
37 ScaleRatioWin::~ScaleRatioWin()
41 void ScaleRatioWin::create_objects()
44 int x0 = x, x1 = x0 + 50;
46 client->load_configuration();
48 add_tool(new BC_Title(x0, y0, _("In R:")));
49 add_tool(in_r = new ScaleRatioRatio(this, client, x1, y0, &client->config.in_r));
50 in_r->create_objects();
51 y0 += in_r->get_th() + 10;
53 add_tool(new BC_Title(x0, y0, _("In W:")));
54 in_w = new ScaleRatioCoord(this, client, x1, y0, 0, &client->config.in_w);
55 in_w->create_objects();
56 y0 += in_w->get_h() + 8;
58 add_tool(new BC_Title(x0, y0, _("In H:")));
59 in_h = new ScaleRatioCoord(this, client, x1, y0, 0, &client->config.in_h);
60 in_h->create_objects();
62 x0 = get_w()/2; y0 = y;
65 add_tool(new BC_Title(x0, y0, _("Out R:")));
66 add_tool(out_r = new ScaleRatioRatio(this, client, x1, y0, &client->config.out_r));
67 out_r->create_objects();
68 y0 += out_r->get_th() + 10;
70 add_tool(new BC_Title(x0, y0, _("Out W:")));
71 out_w = new ScaleRatioCoord(this, client, x1, y0, 0, &client->config.out_w);
72 out_w->create_objects();
73 y0 += out_w->get_h() + 8;
75 add_tool(new BC_Title(x0, y0, _("Out H:")));
76 out_h = new ScaleRatioCoord(this, client, x1, y0, 0, &client->config.out_h);
77 out_h->create_objects();
78 y0 += out_h->get_h() + 8;
81 add_tool(apply_button = new ScaleRatioApply(this, x, y));
82 int x2 = x + apply_button->get_w() + 50;
83 add_tool(type_popup = new ScaleRatioType(this, x2, y, &client->config.type));
84 type_popup->create_objects();
85 y += apply_button->get_h() + 30;
90 add_tool(new BC_Title(x0, y0, _("Src X:")));
91 src_x = new ScaleRatioCoord(this, client, x1, y0, 1, &client->config.src_x);
92 src_x->create_objects();
95 add_tool(new BC_Title(x0, y0, _("Src Y:")));
96 src_y = new ScaleRatioCoord(this, client, x1, y0, 1, &client->config.src_y);
97 src_y->create_objects();
101 add_tool(new BC_Title(x0, y0, _("Src W:")));
102 src_w = new ScaleRatioCoord(this, client, x1, y0, 0, &client->config.src_w);
103 src_w->create_objects();
106 add_tool(new BC_Title(x0, y0, _("Src H:")));
107 src_h = new ScaleRatioCoord(this, client, x1, y0, 0, &client->config.src_h);
108 src_h->create_objects();
114 add_tool(new BC_Title(x0, y0, _("Dst X:")));
115 dst_x = new ScaleRatioCoord(this, client, x1, y0, 1, &client->config.dst_x);
116 dst_x->create_objects();
119 add_tool(new BC_Title(x0, y0, _("Dst Y:")));
120 dst_y = new ScaleRatioCoord(this, client, x1, y0, 1, &client->config.dst_y);
121 dst_y->create_objects();
124 add_tool(new BC_Title(x0, y0, _("Dst W:")));
125 dst_w = new ScaleRatioCoord(this, client, x1, y0, 0, &client->config.dst_w);
126 dst_w->create_objects();
129 add_tool(new BC_Title(x0, y0, _("Dst H:")));
130 dst_h = new ScaleRatioCoord(this, client, x1, y0, 0, &client->config.dst_h);
131 dst_h->create_objects();
140 ScaleRatioCoord::ScaleRatioCoord(ScaleRatioWin *win,
141 ScaleRatioMain *client, int x, int y, int s, float *value)
142 : BC_TumbleTextBox(win, (int)*value, (int)-10000*s, (int)10000, x, y, 100)
144 this->client = client;
149 ScaleRatioCoord::~ScaleRatioCoord()
153 int ScaleRatioCoord::handle_event()
155 *value = atof(get_text());
156 client->send_configure_change();
161 ScaleRatioTumbler::ScaleRatioTumbler(ScaleRatioRatio *ratio, int value, int x, int y)
162 : BC_TumbleTextBox(ratio->win, value, 0, 10000, x, y, 45)
167 ScaleRatioTumbler::~ScaleRatioTumbler()
171 int ScaleRatioTumbler::handle_event()
173 ratio->update_ratio();
177 ScaleRatioRatio::ScaleRatioRatio(ScaleRatioWin *win,
178 ScaleRatioMain *client, int x, int y, float *value)
179 : BC_TextBox(x, y, 100, 1, *value)
181 this->client = client;
188 ScaleRatioRatio::~ScaleRatioRatio()
194 int ScaleRatioRatio::handle_event()
196 *value = atof(get_text());
197 float fah = 0, faw = 0;
198 MWindow::create_aspect_ratio(faw, fah, *value*1000000, 1000000);
199 ah->update((int64_t)fah);
200 aw->update((int64_t)faw);
201 win->update_config();
206 void ScaleRatioRatio::create_objects()
208 int tx = BC_TextBox::get_x();
209 int ty = BC_TextBox::get_y();
211 int y = ty + BC_TextBox::get_h() + 5;
212 float faw = 0, fah = 0;
213 MWindow::create_aspect_ratio(faw, fah, *value*1000000, 1000000);
214 aw = new ScaleRatioTumbler(this, faw, x, y);
215 aw->create_objects();
216 x += aw->get_w() + 5;
217 ah = new ScaleRatioTumbler(this, fah, x, y);
218 ah->create_objects();
222 int w = BC_TextBox::get_w();
227 void ScaleRatioRatio::update_ratio()
229 float fah = atof(ah->get_text());
230 float faw = atof(aw->get_text());
231 *value = fah > 0 ? faw / fah : 1.f;
232 win->update_config();
236 ScaleRatioTypeItem::ScaleRatioTypeItem(ScaleRatioType *popup, int type, const char *text)
243 ScaleRatioTypeItem::~ScaleRatioTypeItem()
247 int ScaleRatioTypeItem::handle_event()
249 popup->win->client->config.type = type;
250 popup->set_value(type);
251 return popup->handle_event();
255 ScaleRatioType::ScaleRatioType(ScaleRatioWin *win, int x, int y, int *value)
256 : BC_PopupMenu(x, y, 180, "", 1)
262 ScaleRatioType::~ScaleRatioType()
266 void ScaleRatioType::create_objects()
268 for( int i=1; i<Rescale::n_scale_types; ++i )
269 add_item(new ScaleRatioTypeItem(this, i, Rescale::scale_types[i]));
273 void ScaleRatioType::update(int v)
275 set_value(*value = v);
278 int ScaleRatioType::handle_event()
280 win->update_config();
285 int ScaleRatioApply::handle_event()
287 win->update_config();
289 win->client->send_configure_change();
293 void ScaleRatioWin::update_config()
295 ScaleRatioConfig *conf = &client->config;
296 Rescale in(conf->in_w, conf->in_h, conf->in_r);
297 Rescale out(conf->out_w, conf->out_h, conf->out_r);
298 in.rescale(out,conf->type, conf->src_w,conf->src_h, conf->dst_w,conf->dst_h);
301 void ScaleRatioWin::update_gui()
303 ScaleRatioConfig *conf = &client->config;
304 type_popup->update(conf->type);
305 in_r->update(conf->in_r);
306 out_r->update(conf->out_r);
307 in_w->update(conf->in_w);
308 in_h->update(conf->in_h);
309 src_x->update(conf->src_x);
310 src_y->update(conf->src_y);
311 src_w->update(conf->src_w);
312 src_h->update(conf->src_h);
313 out_w->update(conf->out_w);
314 out_h->update(conf->out_h);
315 dst_x->update(conf->dst_x);
316 dst_y->update(conf->dst_y);
317 dst_w->update(conf->dst_w);
318 dst_h->update(conf->dst_h);