add BC_SCALE env var for hi def monitors, cleanup theme data
[goodguy/cinelerra.git] / cinelerra-5.1 / plugins / mandelcuda / mandelbrotwindow.C
1 /*
2  * CINELERRA
3  * Copyright (C) 2014 Adam Williams <broadcast at earthling dot net>
4  * 
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  * 
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  * 
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18  * 
19  */
20
21 #include "bcdisplayinfo.h"
22 #include "clip.h"
23 #include "cwindow.h"
24 #include "cwindowgui.h"
25 #include "edl.h"
26 #include "edlsession.h"
27 #include "language.h"
28 #include "mandelbrot.h"
29 #include "mandelbrotwindow.h"
30 #include "mwindow.h"
31 #include "mwindowgui.h"
32 #include "pluginserver.h"
33 #include "theme.h"
34
35 MandelbrotWindow::MandelbrotWindow(Mandelbrot *plugin)
36  : PluginClientWindow(plugin, xS(180), yS(130), xS(180), yS(130), 0)
37 {
38         this->plugin = plugin; 
39         press_x = press_y = 0;
40         button_no = 0;
41         pending_config = 0;
42 }
43
44 MandelbrotWindow::~MandelbrotWindow()
45 {
46 }
47
48 void MandelbrotWindow::create_objects()
49 {
50         int x = xS(10), y = yS(10), pad = xS(5);
51         BC_Title *title;
52         add_subwindow(title = new BC_Title(x,y, _("Mandelbrot:"), MEDIUMFONT, YELLOW));
53         y += title->get_h() + pad;
54         add_subwindow(is_julia = new MandelbrotIsJulia(this, x, y));
55         y += is_julia->get_h() + pad;
56         add_subwindow(drag = new MandelbrotDrag(this, x, y));
57         y += drag->get_h() + pad;
58         add_subwindow(reset = new MandelbrotReset(this, x, y));
59         show_window();
60 }
61
62 void MandelbrotWindow::update_gui()
63 {
64 }
65
66
67 void MandelbrotWindow::send_configure_change()
68 {
69         pending_config = 0;
70         plugin->send_configure_change();
71 }
72
73 int MandelbrotWindow::grab_event(XEvent *event)
74 {
75         int ret = do_grab_event(event);
76         if( pending_config && !grab_event_count() )
77                 send_configure_change();
78         return ret;
79 }
80
81 int MandelbrotWindow::do_grab_event(XEvent *event)
82 {
83         switch( event->type ) {
84         case ButtonPress: break;
85         case ButtonRelease: break;
86         case MotionNotify: break;
87         default:
88                 return 0;
89         }
90
91         MWindow *mwindow = plugin->server->mwindow;
92         CWindowGUI *cwindow_gui = mwindow->cwindow->gui;
93         CWindowCanvas *canvas = cwindow_gui->canvas;
94         int cursor_x, cursor_y;
95         cwindow_gui->get_relative_cursor(cursor_x, cursor_y);
96         cursor_x -= canvas->view_x;
97         cursor_y -= canvas->view_y;
98         float output_x = cursor_x, output_y = cursor_y;
99         canvas->canvas_to_output(mwindow->edl, 0, output_x, output_y);
100
101         if( !button_no ) {
102                 if( cursor_x < 0 || cursor_x >= canvas->view_w ||
103                     cursor_y < 0 || cursor_y >= canvas->view_h )
104                         return 0;
105         }
106
107         switch( event->type ) {
108         case ButtonPress:
109                 if( button_no ) return 0;
110                 press_x = output_x;  press_y = output_y;
111                 button_no = event->xbutton.button;
112                 break;
113         case ButtonRelease:
114                 if( !button_no ) return 0;
115                 button_no = 0;
116                 return 1;
117         case MotionNotify: {
118                 if( !button_no ) return 0;
119                 EDL *edl = plugin->get_edl();
120                 double dx = 0, dy = 0, jx = 0, jy = 0, ds = 1;
121                 double out_w = edl->session->output_w, out_h = edl->session->output_h;
122                 double fx = (double)(press_x - output_x) / (2. * out_w);
123                 double fy = (double)(press_y - output_y) / (2. * out_h);
124                 press_x = output_x;  press_y = output_y;
125                 switch( button_no ) {
126                 case LEFT_BUTTON: {
127                         dx = fx * plugin->config.scale;
128                         dy = fy * plugin->config.scale;
129                         break; }
130                 case MIDDLE_BUTTON: {
131                         ds = fy >= 0.f ? 1-fy : 1/(1+fy);
132                         bclamp(ds, 1-0.05f, 1+0.05f);
133                         break; }
134                 case RIGHT_BUTTON: {
135                         jx = fx;
136                         jy = fy;
137                         break; }
138                 }
139                 plugin->config.x_off += dx;
140                 plugin->config.y_off += dy;
141                 plugin->config.x_julia += jx;
142                 plugin->config.y_julia += jy;
143                 plugin->config.scale *= ds;
144                 pending_config = 1;
145                 break; }
146         default:
147                 return 0;
148         }
149
150         return 1;
151 }
152
153 void MandelbrotWindow::done_event(int result)
154 {
155         ungrab(client->server->mwindow->cwindow->gui);
156 }
157 MandelbrotDrag::MandelbrotDrag(MandelbrotWindow *gui, int x, int y)
158  : BC_CheckBox(x, y, 0, _("Drag"))
159 {
160         this->gui = gui;
161 }
162 int MandelbrotDrag::handle_event()
163 {
164         CWindowGUI *cwindow_gui = gui->plugin->server->mwindow->cwindow->gui;
165         int value = get_value();
166         if( value ) {
167                 if( !gui->grab(cwindow_gui) ) {
168                         update(value = 0);
169                         flicker(10,50);
170                 }
171         }
172         else
173                 gui->ungrab(cwindow_gui);
174         return 1;
175 }
176
177 MandelbrotIsJulia::MandelbrotIsJulia(MandelbrotWindow *gui, int x, int y)
178  : BC_CheckBox(x, y, gui->plugin->config.is_julia, _("Julia"))
179 {
180         this->gui = gui;
181 }
182 MandelbrotIsJulia::~MandelbrotIsJulia()
183 {
184 }
185
186 int MandelbrotIsJulia::handle_event()
187 {
188         Mandelbrot *plugin = gui->plugin;
189         plugin->config.is_julia = get_value();
190         gui->send_configure_change();
191         return 1;
192 }
193
194 MandelbrotReset::MandelbrotReset(MandelbrotWindow *gui, int x, int y)
195  : BC_GenericButton(x, y, _("Reset"))
196 {
197         this->gui = gui;
198 }
199 MandelbrotReset::~MandelbrotReset()
200 {
201 }
202
203 int MandelbrotReset::handle_event()
204 {
205         Mandelbrot *plugin = gui->plugin;
206         int is_julia = plugin->config.is_julia;
207         plugin->config.reset();
208         if( is_julia )
209                 plugin->config.startJulia();
210         gui->send_configure_change();
211         return 1;
212 }
213
214
215