fix problem of using opengl transitions with Motion51 when in OpenGL mode
[goodguy/cinelerra.git] / cinelerra-5.1 / plugins / crop / cropwin.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 /*
23  * 2019. Derivative by Translate plugin. This plugin works also with Proxy.
24  * It uses Percent values instead of Pixel value coordinates.
25 */
26
27 #include "bcdisplayinfo.h"
28 #include "clip.h"
29 #include "language.h"
30 #include "theme.h"
31 #include "crop.h"
32 #include "cropwin.h"
33
34
35
36
37
38
39
40
41
42
43
44
45 CropWin::CropWin(CropMain *client)
46  : PluginClientWindow(client,
47         xS(420),
48         yS(290),
49         xS(420),
50         yS(290),
51         0)
52 {
53         this->client = client;
54 }
55
56 CropWin::~CropWin()
57 {
58 }
59
60 void CropWin::create_objects()
61 {
62         int xs10 = xS(10), xs20 = xS(20), xs200 = xS(200);
63         int ys10 = yS(10), ys20 = yS(20), ys30 = yS(30), ys40 = yS(40);
64         int x2 = xS(80), x3 = xS(180);
65         int x = xs10, y = ys10;
66         int clr_x = get_w()-x - xS(22); // note: clrBtn_w = 22
67
68         BC_TitleBar *title_bar;
69         BC_Bar *bar;
70
71 // Crop section
72         add_subwindow(title_bar = new BC_TitleBar(x, y, get_w()-2*x, xs20, xs10, _("Crop")));
73         y += ys20;
74         add_tool(new BC_Title(x, y, _("Left")));
75         add_tool(new BC_Title((x2-x), y, _("%")));
76         crop_left_text = new CropLeftText(this, client, (x + x2), y);
77         crop_left_text->create_objects();
78         crop_left_slider = new CropLeftSlider(this, client, x3, y, xs200);
79         add_subwindow(crop_left_slider);
80         clr_x = x3 + crop_left_slider->get_w() + x;
81         add_subwindow(crop_left_clr = new CropEdgesClr(this, client,
82                 clr_x, y, RESET_LEFT));
83         y += ys30;
84         add_tool(new BC_Title(x, y, _("Top")));
85         add_tool(new BC_Title((x2-x), y, _("%")));
86         crop_top_text = new CropTopText(this, client, (x + x2), y);
87         crop_top_text->create_objects();
88         crop_top_slider = new CropTopSlider(this, client, x3, y, xs200);
89         add_subwindow(crop_top_slider);
90         add_subwindow(crop_top_clr = new CropEdgesClr(this, client,
91                 clr_x, y, RESET_TOP));
92         y += ys30;
93         add_tool(new BC_Title(x, y, _("Right")));
94         add_tool(new BC_Title((x2-x), y, _("%")));
95         crop_right_text = new CropRightText(this, client, (x + x2), y);
96         crop_right_text->create_objects();
97         crop_right_slider = new CropRightSlider(this, client, x3, y, xs200);
98         add_subwindow(crop_right_slider);
99         add_subwindow(crop_right_clr = new CropEdgesClr(this, client,
100                 clr_x, y, RESET_RIGHT));
101         y += ys30;
102         add_tool(new BC_Title(x, y, _("Bottom")));
103         add_tool(new BC_Title((x2-x), y, _("%")));
104         crop_bottom_text = new CropBottomText(this, client, (x + x2), y);
105         crop_bottom_text->create_objects();
106         crop_bottom_slider = new CropBottomSlider(this, client, x3, y, xs200);
107         add_subwindow(crop_bottom_slider);
108         add_subwindow(crop_bottom_clr = new CropEdgesClr(this, client,
109                 clr_x, y, RESET_BOTTOM));
110         y += ys40;
111
112 // Position section
113         add_subwindow(title_bar = new BC_TitleBar(x, y, get_w()-2*x, xs20, xs10, _("Position")));
114         y += ys20;
115         add_tool(new BC_Title(x, y, _("X")));
116         add_tool(new BC_Title((x2-x), y, _("%")));
117         crop_position_x_text = new CropPositionXText(this, client, (x + x2), y);
118         crop_position_x_text->create_objects();
119         crop_position_x_slider = new CropPositionXSlider(this, client, x3, y, xs200);
120         add_subwindow(crop_position_x_slider);
121         add_subwindow(crop_position_x_clr = new CropEdgesClr(this, client,
122                 clr_x, y, RESET_POSITION_X));
123         y += ys30;
124         add_tool(new BC_Title(x, y, _("Y")));
125         add_tool(new BC_Title((x2-x), y, _("%")));
126         crop_position_y_text = new CropPositionYText(this, client, (x + x2), y);
127         crop_position_y_text->create_objects();
128         crop_position_y_slider = new CropPositionYSlider(this, client, x3, y, xs200);
129         add_subwindow(crop_position_y_slider);
130         add_subwindow(crop_position_y_clr = new CropEdgesClr(this, client,
131                 clr_x, y, RESET_POSITION_Y));
132         y += ys40;
133
134 // Reset section
135         add_subwindow(bar = new BC_Bar(x, y, get_w()-2*x));
136         y += ys10;
137         add_tool(reset = new CropReset(client, this, x, y));
138
139         show_window();
140         flush();
141 }
142
143 void CropWin::update(int clear)
144 {
145         switch(clear) {
146                 case RESET_LEFT :
147                         crop_left_text->update((float)client->config.crop_l);
148                         crop_left_slider->update((float)client->config.crop_l);
149                         break;
150                 case RESET_TOP :
151                         crop_top_text->update((float)client->config.crop_t);
152                         crop_top_slider->update((float)client->config.crop_t);
153                         break;
154                 case RESET_RIGHT :
155                         crop_right_text->update((float)client->config.crop_r);
156                         crop_right_slider->update((float)client->config.crop_r);
157                         break;
158                 case RESET_BOTTOM :
159                         crop_bottom_text->update((float)client->config.crop_b);
160                         crop_bottom_slider->update((float)client->config.crop_b);
161                         break;
162                 case RESET_POSITION_X :
163                         crop_position_x_text->update((float)client->config.position_x);
164                         crop_position_x_slider->update((float)client->config.position_x);
165                         break;
166                 case RESET_POSITION_Y :
167                         crop_position_y_text->update((float)client->config.position_y);
168                         crop_position_y_slider->update((float)client->config.position_y);
169                         break;
170                 case RESET_ALL :
171                 case RESET_DEFAULT_SETTINGS :
172                 default:
173                         crop_left_text->update((float)client->config.crop_l);
174                         crop_left_slider->update((float)client->config.crop_l);
175                         crop_top_text->update((float)client->config.crop_t);
176                         crop_top_slider->update((float)client->config.crop_t);
177                         crop_right_text->update((float)client->config.crop_r);
178                         crop_right_slider->update((float)client->config.crop_r);
179                         crop_bottom_text->update((float)client->config.crop_b);
180                         crop_bottom_slider->update((float)client->config.crop_b);
181
182                         crop_position_x_text->update((float)client->config.position_x);
183                         crop_position_x_slider->update((float)client->config.position_x);
184                         crop_position_y_text->update((float)client->config.position_y);
185                         crop_position_y_slider->update((float)client->config.position_y);
186                         break;
187         }
188 }
189
190
191
192
193
194
195
196 /* *********************************** */
197 /* **** CROP LEFT ******************** */
198 CropLeftText::CropLeftText(CropWin *win,
199         CropMain *client,
200         int x,
201         int y)
202  : BC_TumbleTextBox(win, client->config.crop_l,
203         (float)0.00, (float)100.00, x, y, xS(60), 2)
204 {
205         this->win = win;
206         this->client = client;
207 }
208
209 CropLeftText::~CropLeftText()
210 {
211 }
212
213 int CropLeftText::handle_event()
214 {
215         client->config.crop_l = atof(get_text());
216         win->crop_left_slider->update(client->config.crop_l);
217         client->send_configure_change();
218         return 1;
219 }
220
221 CropLeftSlider::CropLeftSlider(CropWin *win, CropMain *client,
222         int x, int y, int w)
223  : BC_FSlider(x, y, 0, w, w, 0.00, 100.00, client->config.crop_l)
224 {
225         this->win = win;
226         this->client = client;
227         enable_show_value(0); // Hide caption
228         set_precision(0.01);
229 }
230
231 CropLeftSlider::~CropLeftSlider()
232 {
233 }
234
235 int CropLeftSlider::handle_event()
236 {
237         client->config.crop_l = get_value();
238         win->crop_left_text->update(client->config.crop_l);
239         win->update(RESET_ALL);
240         client->send_configure_change();
241         return 1;
242 }
243 /* *********************************** */
244
245 /* *********************************** */
246 /* **** CROP TOP  ******************** */
247 CropTopText::CropTopText(CropWin *win,
248         CropMain *client,
249         int x,
250         int y)
251  : BC_TumbleTextBox(win, client->config.crop_t,
252         (float)0.00, (float)100.00, x, y, xS(60), 2)
253 {
254         this->win = win;
255         this->client = client;
256 }
257
258 CropTopText::~CropTopText()
259 {
260 }
261
262 int CropTopText::handle_event()
263 {
264         client->config.crop_t = atof(get_text());
265         win->crop_top_slider->update(client->config.crop_t);
266         client->send_configure_change();
267         return 1;
268 }
269
270 CropTopSlider::CropTopSlider(CropWin *win, CropMain *client,
271         int x, int y, int w)
272  : BC_FSlider(x, y, 0, w, w, 0.00, 100.00, client->config.crop_t)
273 {
274         this->win = win;
275         this->client = client;
276         enable_show_value(0); // Hide caption
277         set_precision(0.01);
278 }
279
280 CropTopSlider::~CropTopSlider()
281 {
282 }
283
284 int CropTopSlider::handle_event()
285 {
286         client->config.crop_t = get_value();
287         win->crop_top_text->update(client->config.crop_t);
288         win->update(RESET_ALL);
289         client->send_configure_change();
290         return 1;
291 }
292 /* *********************************** */
293
294 /* *********************************** */
295 /* **** CROP RIGHT ******************* */
296 CropRightText::CropRightText(CropWin *win, CropMain *client,
297         int x,
298         int y)
299  : BC_TumbleTextBox(win, client->config.crop_r,
300         (float)0.00, (float)100.00, x, y, xS(60), 2)
301 {
302         this->win = win;
303         this->client = client;
304 }
305
306 CropRightText::~CropRightText()
307 {
308 }
309
310 int CropRightText::handle_event()
311 {
312         client->config.crop_r = atof(get_text());
313         win->crop_right_slider->update(client->config.crop_r);
314         client->send_configure_change();
315         return 1;
316 }
317
318 CropRightSlider::CropRightSlider(CropWin *win, CropMain *client,
319         int x, int y, int w)
320  : BC_FSlider(x, y, 0, w, w, 0.00, 100.00, client->config.crop_r)
321 {
322         this->win = win;
323         this->client = client;
324         enable_show_value(0); // Hide caption
325         set_precision(0.01);
326 }
327
328 CropRightSlider::~CropRightSlider()
329 {
330 }
331
332 int CropRightSlider::handle_event()
333 {
334         client->config.crop_r = get_value();
335         win->crop_right_text->update(client->config.crop_r);
336         win->update(RESET_ALL);
337         client->send_configure_change();
338         return 1;
339 }
340 /* *********************************** */
341
342 /* *********************************** */
343 /* **** CROP BOTTOM ****************** */
344 CropBottomText::CropBottomText(CropWin *win, CropMain *client,
345         int x,
346         int y)
347  : BC_TumbleTextBox(win, client->config.crop_b,
348         (float)0.00, (float)100.00, x, y, xS(60), 2)
349 {
350         this->win = win;
351         this->client = client;
352 }
353
354 CropBottomText::~CropBottomText()
355 {
356 }
357
358 int CropBottomText::handle_event()
359 {
360         client->config.crop_b = atof(get_text());
361         win->crop_bottom_slider->update(client->config.crop_b);
362         client->send_configure_change();
363         return 1;
364 }
365
366 CropBottomSlider::CropBottomSlider(CropWin *win, CropMain *client,
367         int x, int y, int w)
368  : BC_FSlider(x, y, 0, w, w, 0.00, 100.00, client->config.crop_b)
369 {
370         this->win = win;
371         this->client = client;
372         enable_show_value(0); // Hide caption
373         set_precision(0.01);
374 }
375
376 CropBottomSlider::~CropBottomSlider()
377 {
378 }
379
380 int CropBottomSlider::handle_event()
381 {
382         client->config.crop_b = get_value();
383         win->crop_bottom_text->update(client->config.crop_b);
384         win->update(RESET_ALL);
385         client->send_configure_change();
386         return 1;
387 }
388 /* *********************************** */
389
390 /* *********************************** */
391 /* **** CROP POSITION X ************** */
392 CropPositionXText::CropPositionXText(CropWin *win, CropMain *client,
393         int x,
394         int y)
395  : BC_TumbleTextBox(win, client->config.position_x,
396         (float)-100.00, (float)100.00, x, y, xS(60), 2)
397 {
398         this->win = win;
399         this->client = client;
400 }
401
402 CropPositionXText::~CropPositionXText()
403 {
404 }
405
406 int CropPositionXText::handle_event()
407 {
408         client->config.position_x = atof(get_text());
409         win->crop_position_x_slider->update(client->config.position_x);
410         client->send_configure_change();
411         return 1;
412 }
413
414 CropPositionXSlider::CropPositionXSlider(CropWin *win, CropMain *client,
415         int x, int y, int w)
416  : BC_FSlider(x, y, 0, w, w, -100.00, 100.00, client->config.position_x)
417 {
418         this->win = win;
419         this->client = client;
420         enable_show_value(0); // Hide caption
421         set_precision(0.01);
422 }
423
424 CropPositionXSlider::~CropPositionXSlider()
425 {
426 }
427
428 int CropPositionXSlider::handle_event()
429 {
430         client->config.position_x = get_value();
431         win->crop_position_x_text->update(client->config.position_x);
432         win->update(RESET_ALL);
433         client->send_configure_change();
434         return 1;
435 }
436 /* *********************************** */
437
438 /* *********************************** */
439 /* **** CROP POSITION Y ************** */
440 CropPositionYText::CropPositionYText(CropWin *win, CropMain *client,
441         int x,
442         int y)
443  : BC_TumbleTextBox(win, client->config.position_y,
444         (float)-100.00, (float)100.00, x, y, xS(60), 2)
445 {
446         this->win = win;
447         this->client = client;
448 }
449
450 CropPositionYText::~CropPositionYText()
451 {
452 }
453
454 int CropPositionYText::handle_event()
455 {
456         client->config.position_y = atof(get_text());
457         win->crop_position_y_slider->update(client->config.position_y);
458         client->send_configure_change();
459         return 1;
460 }
461
462 CropPositionYSlider::CropPositionYSlider(CropWin *win, CropMain *client,
463         int x, int y, int w)
464  : BC_FSlider(x, y, 0, w, w, -100.00, 100.00, client->config.position_y)
465 {
466         this->win = win;
467         this->client = client;
468         enable_show_value(0); // Hide caption
469         set_precision(0.01);
470 }
471
472 CropPositionYSlider::~CropPositionYSlider()
473 {
474 }
475
476 int CropPositionYSlider::handle_event()
477 {
478         client->config.position_y = get_value();
479         win->crop_position_y_text->update(client->config.position_y);
480         win->update(RESET_ALL);
481         client->send_configure_change();
482         return 1;
483 }
484 /* *********************************** */
485
486
487 CropEdgesClr::CropEdgesClr(CropWin *win, CropMain *client, int x, int y, int clear)
488  : BC_Button(x, y, client->get_theme()->get_image_set("reset_button"))
489 {
490         this->win = win;
491         this->client = client;
492         this->clear = clear;
493 }
494 CropEdgesClr::~CropEdgesClr()
495 {
496 }
497 int CropEdgesClr::handle_event()
498 {
499         client->config.reset(clear);
500         win->update(clear);
501         client->send_configure_change();
502         return 1;
503 }
504
505 CropReset::CropReset(CropMain *client, CropWin *win, int x, int y)
506  : BC_GenericButton(x, y, _("Reset"))
507 {
508         this->client = client;
509         this->win = win;
510 }
511
512 CropReset::~CropReset()
513 {
514 }
515
516 int CropReset::handle_event()
517 {
518         client->config.reset(RESET_ALL);
519         win->update(RESET_ALL);
520         client->send_configure_change();
521         return 1;
522 }