Anonymous Contribution of new Mirror plugin
[goodguy/cinelerra.git] / cinelerra-5.1 / plugins / mirror / mirrorwindow.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  * 2023. Derivative by Flip plugin.
24 */
25
26 #include "bcdisplayinfo.h"
27 #include "mirrorwindow.h"
28 #include "language.h"
29 #include "theme.h"
30
31
32
33
34
35
36
37 MirrorWindow::MirrorWindow(MirrorMain *client)
38  : PluginClientWindow(client, xS(420), yS(270), xS(420), yS(270), 0)
39 {
40         this->client = client;
41 }
42
43 MirrorWindow::~MirrorWindow()
44 {
45         delete mirror_horizontal;
46         delete mirror_swaphorizontal;
47         delete mirror_vertical;
48         delete mirror_swapvertical;
49         delete reflection_center_enable;
50         delete reflection_center_x_text;
51         delete reflection_center_x_slider;
52         delete reflection_center_y_text;
53         delete reflection_center_y_slider;
54         delete reflection_center_x_clr;
55         delete reflection_center_y_clr;
56         delete reset;
57 }
58
59 void MirrorWindow::create_objects()
60 {
61         int xs10 = xS(10), xs20 = xS(20), xs200 = xS(200);
62         int ys10 = yS(10), ys20 = yS(20), ys30 = yS(30), ys40 = yS(40);
63         int x2 = xS(60), x3 = xS(180);
64         int x = xs10, y = ys10;
65         int clr_x = get_w()-x - xS(22); // note: clrBtn_w = 22
66
67         BC_TitleBar *title_bar;
68         BC_Bar *bar;
69
70
71 // Direction section
72         add_subwindow(title_bar = new BC_TitleBar(x, y, get_w()-2*x, xs20, xs10, _("Direction")));
73         y += ys20;
74         add_tool(mirror_horizontal = new MirrorToggle(client,
75                 &(client->config.mirror_horizontal),
76                 _("Horizontal"),
77                 x,
78                 y));
79         add_tool(mirror_swaphorizontal = new MirrorSwapSide(client,
80                 &(client->config.mirror_swaphorizontal),
81                 _("Swap LEFT-RIGHT side"),
82                 (get_w() / 2),
83                 y));
84         y += ys30;
85         add_tool(mirror_vertical = new MirrorToggle(client,
86                 &(client->config.mirror_vertical),
87                 _("Vertical"),
88                 x,
89                 y));
90         add_tool(mirror_swapvertical = new MirrorSwapSide(client,
91                 &(client->config.mirror_swapvertical),
92                 _("Swap TOP-BOTTOM side"),
93                 (get_w() / 2),
94                 y));
95         y += ys40;
96         add_tool(reflection_center_enable = new MirrorReflectionCenter(this, client, x, y));
97         y += ys40;
98
99 // Reflection Center section
100         add_subwindow(title_bar = new BC_TitleBar(x, y, get_w()-2*x, xs20, xs10, _("Reflection Center")));
101         y += ys20;
102         add_tool(new BC_Title(x, y, _("X")));
103         add_tool(new BC_Title((x2-x), y, _("%")));
104         reflection_center_x_text = new MirrorReflectionCenterXText(this, client, (x + x2), y);
105         reflection_center_x_text->create_objects();
106         reflection_center_x_slider = new MirrorReflectionCenterXSlider(this, client, x3, y, xs200);
107         add_subwindow(reflection_center_x_slider);
108         add_subwindow(reflection_center_x_clr = new MirrorReflectionCenterClr(this, client,
109                 clr_x, y, RESET_REFLECTION_CENTER_X));
110         y += ys30;
111         add_tool(new BC_Title(x, y, _("Y")));
112         add_tool(new BC_Title((x2-x), y, _("%")));
113         reflection_center_y_text = new MirrorReflectionCenterYText(this, client, (x + x2), y);
114         reflection_center_y_text->create_objects();
115         reflection_center_y_slider = new MirrorReflectionCenterYSlider(this, client, x3, y, xs200);
116         add_subwindow(reflection_center_y_slider);
117         add_subwindow(reflection_center_y_clr = new MirrorReflectionCenterClr(this, client,
118                 clr_x, y, RESET_REFLECTION_CENTER_Y));
119         y += ys40;
120
121 // Reset section
122         add_subwindow(bar = new BC_Bar(x, y, get_w()-2*x));
123         y += ys10;
124         add_tool(reset = new MirrorReset(client, this, x, y));
125         show_window();
126         flush();
127
128 // Needed to update Enable-Disable GUI when "Show controls" is pressed.
129         update_reflection_center_enable();
130 }
131
132
133 void MirrorWindow::update_reflection_center_enable()
134 {
135         if(client->config.reflection_center_enable)
136         {
137                 reflection_center_x_text->enable();
138                 reflection_center_x_slider->enable();
139                 reflection_center_x_clr->enable();
140                 reflection_center_y_text->enable();
141                 reflection_center_y_slider->enable();
142                 reflection_center_y_clr->enable();
143                 mirror_swaphorizontal->disable();
144                 mirror_swaphorizontal->hide_window();
145                 mirror_swapvertical->disable();
146                 mirror_swapvertical->hide_window();
147         }
148         else
149         {
150                 reflection_center_x_text->disable();
151                 reflection_center_x_slider->disable();
152                 reflection_center_x_clr->disable();
153                 reflection_center_y_text->disable();
154                 reflection_center_y_slider->disable();
155                 reflection_center_y_clr->disable();
156                 mirror_swaphorizontal->enable();
157                 mirror_swaphorizontal->show_window();
158                 mirror_swapvertical->enable();
159                 mirror_swapvertical->show_window();
160         }
161 }
162
163 void MirrorWindow::update(int clear)
164 {
165         switch(clear) {
166                 case RESET_REFLECTION_CENTER_X :
167                         reflection_center_x_text->update((float)client->config.reflection_center_x);
168                         reflection_center_x_slider->update((float)client->config.reflection_center_x);
169                         mirror_horizontal->update(client->config.mirror_horizontal);
170                         mirror_swaphorizontal->update(client->config.mirror_swaphorizontal);
171                         break;
172                 case RESET_REFLECTION_CENTER_Y :
173                         reflection_center_y_text->update((float)client->config.reflection_center_y);
174                         reflection_center_y_slider->update((float)client->config.reflection_center_y);
175                         mirror_vertical->update(client->config.mirror_vertical);
176                         mirror_swapvertical->update(client->config.mirror_swapvertical);
177                         break;
178                 case RESET_ALL :
179                 case RESET_DEFAULT_SETTINGS :
180                 default:
181                         mirror_horizontal->update(client->config.mirror_horizontal);
182                         mirror_swaphorizontal->update(client->config.mirror_swaphorizontal);
183                         mirror_vertical->update(client->config.mirror_vertical);
184                         mirror_swapvertical->update(client->config.mirror_swapvertical);
185                         reflection_center_enable->update(client->config.reflection_center_enable);
186                         reflection_center_x_text->update((float)client->config.reflection_center_x);
187                         reflection_center_x_slider->update((float)client->config.reflection_center_x);
188                         reflection_center_y_text->update((float)client->config.reflection_center_y);
189                         reflection_center_y_slider->update((float)client->config.reflection_center_y);
190                         break;
191         }
192 }
193
194 MirrorToggle::MirrorToggle(MirrorMain *client, int *output, char *string, int x, int y)
195  : BC_CheckBox(x, y, *output, string)
196 {
197         this->client = client;
198         this->output = output;
199 }
200 MirrorToggle::~MirrorToggle()
201 {
202 }
203 int MirrorToggle::handle_event()
204 {
205         *output = get_value();
206         client->send_configure_change();
207         return 1;
208 }
209
210 MirrorSwapSide::MirrorSwapSide(MirrorMain *client, int *output, char *string, int x, int y)
211  : BC_CheckBox(x, y, *output, string)
212 {
213         this->client = client;
214         this->output = output;
215 }
216 MirrorSwapSide::~MirrorSwapSide()
217 {
218 }
219 int MirrorSwapSide::handle_event()
220 {
221         *output = get_value();
222         client->send_configure_change();
223         return 1;
224 }
225
226 MirrorReflectionCenter::MirrorReflectionCenter(MirrorWindow *window, MirrorMain *client, int x, int y)
227  : BC_CheckBox(x, y, client->config.reflection_center_enable, _("Enable Reflection Center"))
228 {
229         this->window = window;
230         this->client = client;
231 }
232 MirrorReflectionCenter::~MirrorReflectionCenter()
233 {
234 }
235 int MirrorReflectionCenter::handle_event()
236 {
237         client->config.reflection_center_enable = get_value();
238
239         if(client->config.reflection_center_enable)
240         {
241                 window->reflection_center_x_text->enable();
242                 window->reflection_center_x_slider->enable();
243                 window->reflection_center_x_clr->enable();
244                 window->reflection_center_y_text->enable();
245                 window->reflection_center_y_slider->enable();
246                 window->reflection_center_y_clr->enable();
247
248                 window->mirror_swaphorizontal->disable();
249                 window->mirror_swaphorizontal->hide_window();
250                 window->mirror_swapvertical->disable();
251                 window->mirror_swapvertical->hide_window();
252
253                 window->reflection_center_x_text->update(client->config.reflection_center_x);
254                 window->reflection_center_x_slider->update(client->config.reflection_center_x);
255                 window->reflection_center_y_text->update(client->config.reflection_center_y);
256                 window->reflection_center_y_slider->update(client->config.reflection_center_y);
257                 window->mirror_swaphorizontal->update(client->config.mirror_swaphorizontal);
258                 window->mirror_swapvertical->update(client->config.mirror_swapvertical);
259         }
260         else
261         {
262                 window->reflection_center_x_text->disable();
263                 window->reflection_center_x_slider->disable();
264                 window->reflection_center_x_clr->disable();
265                 window->reflection_center_y_text->disable();
266                 window->reflection_center_y_slider->disable();
267                 window->reflection_center_y_clr->disable();
268
269                 window->mirror_swaphorizontal->enable();
270                 window->mirror_swaphorizontal->show_window();
271                 window->mirror_swapvertical->enable();
272                 window->mirror_swapvertical->show_window();
273
274                 window->reflection_center_x_text->update(client->config.reflection_center_x);
275                 window->reflection_center_x_slider->update(client->config.reflection_center_x);
276                 window->reflection_center_y_text->update(client->config.reflection_center_y);
277                 window->reflection_center_y_slider->update(client->config.reflection_center_y);
278                 window->mirror_swaphorizontal->update(client->config.mirror_swaphorizontal);
279                 window->mirror_swapvertical->update(client->config.mirror_swapvertical);
280         }
281         client->send_configure_change();
282         return 1;
283 }
284
285 /* ********************************************** */
286 /* **** MIRROR REFLECTION CENTER X ************** */
287 MirrorReflectionCenterXText::MirrorReflectionCenterXText(MirrorWindow *window, MirrorMain *client,
288         int x,
289         int y)
290  : BC_TumbleTextBox(window, client->config.reflection_center_x,
291         (float)0.00, (float)100.00, x, y, xS(60), 2)
292 {
293         this->window = window;
294         this->client = client;
295 }
296
297 MirrorReflectionCenterXText::~MirrorReflectionCenterXText()
298 {
299 }
300
301 int MirrorReflectionCenterXText::handle_event()
302 {
303         client->config.reflection_center_x = atof(get_text());
304         if(client->config.reflection_center_x > 100.00) client->config.reflection_center_x = 100.00;
305         else if(client->config.reflection_center_x < 0.00) client->config.reflection_center_x = 0.00;
306         window->reflection_center_x_text->update(client->config.reflection_center_x);
307         window->reflection_center_x_slider->update(client->config.reflection_center_x);
308         client->send_configure_change();
309         return 1;
310 }
311
312 MirrorReflectionCenterXSlider::MirrorReflectionCenterXSlider(MirrorWindow *window, MirrorMain *client,
313         int x, int y, int w)
314  : BC_FSlider(x, y, 0, w, w, 0.00, 100.00, client->config.reflection_center_x)
315 {
316         this->window = window;
317         this->client = client;
318         enable_show_value(0); // Hide caption
319         set_precision(0.01);
320 }
321
322 MirrorReflectionCenterXSlider::~MirrorReflectionCenterXSlider()
323 {
324 }
325
326 int MirrorReflectionCenterXSlider::handle_event()
327 {
328         client->config.reflection_center_x = get_value();
329         window->reflection_center_x_text->update(client->config.reflection_center_x);
330         window->update(RESET_ALL);
331         client->send_configure_change();
332         return 1;
333 }
334 /* ********************************************** */
335
336 /* ********************************************** */
337 /* **** MIRROR REFLECTION CENTER Y ************** */
338 MirrorReflectionCenterYText::MirrorReflectionCenterYText(MirrorWindow *window, MirrorMain *client,
339         int x,
340         int y)
341  : BC_TumbleTextBox(window, client->config.reflection_center_y,
342         (float)0.00, (float)100.00, x, y, xS(60), 2)
343 {
344         this->window = window;
345         this->client = client;
346 }
347
348 MirrorReflectionCenterYText::~MirrorReflectionCenterYText()
349 {
350 }
351
352 int MirrorReflectionCenterYText::handle_event()
353 {
354         client->config.reflection_center_y = atof(get_text());
355         if(client->config.reflection_center_y > 100.00) client->config.reflection_center_y = 100.00;
356         else if(client->config.reflection_center_y < 0.00) client->config.reflection_center_y = 0.00;
357         window->reflection_center_y_text->update(client->config.reflection_center_y);
358         window->reflection_center_y_slider->update(client->config.reflection_center_y);
359         client->send_configure_change();
360         return 1;
361 }
362
363 MirrorReflectionCenterYSlider::MirrorReflectionCenterYSlider(MirrorWindow *window, MirrorMain *client,
364         int x, int y, int w)
365  : BC_FSlider(x, y, 0, w, w, 0.00, 100.00, client->config.reflection_center_y)
366 {
367         this->window = window;
368         this->client = client;
369         enable_show_value(0); // Hide caption
370         set_precision(0.01);
371 }
372
373 MirrorReflectionCenterYSlider::~MirrorReflectionCenterYSlider()
374 {
375 }
376
377 int MirrorReflectionCenterYSlider::handle_event()
378 {
379         client->config.reflection_center_y = get_value();
380         window->reflection_center_y_text->update(client->config.reflection_center_y);
381         window->update(RESET_ALL);
382         client->send_configure_change();
383         return 1;
384 }
385 /* ********************************************** */
386
387
388 MirrorReflectionCenterClr::MirrorReflectionCenterClr(MirrorWindow *window, MirrorMain *client, int x, int y, int clear)
389  : BC_Button(x, y, client->get_theme()->get_image_set("reset_button"))
390 {
391         this->window = window;
392         this->client = client;
393         this->clear = clear;
394 }
395 MirrorReflectionCenterClr::~MirrorReflectionCenterClr()
396 {
397 }
398 int MirrorReflectionCenterClr::handle_event()
399 {
400         client->config.reset(clear);
401         window->update(clear);
402         client->send_configure_change();
403         return 1;
404 }
405
406 MirrorReset::MirrorReset(MirrorMain *client, MirrorWindow *window, int x, int y)
407  : BC_GenericButton(x, y, _("Reset"))
408 {
409         this->client = client;
410         this->window = window;
411 }
412
413 MirrorReset::~MirrorReset()
414 {
415 }
416
417 int MirrorReset::handle_event()
418 {
419         client->config.reset(RESET_ALL);
420         window->update_reflection_center_enable();
421         window->update(RESET_ALL);
422         client->send_configure_change();
423         return 1;
424 }