prevent popup deactivation while button_down
[goodguy/history.git] / cinelerra-5.0 / cinelerra / gwindowgui.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 #include "autoconf.h"
23 #include "bcsignals.h"
24 #include "clip.h"
25 #include "edl.h"
26 #include "edlsession.h"
27 #include "gwindowgui.h"
28 #include "language.h"
29 #include "mainmenu.h"
30 #include "mainsession.h"
31 #include "mwindow.h"
32 #include "mwindowgui.h"
33 #include "trackcanvas.h"
34
35
36
37
38
39 GWindowGUI::GWindowGUI(MWindow *mwindow,
40         int w,
41         int h)
42  : BC_Window(_(PROGRAM_NAME ": Overlays"),
43         mwindow->session->gwindow_x, 
44     mwindow->session->gwindow_y, 
45     w, 
46     h,
47     w,
48     h,
49     0,
50     0,
51     1)
52 {
53         this->mwindow = mwindow;
54         drag_operation = 0;
55         new_status = 0;
56 }
57
58 static const char *other_text[OTHER_TOGGLES] =
59 {
60         _("Assets"),
61         _("Titles"),
62         _("Transitions"),
63         _("Plugin Autos")
64 };
65
66 static const char *auto_text[AUTOMATION_TOTAL] = 
67 {
68         _("Mute"),
69         _("Camera X"),
70         _("Camera Y"),
71         _("Camera Z"),
72         _("Projector X"),
73         _("Projector Y"),
74         _("Projector Z"),
75         _("Fade"),
76         _("Pan"),
77         _("Mode"),
78         _("Mask"),
79         _("Speed")
80 };
81
82 void GWindowGUI::calculate_extents(BC_WindowBase *gui, int *w, int *h)
83 {
84         int temp1, temp2, temp3, temp4, temp5, temp6, temp7;
85         int current_w, current_h;
86         *w = 10;
87         *h = 10;
88         for(int i = 0; i < OTHER_TOGGLES; i++)
89         {
90                 BC_Toggle::calculate_extents(gui, 
91                         BC_WindowBase::get_resources()->checkbox_images,
92                         0,
93                         &temp1,
94                         &current_w,
95                         &current_h,
96                         &temp2,
97                         &temp3,
98                         &temp4,
99                         &temp5, 
100                         &temp6,
101                         &temp7, 
102                         other_text[i],
103                         MEDIUMFONT);
104                 *w = MAX(current_w, *w);
105                 *h += current_h + 5;
106         }
107
108         for(int i = 0; i < AUTOMATION_TOTAL; i++)
109         {
110                 BC_Toggle::calculate_extents(gui, 
111                         BC_WindowBase::get_resources()->checkbox_images,
112                         0,
113                         &temp1,
114                         &current_w,
115                         &current_h,
116                         &temp2,
117                         &temp3,
118                         &temp4,
119                         &temp5, 
120                         &temp6,
121                         &temp7, 
122                         auto_text[i],
123                         MEDIUMFONT);
124                 *w = MAX(current_w, *w);
125                 *h += current_h + 5;
126         }
127         *h += 10;
128         *w += 20;
129 }
130
131
132
133 void GWindowGUI::create_objects()
134 {
135         int x = 10, y = 10;
136         lock_window("GWindowGUI::create_objects 1");
137
138
139         for(int i = 0; i < OTHER_TOGGLES; i++)
140         {
141                 add_tool(other[i] = new GWindowToggle(mwindow, 
142                         this, 
143                         x, 
144                         y, 
145                         -1,
146                         i, 
147                         other_text[i]));
148                 y += other[i]->get_h() + 5;
149         }
150
151         for(int i = 0; i < AUTOMATION_TOTAL; i++)
152         {
153                 add_tool(auto_toggle[i] = new GWindowToggle(mwindow, 
154                         this, 
155                         x, 
156                         y, 
157                         i,
158                         -1, 
159                         auto_text[i]));
160                 y += auto_toggle[i]->get_h() + 5;
161         }
162         unlock_window();
163 }
164
165 void GWindowGUI::update_mwindow()
166 {
167         unlock_window();
168         mwindow->gui->mainmenu->update_toggles(1);
169         lock_window("GWindowGUI::update_mwindow");
170 }
171
172 void GWindowGUI::update_toggles(int use_lock)
173 {
174         if(use_lock) lock_window("GWindowGUI::update_toggles");
175
176         for(int i = 0; i < OTHER_TOGGLES; i++)
177         {
178                 other[i]->update();
179         }
180
181         for(int i = 0; i < AUTOMATION_TOTAL; i++)
182         {
183                 auto_toggle[i]->update();
184         }
185
186         if(use_lock) unlock_window();
187 }
188
189 int GWindowGUI::translation_event()
190 {
191         mwindow->session->gwindow_x = get_x();
192         mwindow->session->gwindow_y = get_y();
193         return 0;
194 }
195
196 int GWindowGUI::close_event()
197 {
198         hide_window();
199         mwindow->session->show_gwindow = 0;
200         unlock_window();
201
202         mwindow->gui->lock_window("GWindowGUI::close_event");
203         mwindow->gui->mainmenu->show_gwindow->set_checked(0);
204         mwindow->gui->unlock_window();
205
206         lock_window("GWindowGUI::close_event");
207         mwindow->save_defaults();
208         return 1;
209 }
210
211 int GWindowGUI::keypress_event()
212 {
213         switch(get_keypress())
214         {
215                 case 'w':
216                 case 'W':
217                         if(ctrl_down())
218                         {
219                                 close_event();
220                                 return 1;
221                         }
222                         break;
223         }
224         return 0;
225 }
226
227 int GWindowGUI::cursor_motion_event()
228 {
229         //int cursor_x = get_relative_cursor_x();
230         int cursor_y = get_relative_cursor_y();
231         //int update_gui = 0;
232
233         if(drag_operation)
234         {
235                 if(cursor_y >= 0 &&
236                         cursor_y < get_h())
237                 {
238                         for(int i = 0; i < MAX(OTHER_TOGGLES, AUTOMATION_TOTAL); i++)
239                         {
240                                 if(i < OTHER_TOGGLES)
241                                 {
242                                         if(cursor_y >= other[i]->get_y() &&
243                                                 cursor_y < other[i]->get_y() + other[i]->get_h())
244                                         {
245                                                 other[i]->BC_Toggle::update(new_status);
246                                                 //update_gui = 1;
247                                         }
248                                 }
249                                 
250                                 if(i < AUTOMATION_TOTAL)
251                                 {
252                                         if(cursor_y >= auto_toggle[i]->get_y() &&
253                                                 cursor_y < auto_toggle[i]->get_y() + auto_toggle[i]->get_h())
254                                         {
255                                                 auto_toggle[i]->BC_Toggle::update(new_status);
256                                                 //update_gui = 1;
257                                         }
258                                 }
259                         }
260                 }
261         }
262         return 0;
263 }
264
265
266
267
268
269
270
271
272
273 GWindowToggle::GWindowToggle(MWindow *mwindow, 
274         GWindowGUI *gui, 
275         int x, 
276         int y, 
277         int subscript, 
278         int other,
279         const char *text)
280  : BC_CheckBox(x, 
281         y, 
282         *get_main_value(mwindow, subscript, other), 
283         text)
284 {
285         this->mwindow = mwindow;
286         this->gui = gui;
287         this->subscript = subscript;
288         this->other = other;
289         set_select_drag(1);
290 }
291
292
293 int GWindowToggle::button_press_event()
294 {
295         if(is_event_win() && get_buttonpress() == 1)
296         {
297 //printf("GWindowToggle::button_press_event %d %d\n", __LINE__, get_value());
298                 set_status(BC_Toggle::TOGGLE_DOWN);
299
300                 BC_Toggle::update(!get_value());
301                 gui->drag_operation = 1;
302                 gui->new_status = get_value();
303 //printf("GWindowToggle::button_press_event %d %d\n", __LINE__, get_value());
304
305                 return 1;
306         }
307         return 0;
308 }
309
310 int GWindowToggle::button_release_event()
311 {
312         int result = BC_Toggle::button_release_event();
313         gui->drag_operation = 0;
314         handle_event();
315         return result;
316 }
317
318
319
320 int GWindowToggle::handle_event()
321 {
322         *get_main_value(mwindow, subscript, other) = get_value();
323         gui->update_mwindow();
324
325
326 // Update stuff in MWindow
327         unlock_window();
328         mwindow->gui->lock_window("GWindowToggle::handle_event");
329         if(subscript >= 0)
330         {
331                 mwindow->gui->draw_overlays(1);
332         }
333         else
334         {
335                 switch(other)
336                 {
337                         case ASSETS:
338                         case TITLES:
339                                 mwindow->gui->update(1,
340                                         1,
341                                         0,
342                                         0,
343                                         1, 
344                                         0,
345                                         0);
346                                 break;
347
348                         case TRANSITIONS:
349                         case PLUGIN_AUTOS:
350                                 mwindow->gui->draw_overlays(1);
351                                 break;
352                 }
353         }
354
355         mwindow->gui->unlock_window();
356         lock_window("GWindowToggle::handle_event");
357
358         return 1;
359 }
360
361 int *GWindowToggle::get_main_value(MWindow *mwindow, int subscript, int other)
362 {
363         if(subscript >= 0)
364         {
365                 return &mwindow->edl->session->auto_conf->autos[subscript];
366         }
367         else
368         {
369                 switch(other)
370                 {
371                         case ASSETS:
372                                 return &mwindow->edl->session->show_assets;
373                                 break;
374                         case TITLES:
375                                 return &mwindow->edl->session->show_titles;
376                                 break;
377                         case TRANSITIONS:
378                                 return &mwindow->edl->session->auto_conf->transitions;
379                                 break;
380                         case PLUGIN_AUTOS:
381                                 return &mwindow->edl->session->auto_conf->plugins;
382                                 break;
383                 }
384         }
385         return 0;
386 }
387
388 void GWindowToggle::update()
389 {
390         set_value(*get_main_value(mwindow, subscript, other));
391 }
392
393
394