r885: Don't delete a borrowed frame.
[cinelerra_cv/ct.git] / cinelerra / gwindowgui.C
blobebe4bed7d045bb61f4c3f3f3a911d6f2c69d0aa2
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 "mainmenu.h"
8 #include "mainsession.h"
9 #include "mwindow.h"
10 #include "mwindowgui.h"
11 #include "trackcanvas.h"
17 GWindowGUI::GWindowGUI(MWindow *mwindow,
18         int w,
19         int h)
20  : BC_Window(PROGRAM_NAME ": Overlays",
21         mwindow->session->gwindow_x, 
22     mwindow->session->gwindow_y, 
23     w, 
24     h,
25     w,
26     h,
27     0,
28     0,
29     1)
31         this->mwindow = mwindow;
34 static char *other_text[OTHER_TOGGLES] =
36         "Assets",
37         "Titles",
38         "Transitions",
39         "Plugin Autos"
42 static char *auto_text[] = 
44         "Mute",
45         "Camera X",
46         "Camera Y",
47         "Camera Z",
48         "Projector X",
49         "Projector Y",
50         "Projector Z",
51         "Fade",
52         "Pan",
53         "Mode",
54         "Mask",
55         "Nudge"
58 void GWindowGUI::calculate_extents(BC_WindowBase *gui, int *w, int *h)
60         int temp1, temp2, temp3, temp4, temp5, temp6, temp7;
61         int current_w, current_h;
62         *w = 10;
63         *h = 10;
64         for(int i = 0; i < OTHER_TOGGLES; i++)
65         {
66                 BC_Toggle::calculate_extents(gui, 
67                         BC_WindowBase::get_resources()->checkbox_images,
68                         0,
69                         &temp1,
70                         &current_w,
71                         &current_h,
72                         &temp2,
73                         &temp3,
74                         &temp4,
75                         &temp5, 
76                         &temp6,
77                         &temp7, 
78                         other_text[i]);
79                 *w = MAX(current_w, *w);
80                 *h += current_h + 5;
81         }
83         for(int i = 0; i < AUTOMATION_TOTAL; i++)
84         {
85                 BC_Toggle::calculate_extents(gui, 
86                         BC_WindowBase::get_resources()->checkbox_images,
87                         0,
88                         &temp1,
89                         &current_w,
90                         &current_h,
91                         &temp2,
92                         &temp3,
93                         &temp4,
94                         &temp5, 
95                         &temp6,
96                         &temp7, 
97                         auto_text[i]);
98                 *w = MAX(current_w, *w);
99                 *h += current_h + 5;
100         }
101         *h += 10;
102         *w += 20;
107 void GWindowGUI::create_objects()
109         int x = 10, y = 10;
112         for(int i = 0; i < OTHER_TOGGLES; i++)
113         {
114                 add_tool(other[i] = new GWindowToggle(mwindow, 
115                         this, 
116                         x, 
117                         y, 
118                         -1,
119                         i, 
120                         other_text[i]));
121                 y += other[i]->get_h() + 5;
122         }
124         for(int i = 0; i < AUTOMATION_TOTAL; i++)
125         {
126                 add_tool(auto_toggle[i] = new GWindowToggle(mwindow, 
127                         this, 
128                         x, 
129                         y, 
130                         i,
131                         -1, 
132                         auto_text[i]));
133                 y += auto_toggle[i]->get_h() + 5;
134         }
137 void GWindowGUI::update_mwindow()
139         unlock_window();
140         mwindow->gui->mainmenu->update_toggles(1);
141         lock_window("GWindowGUI::update_mwindow");
144 void GWindowGUI::update_toggles(int use_lock)
146         if(use_lock) lock_window("GWindowGUI::update_toggles");
148         for(int i = 0; i < OTHER_TOGGLES; i++)
149         {
150                 other[i]->update();
151         }
153         for(int i = 0; i < AUTOMATION_TOTAL; i++)
154         {
155                 auto_toggle[i]->update();
156         }
158         if(use_lock) unlock_window();
161 int GWindowGUI::translation_event()
163         mwindow->session->gwindow_x = get_x();
164         mwindow->session->gwindow_y = get_y();
165         return 0;
168 int GWindowGUI::close_event()
170         hide_window();
171         mwindow->session->show_gwindow = 0;
172         unlock_window();
174         mwindow->gui->lock_window("GWindowGUI::close_event");
175         mwindow->gui->mainmenu->show_gwindow->set_checked(0);
176         mwindow->gui->unlock_window();
178         lock_window("GWindowGUI::close_event");
179         mwindow->save_defaults();
180         return 1;
183 int GWindowGUI::keypress_event()
185         switch(get_keypress())
186         {
187                 case 'w':
188                 case 'W':
189                         if(ctrl_down())
190                         {
191                                 close_event();
192                                 return 1;
193                         }
194                         break;
195         }
196         return 0;
204 GWindowToggle::GWindowToggle(MWindow *mwindow, 
205         GWindowGUI *gui, 
206         int x, 
207         int y, 
208         int subscript, 
209         int other,
210         char *text)
211  : BC_CheckBox(x, 
212         y, 
213         *get_main_value(mwindow, subscript, other), 
214         text)
216         this->mwindow = mwindow;
217         this->gui = gui;
218         this->subscript = subscript;
219         this->other = other;
222 int GWindowToggle::handle_event()
224         *get_main_value(mwindow, subscript, other) = get_value();
225         gui->update_mwindow();
228 // Update stuff in MWindow
229         unlock_window();
230         mwindow->gui->lock_window("GWindowToggle::handle_event");
231         if(subscript >= 0)
232         {
233                 mwindow->gui->canvas->draw_overlays();
234                 mwindow->gui->canvas->flash();
235         }
236         else
237         {
238                 switch(other)
239                 {
240                         case ASSETS:
241                         case TITLES:
242                                 mwindow->gui->update(1,
243                                         1,
244                                         0,
245                                         0,
246                                         1, 
247                                         0,
248                                         0);
249                                 break;
251                         case TRANSITIONS:
252                         case PLUGIN_AUTOS:
253                                 mwindow->gui->canvas->draw_overlays();
254                                 mwindow->gui->canvas->flash();
255                                 break;
256                 }
257         }
259         mwindow->gui->unlock_window();
260         lock_window("GWindowToggle::handle_event");
262         return 1;
265 int* GWindowToggle::get_main_value(MWindow *mwindow, int subscript, int other)
267         if(subscript >= 0)
268         {
269                 return &mwindow->edl->session->auto_conf->autos[subscript];
270         }
271         else
272         {
273                 switch(other)
274                 {
275                         case ASSETS:
276                                 return &mwindow->edl->session->show_assets;
277                                 break;
278                         case TITLES:
279                                 return &mwindow->edl->session->show_titles;
280                                 break;
281                         case TRANSITIONS:
282                                 return &mwindow->edl->session->auto_conf->transitions;
283                                 break;
284                         case PLUGIN_AUTOS:
285                                 return &mwindow->edl->session->auto_conf->plugins;
286                                 break;
287                 }
288         }
291 void GWindowToggle::update()
293         set_value(*get_main_value(mwindow, subscript, other));