3 * Copyright (C) 2014 Adam Williams <broadcast at earthling dot net>
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.
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.
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
21 #include "bcdisplayinfo.h"
24 #include "cwindowgui.h"
26 #include "edlsession.h"
28 #include "mandelbrot.h"
29 #include "mandelbrotwindow.h"
31 #include "mwindowgui.h"
32 #include "pluginserver.h"
35 MandelbrotWindow::MandelbrotWindow(Mandelbrot *plugin)
36 : PluginClientWindow(plugin, xS(180), yS(130), xS(180), yS(130), 0)
38 this->plugin = plugin;
39 press_x = press_y = 0;
44 MandelbrotWindow::~MandelbrotWindow()
48 void MandelbrotWindow::create_objects()
50 int x = xS(10), y = yS(10), pad = xS(5);
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));
62 void MandelbrotWindow::update_gui()
67 void MandelbrotWindow::send_configure_change()
70 plugin->send_configure_change();
73 int MandelbrotWindow::grab_event(XEvent *event)
75 int ret = do_grab_event(event);
76 if( pending_config && !grab_event_count() )
77 send_configure_change();
81 int MandelbrotWindow::do_grab_event(XEvent *event)
83 switch( event->type ) {
84 case ButtonPress: break;
85 case ButtonRelease: break;
86 case MotionNotify: break;
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);
102 if( cursor_x < 0 || cursor_x >= canvas->view_w ||
103 cursor_y < 0 || cursor_y >= canvas->view_h )
107 switch( event->type ) {
109 if( button_no ) return 0;
110 press_x = output_x; press_y = output_y;
111 button_no = event->xbutton.button;
114 if( !button_no ) return 0;
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 ) {
127 dx = fx * plugin->config.scale;
128 dy = fy * plugin->config.scale;
130 case MIDDLE_BUTTON: {
131 ds = fy >= 0.f ? 1-fy : 1/(1+fy);
132 bclamp(ds, 1-0.05f, 1+0.05f);
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;
153 void MandelbrotWindow::done_event(int result)
155 ungrab(client->server->mwindow->cwindow->gui);
157 MandelbrotDrag::MandelbrotDrag(MandelbrotWindow *gui, int x, int y)
158 : BC_CheckBox(x, y, 0, _("Drag"))
162 int MandelbrotDrag::handle_event()
164 CWindowGUI *cwindow_gui = gui->plugin->server->mwindow->cwindow->gui;
166 if( !gui->grab(cwindow_gui) ) {
172 gui->ungrab(cwindow_gui);
175 int MandelbrotDrag::handle_ungrab()
177 CWindowGUI *cwindow_gui = gui->plugin->server->mwindow->cwindow->gui;
178 int ret = gui->ungrab(cwindow_gui);
179 if( ret ) update(*value = 0);
183 MandelbrotIsJulia::MandelbrotIsJulia(MandelbrotWindow *gui, int x, int y)
184 : BC_CheckBox(x, y, gui->plugin->config.is_julia, _("Julia"))
188 MandelbrotIsJulia::~MandelbrotIsJulia()
192 int MandelbrotIsJulia::handle_event()
194 Mandelbrot *plugin = gui->plugin;
195 plugin->config.is_julia = get_value();
196 gui->send_configure_change();
200 MandelbrotReset::MandelbrotReset(MandelbrotWindow *gui, int x, int y)
201 : BC_GenericButton(x, y, _("Reset"))
205 MandelbrotReset::~MandelbrotReset()
209 int MandelbrotReset::handle_event()
211 Mandelbrot *plugin = gui->plugin;
212 int is_julia = plugin->config.is_julia;
213 plugin->config.reset();
215 plugin->config.startJulia();
216 gui->send_configure_change();