r1014: Enable horizontal scrolling with the mouse wheel by pressing Ctrl.
[cinelerra_cv/ct.git] / cinelerra / gwindowgui.C
blob22a1419439a9cb6c6d478c5dcfce9575995650ee
1 #include "autoconf.h"
2 #include "bcsignals.h"
3 #include "clip.h"
4 #include "edl.h"
5 #include "edlsession.h"
6 #include "gwindowgui.h"
7 #include "language.h"
8 #include "mainmenu.h"
9 #include "mainsession.h"
10 #include "mwindow.h"
11 #include "mwindowgui.h"
12 #include "trackcanvas.h"
18 GWindowGUI::GWindowGUI(MWindow *mwindow,
19         int w,
20         int h)
21  : BC_Window(PROGRAM_NAME N_(": Overlays"),
22         mwindow->session->gwindow_x, 
23     mwindow->session->gwindow_y, 
24     w, 
25     h,
26     w,
27     h,
28     0,
29     0,
30     1)
32         this->mwindow = mwindow;
35 static char *other_text[NONAUTOTOGGLES_COUNT] =
37         N_("Assets"),
38         N_("Titles"),
39         N_("Transitions"),
40         N_("Plugin Autos")
43 static char *auto_text[] = 
45         N_("Mute"),
46         N_("Camera X"),
47         N_("Camera Y"),
48         N_("Camera Z"),
49         N_("Projector X"),
50         N_("Projector Y"),
51         N_("Projector Z"),
52         N_("Fade"),
53         N_("Pan"),
54         N_("Mode"),
55         N_("Mask"),
56         N_("Nudge")
59 static toggleinfo toggle_order[] = 
61         {0, NONAUTOTOGGLES_ASSETS},
62         {0, NONAUTOTOGGLES_TITLES},
63         {0, NONAUTOTOGGLES_TRANSITIONS},
64         {1, AUTOMATION_FADE},
65         {1, AUTOMATION_MUTE},
66         {1, AUTOMATION_MODE},
67         {1, AUTOMATION_PAN},
68         {0, NONAUTOTOGGLES_PLUGIN_AUTOS},
69         {1, AUTOMATION_MASK},
70         {1, AUTOMATION_CAMERA_X},
71         {1, AUTOMATION_CAMERA_Y},
72         {1, AUTOMATION_CAMERA_Z},
73         {1, AUTOMATION_PROJECTOR_X},
74         {1, AUTOMATION_PROJECTOR_Y},
75         {1, AUTOMATION_PROJECTOR_Z},
78 void GWindowGUI::calculate_extents(BC_WindowBase *gui, int *w, int *h)
80         int temp1, temp2, temp3, temp4, temp5, temp6, temp7;
81         int current_w, current_h;
82         *w = 10;
83         *h = 10;
84         for(int i = 0; i < NONAUTOTOGGLES_COUNT + AUTOMATION_TOTAL; i++)
85         {
86                 BC_Toggle::calculate_extents(gui, 
87                         BC_WindowBase::get_resources()->checkbox_images,
88                         0,
89                         &temp1,
90                         &current_w,
91                         &current_h,
92                         &temp2,
93                         &temp3,
94                         &temp4,
95                         &temp5, 
96                         &temp6,
97                         &temp7, 
98                         toggle_order[i].isauto ? auto_text[toggle_order[i].ref] : other_text[toggle_order[i].ref]);
99                 *w = MAX(current_w, *w);
100                 *h += current_h + 5;
101         }
103         *h += 10;
104         *w += 20;
109 void GWindowGUI::create_objects()
111         int x = 10, y = 10;
114         for(int i = 0; i < NONAUTOTOGGLES_COUNT + AUTOMATION_TOTAL; i++)
115         {
116                 add_tool(toggles[i] = new GWindowToggle(mwindow, 
117                         this, 
118                         x, 
119                         y, 
120                         toggle_order[i]));
121                 y += toggles[i]->get_h() + 5;
122         }
125 void GWindowGUI::update_mwindow()
127         unlock_window();
128         mwindow->gui->mainmenu->update_toggles(1);
129         lock_window("GWindowGUI::update_mwindow");
132 void GWindowGUI::update_toggles(int use_lock)
134         if(use_lock) lock_window("GWindowGUI::update_toggles");
136         for(int i = 0; i < NONAUTOTOGGLES_COUNT + AUTOMATION_TOTAL; i++)
137         {
138                 toggles[i]->update();
139         }
141         if(use_lock) unlock_window();
144 int GWindowGUI::translation_event()
146         mwindow->session->gwindow_x = get_x();
147         mwindow->session->gwindow_y = get_y();
148         return 0;
151 int GWindowGUI::close_event()
153         hide_window();
154         mwindow->session->show_gwindow = 0;
155         unlock_window();
157         mwindow->gui->lock_window("GWindowGUI::close_event");
158         mwindow->gui->mainmenu->show_gwindow->set_checked(0);
159         mwindow->gui->unlock_window();
161         lock_window("GWindowGUI::close_event");
162         mwindow->save_defaults();
163         return 1;
166 int GWindowGUI::keypress_event()
168         switch(get_keypress())
169         {
170                 case 'w':
171                 case 'W':
172                         if(ctrl_down())
173                         {
174                                 close_event();
175                                 return 1;
176                         }
177                         break;
178         }
179         return 0;
187 GWindowToggle::GWindowToggle(MWindow *mwindow, 
188         GWindowGUI *gui, 
189         int x, 
190         int y, 
191         toggleinfo toggleinf)
192  : BC_CheckBox(x, 
193         y, 
194         *get_main_value(mwindow, toggleinf), 
195         toggleinf.isauto ? auto_text[toggleinf.ref] : other_text[toggleinf.ref])
197         this->mwindow = mwindow;
198         this->gui = gui;
199         this->toggleinf = toggleinf;
202 int GWindowToggle::handle_event()
204         *get_main_value(mwindow, toggleinf) = get_value();
205         gui->update_mwindow();
208 // Update stuff in MWindow
209         unlock_window();
210         mwindow->gui->lock_window("GWindowToggle::handle_event");
211         if(toggleinf.isauto)
212         {
213                 mwindow->gui->canvas->draw_overlays();
214                 mwindow->gui->canvas->flash();
215         }
216         else
217         {
218                 switch(toggleinf.ref)
219                 {
220                         case NONAUTOTOGGLES_ASSETS:
221                         case NONAUTOTOGGLES_TITLES:
222                                 mwindow->gui->update(1,
223                                         1,
224                                         0,
225                                         0,
226                                         1, 
227                                         0,
228                                         0);
229                                 break;
231                         case NONAUTOTOGGLES_TRANSITIONS:
232                         case NONAUTOTOGGLES_PLUGIN_AUTOS:
233                                 mwindow->gui->canvas->draw_overlays();
234                                 mwindow->gui->canvas->flash();
235                                 break;
236                 }
237         }
239         mwindow->gui->unlock_window();
240         lock_window("GWindowToggle::handle_event");
242         return 1;
245 int* GWindowToggle::get_main_value(MWindow *mwindow, toggleinfo toggleinf)
247         if(toggleinf.isauto)
248         {
249                 return &mwindow->edl->session->auto_conf->autos[toggleinf.ref];
250         }
251         else
252         {
253                 switch(toggleinf.ref)
254                 {
255                         case NONAUTOTOGGLES_ASSETS:
256                                 return &mwindow->edl->session->show_assets;
257                                 break;
258                         case NONAUTOTOGGLES_TITLES:
259                                 return &mwindow->edl->session->show_titles;
260                                 break;
261                         case NONAUTOTOGGLES_TRANSITIONS:
262                                 return &mwindow->edl->session->auto_conf->transitions;
263                                 break;
264                         case NONAUTOTOGGLES_PLUGIN_AUTOS:
265                                 return &mwindow->edl->session->auto_conf->plugins;
266                                 break;
267                 }
268         }
271 void GWindowToggle::update()
273         set_value(*get_main_value(mwindow, toggleinf));