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