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