Add back 2 patches for histogram and overlayframe that are working correctly and...
[goodguy/cinelerra.git] / cinelerra-5.1 / plugins / scale / scalewin.C
1
2 /*
3  * CINELERRA
4  * Copyright (C) 2008 Adam Williams <broadcast at earthling dot net>
5  *
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.
10  *
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.
15  *
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
19  *
20  */
21
22 #include "bcdisplayinfo.h"
23 #include "clip.h"
24 #include "language.h"
25 #include "theme.h"
26 #include "mwindow.h"
27 #include "pluginserver.h"
28 #include "scale.h"
29
30
31
32 ScaleWin::ScaleWin(ScaleMain *client)
33  : PluginClientWindow(client, xS(420), yS(260), xS(420), yS(260), 0)
34 {
35         this->client = client;
36 }
37
38 ScaleWin::~ScaleWin()
39 {
40         delete x_factor_text;
41         delete x_factor_slider;
42         delete x_factor_clr;
43         delete y_factor_text;
44         delete y_factor_slider;
45         delete y_factor_clr;
46         delete width_text;
47         delete width_slider;
48         delete width_clr;
49         delete height_text;
50         delete height_slider;
51         delete height_clr;
52 }
53
54 void ScaleWin::create_objects()
55 {
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
61
62         BC_TitleBar *title_bar;
63         BC_Bar *bar;
64
65
66 // Scale section
67         add_subwindow(title_bar = new BC_TitleBar(x, y, get_w()-2*x, xs20, xs10, _("Scale")));
68         y += ys20;
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));
78         y += ys30;
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));
85         y += ys30;
86         add_tool(constrain = new ScaleConstrain(this, client, (x + x2), y));
87         y += ys40;
88
89 // Size section
90         add_subwindow(title_bar = new BC_TitleBar(x, y, get_w()-2*x, xs20, xs10, _("Size")));
91         y += ys20;
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));
99         int ya = y;
100         y += ys30;
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));
107
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));
111         y += ys40;
112
113 // Reset section
114         add_subwindow(bar = new BC_Bar(x, y, get_w()-2*x));
115         y += ys10;
116         add_tool(reset = new ScaleReset(this, client, x, y));
117
118         show_window();
119         flush();
120
121         // Needed to update Enable-Disable GUI when "Show controls" is pressed.
122         update_scale_size_enable();
123 }
124
125
126 void ScaleWin::update_scale_size_enable()
127 {
128         if(use_scale->get_value()==1) 
129         {
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();
137
138                 x_factor_text->enable();
139                 x_factor_slider->enable();
140                 x_factor_clr->enable();
141                 if(client->config.constrain)
142                 {
143                         y_factor_text->disable();
144                         y_factor_slider->disable();
145                         y_factor_clr->disable();
146                 }
147                 else
148                 {
149                         y_factor_text->enable();
150                         y_factor_slider->enable();
151                         y_factor_clr->enable();
152                 }
153                 constrain->enable();
154         }
155
156         if(use_size->get_value()==1)
157         {
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();
165
166                 width_text->enable();
167                 width_slider->enable();
168                 width_clr->enable();
169                 height_text->enable();
170                 height_slider->enable();
171                 height_clr->enable();
172                 pulldown->show_window();
173         }
174 }
175
176
177 void ScaleWin::update(int clear)
178 {
179         switch(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);
183                         break;
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);
187                         break;
188                 case RESET_WIDTH :
189                         width_text->update((int64_t)client->config.width);
190                         width_slider->update((int64_t)client->config.width);
191                         break;
192                 case RESET_HEIGHT :
193                         height_text->update((int64_t)client->config.height);
194                         height_slider->update((int64_t)client->config.height);
195                         break;
196                 case RESET_ALL :
197                 case RESET_DEFAULT_SETTINGS :
198                 default:
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);
204
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);
209
210                         use_scale->update((int)!client->config.type);
211                         use_size->update((int)client->config.type);
212                         break;
213         }
214 }
215
216
217
218
219
220 ScaleUseScale::ScaleUseScale(ScaleWin *win, ScaleMain *client, int x, int y)
221  : BC_Radial(x, y, client->config.type == FIXED_SCALE, "")
222 {
223         this->win = win;
224         this->client = client;
225         set_tooltip(_("Use fixed scale"));
226 }
227 ScaleUseScale::~ScaleUseScale()
228 {
229 }
230 int ScaleUseScale::handle_event()
231 {
232         client->set_type(FIXED_SCALE);
233         win->update_scale_size_enable();
234         return 1;
235 }
236
237 ScaleUseSize::ScaleUseSize(ScaleWin *win, ScaleMain *client, int x, int y)
238  : BC_Radial(x, y, client->config.type == FIXED_SIZE, "")
239 {
240         this->win = win;
241         this->client = client;
242         set_tooltip(_("Use fixed size"));
243 }
244 ScaleUseSize::~ScaleUseSize()
245 {
246 }
247 int ScaleUseSize::handle_event()
248 {
249         client->set_type(FIXED_SIZE);
250         win->update_scale_size_enable();
251         return 1;
252 }
253
254
255
256 ScaleConstrain::ScaleConstrain(ScaleWin *win, ScaleMain *client, int x, int y)
257  : BC_CheckBox(x, y, client->config.constrain, _("Constrain ratio"))
258 {
259         this->win = win;
260         this->client = client;
261 }
262 ScaleConstrain::~ScaleConstrain()
263 {
264 }
265 int ScaleConstrain::handle_event()
266 {
267         client->config.constrain = get_value();
268
269         if(client->config.constrain)
270         {
271                 win->y_factor_text->disable();
272                 win->y_factor_slider->disable();
273                 win->y_factor_clr->disable();
274
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);
278         }
279         else
280         {
281                 win->y_factor_text->enable();
282                 win->y_factor_slider->enable();
283                 win->y_factor_clr->enable();
284         }
285         client->send_configure_change();
286         return 1;
287 }
288
289
290
291 /* *********************************** */
292 /* **** SCALE X FACTOR  ************** */
293 ScaleXFactorText::ScaleXFactorText(ScaleWin *win, ScaleMain *client,
294         int x, int y)
295  : BC_TumbleTextBox(win, (float)client->config.x_factor,
296         MIN_FACTOR, MAX_FACTOR, x, y, xS(60), 2)
297 {
298         this->client = client;
299         this->win = win;
300         set_increment(0.1);
301         enabled = 1;
302 }
303
304 ScaleXFactorText::~ScaleXFactorText()
305 {
306 }
307
308 int ScaleXFactorText::handle_event()
309 {
310         client->config.x_factor = atof(get_text());
311         CLAMP(client->config.x_factor, MIN_FACTOR, MAX_FACTOR);
312
313         if(client->config.constrain)
314         {
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);
318         }
319         win->x_factor_slider->update(client->config.x_factor);
320         client->send_configure_change();
321         return 1;
322 }
323
324 ScaleXFactorSlider::ScaleXFactorSlider(ScaleWin *win, ScaleMain *client,
325         int x, int y, int w)
326  : BC_FSlider(x, y, 0, w, w, MIN_FACTOR, MAX_FACTOR, (float)client->config.x_factor)
327 {
328         this->win = win;
329         this->client = client;
330         enable_show_value(0); // Hide caption
331         set_precision(0.01);
332 }
333
334 ScaleXFactorSlider::~ScaleXFactorSlider()
335 {
336 }
337
338 int ScaleXFactorSlider::handle_event()
339 {
340         client->config.x_factor = get_value();
341         if(client->config.constrain)
342         {
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);
346         }
347         win->x_factor_text->update(client->config.x_factor);
348         client->send_configure_change();
349         return 1;
350 }
351 /* *********************************** */
352
353
354 /* *********************************** */
355 /* **** SCALE Y FACTOR  ************** */
356 ScaleYFactorText::ScaleYFactorText(ScaleWin *win, ScaleMain *client,
357         int x, int y)
358  : BC_TumbleTextBox(win, (float)client->config.y_factor,
359         MIN_FACTOR, MAX_FACTOR, x, y, xS(60), 2)
360 {
361         this->client = client;
362         this->win = win;
363         set_increment(0.1);
364         enabled = 1;
365 }
366
367 ScaleYFactorText::~ScaleYFactorText()
368 {
369 }
370
371 int ScaleYFactorText::handle_event()
372 {
373         client->config.y_factor = atof(get_text());
374         CLAMP(client->config.y_factor, MIN_FACTOR, MAX_FACTOR);
375
376         if(client->config.constrain)
377         {
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);
381         }
382         win->y_factor_slider->update(client->config.y_factor);
383         client->send_configure_change();
384         return 1;
385 }
386
387 ScaleYFactorSlider::ScaleYFactorSlider(ScaleWin *win, ScaleMain *client,
388         int x, int y, int w)
389  : BC_FSlider(x, y, 0, w, w, MIN_FACTOR, MAX_FACTOR, (float)client->config.y_factor)
390 {
391         this->win = win;
392         this->client = client;
393         enable_show_value(0); // Hide caption
394         set_precision(0.01);
395 }
396
397 ScaleYFactorSlider::~ScaleYFactorSlider()
398 {
399 }
400
401 int ScaleYFactorSlider::handle_event()
402 {
403         client->config.y_factor = get_value();
404         if(client->config.constrain)
405         {
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);
409         }
410         win->y_factor_text->update(client->config.y_factor);
411         client->send_configure_change();
412         return 1;
413 }
414 /* *********************************** */
415
416
417 /* *********************************** */
418 /* **** SCALE WIDTH     ************** */
419 ScaleWidthText::ScaleWidthText(ScaleWin *win, ScaleMain *client,
420         int x, int y)
421  : BC_TumbleTextBox(win, client->config.width,
422         0, MAX_WIDTH, x, y, xS(60))
423 {
424         this->client = client;
425         this->win = win;
426         set_increment(10);
427         enabled = 1;
428 }
429
430 ScaleWidthText::~ScaleWidthText()
431 {
432 }
433
434 int ScaleWidthText::handle_event()
435 {
436         client->config.width = atoi(get_text());
437         win->width_slider->update(client->config.width);
438         client->send_configure_change();
439         return 1;
440 }
441
442 ScaleWidthSlider::ScaleWidthSlider(ScaleWin *win, ScaleMain *client,
443         int x, int y, int w)
444  : BC_ISlider(x, y, 0, w, w, 0, MAX_WIDTH, client->config.width)
445 {
446         this->client = client;
447         this->win = win;
448         enable_show_value(0); // Hide caption
449 }
450
451 ScaleWidthSlider::~ScaleWidthSlider()
452 {
453 }
454
455 int ScaleWidthSlider::handle_event()
456 {
457         client->config.width = get_value();
458         win->width_text->update((int64_t)client->config.width);
459         client->send_configure_change();
460         return 1;
461 }
462 /* *********************************** */
463
464
465 /* *********************************** */
466 /* **** SCALE HEIGHT    ************** */
467 ScaleHeightText::ScaleHeightText(ScaleWin *win, ScaleMain *client,
468         int x, int y)
469  : BC_TumbleTextBox(win, client->config.height,
470         0, MAX_HEIGHT, x, y, xS(60))
471 {
472         this->client = client;
473         this->win = win;
474         set_increment(10);
475         enabled = 1;
476 }
477
478 ScaleHeightText::~ScaleHeightText()
479 {
480 }
481
482 int ScaleHeightText::handle_event()
483 {
484         client->config.height = atoi(get_text());
485         win->height_slider->update(client->config.height);
486         client->send_configure_change();
487         return 1;
488 }
489
490 ScaleHeightSlider::ScaleHeightSlider(ScaleWin *win, ScaleMain *client,
491         int x, int y, int w)
492  : BC_ISlider(x, y, 0, w, w, 0, MAX_HEIGHT, client->config.height)
493 {
494         this->client = client;
495         this->win = win;
496         enable_show_value(0); // Hide caption
497 }
498
499 ScaleHeightSlider::~ScaleHeightSlider()
500 {
501 }
502
503 int ScaleHeightSlider::handle_event()
504 {
505         client->config.height = get_value();
506         win->height_text->update((int64_t)client->config.height);
507         client->send_configure_change();
508         return 1;
509 }
510 /* *********************************** */
511
512
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"))
515 {
516         this->win = win;
517         this->client = client;
518         this->clear = clear;
519 }
520 ScaleClr::~ScaleClr()
521 {
522 }
523 int ScaleClr::handle_event()
524 {
525         client->config.reset(clear);
526         win->update(clear);
527         if( client->config.constrain && win->use_scale->get_value() )
528         {
529                 client->config.reset(RESET_X_FACTOR);
530                 win->update(RESET_X_FACTOR);
531
532                 client->config.reset(RESET_Y_FACTOR);
533                 win->update(RESET_Y_FACTOR);
534         }
535         client->send_configure_change();
536         return 1;
537 }
538
539 ScaleReset::ScaleReset(ScaleWin *win, ScaleMain *client, int x, int y)
540  : BC_GenericButton(x, y, _("Reset"))
541 {
542         this->win = win;
543         this->client = client;
544 }
545
546 ScaleReset::~ScaleReset()
547 {
548 }
549
550 int ScaleReset::handle_event()
551 {
552         client->config.reset(RESET_ALL);
553         win->update(RESET_ALL);
554         win->update_scale_size_enable();
555         client->send_configure_change();
556         return 1;
557 }