color coded keyframe curves, keyframe popups, cwin scrollbar fixes
[goodguy/history.git] / cinelerra-5.1 / 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 "theme.h"
34 #include "trackcanvas.h"
35
36
37
38
39
40 GWindowGUI::GWindowGUI(MWindow *mwindow, int w, int h)
41  : BC_Window(_(PROGRAM_NAME ": Overlays"),
42         mwindow->session->gwindow_x, mwindow->session->gwindow_y,
43         w, h, w, h, 0, 0, 1)
44 {
45         this->mwindow = mwindow;
46 }
47
48 const char *GWindowGUI::other_text[NON_AUTOMATION_TOTAL] =
49 {
50         "Assets",
51         "Titles",
52         "Transitions",
53         "Plugin Autos"
54 };
55
56 const char *GWindowGUI::auto_text[AUTOMATION_TOTAL] =
57 {
58         "Mute",
59         "Camera X",
60         "Camera Y",
61         "Camera Z",
62         "Projector X",
63         "Projector Y",
64         "Projector Z",
65         "Fade",
66         "Pan",
67         "Mode",
68         "Mask",
69         "Speed"
70 };
71
72 int GWindowGUI::auto_colors[AUTOMATION_TOTAL] =
73 {
74         PINK,
75         RED,
76         GREEN,
77         BLUE,
78         LTPINK,
79         LTGREEN,
80         LTBLUE,
81         LTPURPLE,
82         0,
83         0,
84         0,
85         ORANGE,
86 };
87
88
89 static toggleinfo toggle_order[] =
90 {
91         {0, NON_AUTOMATION_ASSETS},
92         {0, NON_AUTOMATION_TITLES},
93         {0, NON_AUTOMATION_TRANSITIONS},
94         {0, NON_AUTOMATION_PLUGIN_AUTOS},
95         {0, -1}, // bar
96         {1, AUTOMATION_FADE},
97         {1, AUTOMATION_MUTE},
98         {1, AUTOMATION_SPEED},
99         {1, AUTOMATION_CAMERA_X},
100         {1, AUTOMATION_CAMERA_Y},
101         {1, AUTOMATION_CAMERA_Z},
102         {1, AUTOMATION_PROJECTOR_X},
103         {1, AUTOMATION_PROJECTOR_Y},
104         {1, AUTOMATION_PROJECTOR_Z},
105         {1, AUTOMATION_MODE},
106         {1, AUTOMATION_PAN},
107         {1, AUTOMATION_MASK},
108 };
109
110 void GWindowGUI::calculate_extents(BC_WindowBase *gui, int *w, int *h)
111 {
112         int temp1, temp2, temp3, temp4, temp5, temp6, temp7;
113         int current_w, current_h;
114         *w = 10;
115         *h = 10;
116
117         for( int i=0; i<(int)(sizeof(toggle_order)/sizeof(toggle_order[0])); ++i ) {
118                 toggleinfo *tp = &toggle_order[i];
119                 int isauto = tp->isauto, ref = tp->ref;
120                 if( ref < 0 ) {
121                         *h += get_resources()->bar_data->get_h() + 5;
122                         continue;
123                 }
124                 BC_Toggle::calculate_extents(gui,
125                         BC_WindowBase::get_resources()->checkbox_images,
126                         0, &temp1, &current_w, &current_h,
127                         &temp2, &temp3, &temp4, &temp5, &temp6, &temp7,
128                         _(isauto ?  auto_text[ref] : other_text[ref]),
129                         MEDIUMFONT);
130                 *w = MAX(current_w, *w);
131                 *h += current_h + 5;
132         }
133
134         *h += 10;
135         *w += 20;
136 }
137
138
139
140 void GWindowGUI::create_objects()
141 {
142         int x = 10, y = 10;
143         lock_window("GWindowGUI::create_objects 1");
144
145         for( int i=0; i<(int)(sizeof(toggle_order)/sizeof(toggle_order[0])); ++i ) {
146                 toggleinfo *tp = &toggle_order[i];
147                 int ref = tp->ref;
148                 if( ref < 0 ) {
149                         BC_Bar *bar = new BC_Bar(x,y,get_w()-x-10);
150                         add_tool(bar);
151                         toggles[i] = 0;
152                         y += bar->get_h() + 5;
153                         continue;
154                 }
155                 toggles[i] = new GWindowToggle(mwindow, this, x, y, *tp);
156                 add_tool(toggles[i]);
157                 VFrame *vframe = 0;
158                 switch( ref ) {
159                 case AUTOMATION_MODE: vframe = mwindow->theme->modekeyframe_data;  break;
160                 case AUTOMATION_PAN:  vframe = mwindow->theme->pankeyframe_data;   break;
161                 case AUTOMATION_MASK: vframe = mwindow->theme->maskkeyframe_data;  break;
162                 }
163                 if( vframe )
164                         draw_vframe(vframe, get_w()-vframe->get_w()-10, y);
165                 y += toggles[i]->get_h() + 5;
166         }
167         unlock_window();
168 }
169
170 void GWindowGUI::update_mwindow()
171 {
172         unlock_window();
173         mwindow->gui->mainmenu->update_toggles(1);
174         lock_window("GWindowGUI::update_mwindow");
175 }
176
177 void GWindowGUI::update_toggles(int use_lock)
178 {
179         if(use_lock) lock_window("GWindowGUI::update_toggles");
180
181         for( int i=0; i<(int)(sizeof(toggle_order)/sizeof(toggle_order[0])); ++i ) {
182                 if( toggles[i] ) toggles[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         case 'w':
214         case 'W':
215         case '0':
216                 if( ctrl_down() ) {
217                         close_event();
218                         return 1;
219                 }
220                 break;
221         }
222         return 0;
223 }
224
225
226 GWindowToggle::GWindowToggle(MWindow *mwindow,
227         GWindowGUI *gui, int x, int y, toggleinfo toggleinf)
228  : BC_CheckBox(x, y, *get_main_value(mwindow, toggleinf),
229         _((toggleinf.isauto ?
230                 GWindowGUI::auto_text[toggleinf.ref] :
231                 GWindowGUI::other_text[toggleinf.ref])),
232         MEDIUMFONT,
233         !toggleinf.isauto ? -1 : GWindowGUI::auto_colors[toggleinf.ref])
234 {
235         this->mwindow = mwindow;
236         this->gui = gui;
237         this->toggleinf = toggleinf;
238 }
239
240 int GWindowToggle::handle_event()
241 {
242         *get_main_value(mwindow, toggleinf) = get_value();
243         gui->update_mwindow();
244
245
246 // Update stuff in MWindow
247         unlock_window();
248         mwindow->gui->lock_window("GWindowToggle::handle_event");
249         if(toggleinf.isauto)
250         {
251                 mwindow->gui->draw_overlays(1);
252         }
253         else
254         {
255                 switch(toggleinf.ref)
256                 {
257                         case NON_AUTOMATION_ASSETS:
258                         case NON_AUTOMATION_TITLES:
259                                 mwindow->gui->update(1, 1, 0, 0, 1, 0, 0);
260                                 break;
261
262                         case NON_AUTOMATION_TRANSITIONS:
263                         case NON_AUTOMATION_PLUGIN_AUTOS:
264                                 mwindow->gui->draw_overlays(1);
265                                 break;
266                 }
267         }
268
269         mwindow->gui->unlock_window();
270         lock_window("GWindowToggle::handle_event");
271
272         return 1;
273 }
274
275 int* GWindowToggle::get_main_value(MWindow *mwindow, toggleinfo toggleinf)
276 {
277         if( toggleinf.isauto )
278                 return &mwindow->edl->session->auto_conf->autos[toggleinf.ref];
279
280         switch(toggleinf.ref) {
281         case NON_AUTOMATION_ASSETS: return &mwindow->edl->session->show_assets;
282         case NON_AUTOMATION_TITLES: return &mwindow->edl->session->show_titles;
283         case NON_AUTOMATION_TRANSITIONS: return &mwindow->edl->session->auto_conf->transitions;
284         case NON_AUTOMATION_PLUGIN_AUTOS: return &mwindow->edl->session->auto_conf->plugins;
285         }
286         return 0;
287 }
288
289 void GWindowToggle::update()
290 {
291         int *vp = get_main_value(mwindow, toggleinf);
292         if( !vp ) return;
293         set_value(*vp);
294 }
295
296
297