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"
27 #include "pluginserver.h"
32 ScaleWin::ScaleWin(ScaleMain *client)
33 : PluginClientWindow(client, xS(420), yS(260), xS(420), yS(260), 0)
35 this->client = client;
41 delete x_factor_slider;
44 delete y_factor_slider;
54 void ScaleWin::create_objects()
56 int xs10 = xS(10), xs20 = xS(20), xs200 = xS(200);
57 int ys10 = yS(10), ys20 = yS(20), ys30 = yS(30), ys40 = yS(40);
58 int x2 = xS(60), x3 = xS(180);
59 int x = xs10, y = ys10;
60 int clr_x = get_w()-x - xS(22); // note: clrBtn_w = 22
62 BC_TitleBar *title_bar;
67 add_subwindow(title_bar = new BC_TitleBar(x, y, get_w()-2*x, xs20, xs10, _("Scale")));
69 add_tool(use_scale = new ScaleUseScale(this, client, x, y));
70 int xa= x*2 + use_scale->get_w();
71 add_tool(new BC_Title(xa, y, _("X:")));
72 x_factor_text = new ScaleXFactorText(this, client, (x + x2), y);
73 x_factor_text->create_objects();
74 x_factor_slider = new ScaleXFactorSlider(this, client, x3, y, xs200);
75 add_subwindow(x_factor_slider);
76 clr_x = x3 + x_factor_slider->get_w() + x;
77 add_subwindow(x_factor_clr = new ScaleClr(this, client, clr_x, y, RESET_X_FACTOR));
79 add_tool(new BC_Title(xa, y, _("Y:")));
80 y_factor_text = new ScaleYFactorText(this, client, (x + x2), y);
81 y_factor_text->create_objects();
82 y_factor_slider = new ScaleYFactorSlider(this, client, x3, y, xs200);
83 add_subwindow(y_factor_slider);
84 add_subwindow(y_factor_clr = new ScaleClr(this, client, clr_x, y, RESET_Y_FACTOR));
86 add_tool(constrain = new ScaleConstrain(this, client, (x + x2), y));
90 add_subwindow(title_bar = new BC_TitleBar(x, y, get_w()-2*x, xs20, xs10, _("Size")));
92 add_tool(use_size = new ScaleUseSize(this, client, x, y));
93 add_tool(new BC_Title(xa, y, _("W:")));
94 width_text = new ScaleWidthText(this, client, (x + x2), y);
95 width_text->create_objects();
96 width_slider = new ScaleWidthSlider(this, client, x3, y, xs200);
97 add_subwindow(width_slider);
98 add_subwindow(width_clr = new ScaleClr(this, client, clr_x, y, RESET_WIDTH));
101 add_tool(new BC_Title(xa, y, _("H:")));
102 height_text = new ScaleHeightText(this, client, (x + x2), y);
103 height_text->create_objects();
104 height_slider = new ScaleHeightSlider(this, client, x3, y, xs200);
105 add_subwindow(height_slider);
106 add_subwindow(height_clr = new ScaleClr(this, client, clr_x, y, RESET_HEIGHT));
108 int x4 = x + x2 + height_text->get_w();
109 add_tool(pulldown = new FrameSizePulldown(client->server->mwindow->theme,
110 width_text->get_textbox(), height_text->get_textbox(), x4, ya));
114 add_subwindow(bar = new BC_Bar(x, y, get_w()-2*x));
116 add_tool(reset = new ScaleReset(this, client, x, y));
121 // Needed to update Enable-Disable GUI when "Show controls" is pressed.
122 update_scale_size_enable();
126 void ScaleWin::update_scale_size_enable()
128 if(use_scale->get_value()==1)
130 width_text->disable();
131 width_slider->disable();
132 width_clr->disable();
133 height_text->disable();
134 height_slider->disable();
135 height_clr->disable();
136 pulldown->hide_window();
138 x_factor_text->enable();
139 x_factor_slider->enable();
140 x_factor_clr->enable();
141 if(client->config.constrain)
143 y_factor_text->disable();
144 y_factor_slider->disable();
145 y_factor_clr->disable();
149 y_factor_text->enable();
150 y_factor_slider->enable();
151 y_factor_clr->enable();
156 if(use_size->get_value()==1)
158 x_factor_text->disable();
159 x_factor_slider->disable();
160 x_factor_clr->disable();
161 y_factor_text->disable();
162 y_factor_slider->disable();
163 y_factor_clr->disable();
164 constrain->disable();
166 width_text->enable();
167 width_slider->enable();
169 height_text->enable();
170 height_slider->enable();
171 height_clr->enable();
172 pulldown->show_window();
177 void ScaleWin::update(int clear)
180 case RESET_X_FACTOR :
181 x_factor_text->update((float)client->config.x_factor);
182 x_factor_slider->update((float)client->config.x_factor);
184 case RESET_Y_FACTOR :
185 y_factor_text->update((float)client->config.y_factor);
186 y_factor_slider->update((float)client->config.y_factor);
189 width_text->update((int64_t)client->config.width);
190 width_slider->update((int64_t)client->config.width);
193 height_text->update((int64_t)client->config.height);
194 height_slider->update((int64_t)client->config.height);
197 case RESET_DEFAULT_SETTINGS :
199 x_factor_text->update((float)client->config.x_factor);
200 x_factor_slider->update((float)client->config.x_factor);
201 y_factor_text->update((float)client->config.y_factor);
202 y_factor_slider->update((float)client->config.y_factor);
203 constrain->update(client->config.constrain);
205 width_text->update((int64_t)client->config.width);
206 width_slider->update((int64_t)client->config.width);
207 height_text->update((int64_t)client->config.height);
208 height_slider->update((int64_t)client->config.height);
210 use_scale->update((int)!client->config.type);
211 use_size->update((int)client->config.type);
220 ScaleUseScale::ScaleUseScale(ScaleWin *win, ScaleMain *client, int x, int y)
221 : BC_Radial(x, y, client->config.type == FIXED_SCALE, "")
224 this->client = client;
225 set_tooltip(_("Use fixed scale"));
227 ScaleUseScale::~ScaleUseScale()
230 int ScaleUseScale::handle_event()
232 client->set_type(FIXED_SCALE);
233 win->update_scale_size_enable();
237 ScaleUseSize::ScaleUseSize(ScaleWin *win, ScaleMain *client, int x, int y)
238 : BC_Radial(x, y, client->config.type == FIXED_SIZE, "")
241 this->client = client;
242 set_tooltip(_("Use fixed size"));
244 ScaleUseSize::~ScaleUseSize()
247 int ScaleUseSize::handle_event()
249 client->set_type(FIXED_SIZE);
250 win->update_scale_size_enable();
256 ScaleConstrain::ScaleConstrain(ScaleWin *win, ScaleMain *client, int x, int y)
257 : BC_CheckBox(x, y, client->config.constrain, _("Constrain ratio"))
260 this->client = client;
262 ScaleConstrain::~ScaleConstrain()
265 int ScaleConstrain::handle_event()
267 client->config.constrain = get_value();
269 if(client->config.constrain)
271 win->y_factor_text->disable();
272 win->y_factor_slider->disable();
273 win->y_factor_clr->disable();
275 client->config.y_factor = client->config.x_factor;
276 win->y_factor_text->update(client->config.y_factor);
277 win->y_factor_slider->update(client->config.y_factor);
281 win->y_factor_text->enable();
282 win->y_factor_slider->enable();
283 win->y_factor_clr->enable();
285 client->send_configure_change();
291 /* *********************************** */
292 /* **** SCALE X FACTOR ************** */
293 ScaleXFactorText::ScaleXFactorText(ScaleWin *win, ScaleMain *client,
295 : BC_TumbleTextBox(win, (float)client->config.x_factor,
296 MIN_FACTOR, MAX_FACTOR, x, y, xS(60), 2)
298 this->client = client;
304 ScaleXFactorText::~ScaleXFactorText()
308 int ScaleXFactorText::handle_event()
310 client->config.x_factor = atof(get_text());
311 CLAMP(client->config.x_factor, MIN_FACTOR, MAX_FACTOR);
313 if(client->config.constrain)
315 client->config.y_factor = client->config.x_factor;
316 win->y_factor_text->update(client->config.y_factor);
317 win->y_factor_slider->update(client->config.y_factor);
319 win->x_factor_slider->update(client->config.x_factor);
320 client->send_configure_change();
324 ScaleXFactorSlider::ScaleXFactorSlider(ScaleWin *win, ScaleMain *client,
326 : BC_FSlider(x, y, 0, w, w, MIN_FACTOR, MAX_FACTOR, (float)client->config.x_factor)
329 this->client = client;
330 enable_show_value(0); // Hide caption
334 ScaleXFactorSlider::~ScaleXFactorSlider()
338 int ScaleXFactorSlider::handle_event()
340 client->config.x_factor = get_value();
341 if(client->config.constrain)
343 client->config.y_factor = client->config.x_factor;
344 win->y_factor_text->update(client->config.y_factor);
345 win->y_factor_slider->update(client->config.y_factor);
347 win->x_factor_text->update(client->config.x_factor);
348 client->send_configure_change();
351 /* *********************************** */
354 /* *********************************** */
355 /* **** SCALE Y FACTOR ************** */
356 ScaleYFactorText::ScaleYFactorText(ScaleWin *win, ScaleMain *client,
358 : BC_TumbleTextBox(win, (float)client->config.y_factor,
359 MIN_FACTOR, MAX_FACTOR, x, y, xS(60), 2)
361 this->client = client;
367 ScaleYFactorText::~ScaleYFactorText()
371 int ScaleYFactorText::handle_event()
373 client->config.y_factor = atof(get_text());
374 CLAMP(client->config.y_factor, MIN_FACTOR, MAX_FACTOR);
376 if(client->config.constrain)
378 client->config.x_factor = client->config.y_factor;
379 win->x_factor_text->update(client->config.x_factor);
380 win->x_factor_slider->update(client->config.x_factor);
382 win->y_factor_slider->update(client->config.y_factor);
383 client->send_configure_change();
387 ScaleYFactorSlider::ScaleYFactorSlider(ScaleWin *win, ScaleMain *client,
389 : BC_FSlider(x, y, 0, w, w, MIN_FACTOR, MAX_FACTOR, (float)client->config.y_factor)
392 this->client = client;
393 enable_show_value(0); // Hide caption
397 ScaleYFactorSlider::~ScaleYFactorSlider()
401 int ScaleYFactorSlider::handle_event()
403 client->config.y_factor = get_value();
404 if(client->config.constrain)
406 client->config.x_factor = client->config.y_factor;
407 win->x_factor_text->update(client->config.x_factor);
408 win->x_factor_slider->update(client->config.x_factor);
410 win->y_factor_text->update(client->config.y_factor);
411 client->send_configure_change();
414 /* *********************************** */
417 /* *********************************** */
418 /* **** SCALE WIDTH ************** */
419 ScaleWidthText::ScaleWidthText(ScaleWin *win, ScaleMain *client,
421 : BC_TumbleTextBox(win, client->config.width,
422 0, MAX_WIDTH, x, y, xS(60))
424 this->client = client;
430 ScaleWidthText::~ScaleWidthText()
434 int ScaleWidthText::handle_event()
436 client->config.width = atoi(get_text());
437 win->width_slider->update(client->config.width);
438 client->send_configure_change();
442 ScaleWidthSlider::ScaleWidthSlider(ScaleWin *win, ScaleMain *client,
444 : BC_ISlider(x, y, 0, w, w, 0, MAX_WIDTH, client->config.width)
446 this->client = client;
448 enable_show_value(0); // Hide caption
451 ScaleWidthSlider::~ScaleWidthSlider()
455 int ScaleWidthSlider::handle_event()
457 client->config.width = get_value();
458 win->width_text->update((int64_t)client->config.width);
459 client->send_configure_change();
462 /* *********************************** */
465 /* *********************************** */
466 /* **** SCALE HEIGHT ************** */
467 ScaleHeightText::ScaleHeightText(ScaleWin *win, ScaleMain *client,
469 : BC_TumbleTextBox(win, client->config.height,
470 0, MAX_HEIGHT, x, y, xS(60))
472 this->client = client;
478 ScaleHeightText::~ScaleHeightText()
482 int ScaleHeightText::handle_event()
484 client->config.height = atoi(get_text());
485 win->height_slider->update(client->config.height);
486 client->send_configure_change();
490 ScaleHeightSlider::ScaleHeightSlider(ScaleWin *win, ScaleMain *client,
492 : BC_ISlider(x, y, 0, w, w, 0, MAX_HEIGHT, client->config.height)
494 this->client = client;
496 enable_show_value(0); // Hide caption
499 ScaleHeightSlider::~ScaleHeightSlider()
503 int ScaleHeightSlider::handle_event()
505 client->config.height = get_value();
506 win->height_text->update((int64_t)client->config.height);
507 client->send_configure_change();
510 /* *********************************** */
513 ScaleClr::ScaleClr(ScaleWin *win, ScaleMain *client, int x, int y, int clear)
514 : BC_Button(x, y, client->get_theme()->get_image_set("reset_button"))
517 this->client = client;
520 ScaleClr::~ScaleClr()
523 int ScaleClr::handle_event()
525 client->config.reset(clear);
527 if( client->config.constrain && win->use_scale->get_value() )
529 client->config.reset(RESET_X_FACTOR);
530 win->update(RESET_X_FACTOR);
532 client->config.reset(RESET_Y_FACTOR);
533 win->update(RESET_Y_FACTOR);
535 client->send_configure_change();
539 ScaleReset::ScaleReset(ScaleWin *win, ScaleMain *client, int x, int y)
540 : BC_GenericButton(x, y, _("Reset"))
543 this->client = client;
546 ScaleReset::~ScaleReset()
550 int ScaleReset::handle_event()
552 client->config.reset(RESET_ALL);
553 win->update(RESET_ALL);
554 win->update_scale_size_enable();
555 client->send_configure_change();