rework keyframe hide popup, keyframe auto render, textbox set_selection wide text
[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 "trackcanvas.h"
34
35
36
37
38
39 GWindowGUI::GWindowGUI(MWindow *mwindow, int w, int h)
40  : BC_Window(_(PROGRAM_NAME ": Overlays"),
41         mwindow->session->gwindow_x, mwindow->session->gwindow_y,
42         w, h, w, h, 0, 0, 1)
43 {
44         this->mwindow = mwindow;
45 }
46
47 static const char *other_text[NON_AUTOMATION_TOTAL] =
48 {
49         _("Assets"),
50         _("Titles"),
51         _("Transitions"),
52         _("Plugin Autos")
53 };
54
55 static const char *auto_text[AUTOMATION_TOTAL] =
56 {
57         _("Mute"),
58         _("Camera X"),
59         _("Camera Y"),
60         _("Camera Z"),
61         _("Projector X"),
62         _("Projector Y"),
63         _("Projector Z"),
64         _("Fade"),
65         _("Pan"),
66         _("Mode"),
67         _("Mask"),
68         _("Speed")
69 };
70
71
72 static toggleinfo toggle_order[] =
73 {
74         {0, NON_AUTOMATION_ASSETS},
75         {0, NON_AUTOMATION_TITLES},
76         {0, NON_AUTOMATION_TRANSITIONS},
77         {1, AUTOMATION_FADE},
78         {1, AUTOMATION_MUTE},
79         {1, AUTOMATION_MODE},
80         {1, AUTOMATION_PAN},
81         {0, NON_AUTOMATION_PLUGIN_AUTOS},
82         {1, AUTOMATION_MASK},
83         {1, AUTOMATION_SPEED},
84         {1, AUTOMATION_CAMERA_X},
85         {1, AUTOMATION_CAMERA_Y},
86         {1, AUTOMATION_CAMERA_Z},
87         {1, AUTOMATION_PROJECTOR_X},
88         {1, AUTOMATION_PROJECTOR_Y},
89         {1, AUTOMATION_PROJECTOR_Z},
90 };
91
92 void GWindowGUI::calculate_extents(BC_WindowBase *gui, int *w, int *h)
93 {
94         int temp1, temp2, temp3, temp4, temp5, temp6, temp7;
95         int current_w, current_h;
96         *w = 10;
97         *h = 10;
98
99         for(int i = 0; i < NON_AUTOMATION_TOTAL + AUTOMATION_TOTAL; i++)
100         {
101                 BC_Toggle::calculate_extents(gui,
102                         BC_WindowBase::get_resources()->checkbox_images,
103                         0, &temp1, &current_w, &current_h,
104                         &temp2, &temp3, &temp4, &temp5, &temp6, &temp7,
105                         toggle_order[i].isauto ?
106                                 auto_text[toggle_order[i].ref] :
107                                 other_text[toggle_order[i].ref], MEDIUMFONT);
108                 *w = MAX(current_w, *w);
109                 *h += current_h + 5;
110         }
111
112         *h += 10;
113         *w += 20;
114 }
115
116
117
118 void GWindowGUI::create_objects()
119 {
120         int x = 10, y = 10;
121         lock_window("GWindowGUI::create_objects 1");
122
123
124         for(int i = 0; i < NON_AUTOMATION_TOTAL + AUTOMATION_TOTAL; i++)
125         {
126                 add_tool(toggles[i] = new GWindowToggle(mwindow,
127                         this,
128                         x,
129                         y,
130                         toggle_order[i]));
131                 y += toggles[i]->get_h() + 5;
132         }
133         unlock_window();
134 }
135
136 void GWindowGUI::update_mwindow()
137 {
138         unlock_window();
139         mwindow->gui->mainmenu->update_toggles(1);
140         lock_window("GWindowGUI::update_mwindow");
141 }
142
143 void GWindowGUI::update_toggles(int use_lock)
144 {
145         if(use_lock) lock_window("GWindowGUI::update_toggles");
146
147         for(int i = 0; i < NON_AUTOMATION_TOTAL + AUTOMATION_TOTAL; i++)
148         {
149                 toggles[i]->update();
150         }
151
152         if(use_lock) unlock_window();
153 }
154
155 int GWindowGUI::translation_event()
156 {
157         mwindow->session->gwindow_x = get_x();
158         mwindow->session->gwindow_y = get_y();
159         return 0;
160 }
161
162 int GWindowGUI::close_event()
163 {
164         hide_window();
165         mwindow->session->show_gwindow = 0;
166         unlock_window();
167
168         mwindow->gui->lock_window("GWindowGUI::close_event");
169         mwindow->gui->mainmenu->show_gwindow->set_checked(0);
170         mwindow->gui->unlock_window();
171
172         lock_window("GWindowGUI::close_event");
173         mwindow->save_defaults();
174         return 1;
175 }
176
177 int GWindowGUI::keypress_event()
178 {
179         switch(get_keypress())
180         {
181                 case 'w':
182                 case 'W':
183                         if(ctrl_down())
184                         {
185                                 close_event();
186                                 return 1;
187                         }
188                         break;
189         }
190         return 0;
191 }
192
193
194
195
196
197
198 GWindowToggle::GWindowToggle(MWindow *mwindow,
199         GWindowGUI *gui, int x, int y, toggleinfo toggleinf)
200  : BC_CheckBox(x, y, *get_main_value(mwindow, toggleinf),
201         toggleinf.isauto ? auto_text[toggleinf.ref] : other_text[toggleinf.ref])
202 {
203         this->mwindow = mwindow;
204         this->gui = gui;
205         this->toggleinf = toggleinf;
206 }
207
208 int GWindowToggle::handle_event()
209 {
210         *get_main_value(mwindow, toggleinf) = get_value();
211         gui->update_mwindow();
212
213
214 // Update stuff in MWindow
215         unlock_window();
216         mwindow->gui->lock_window("GWindowToggle::handle_event");
217         if(toggleinf.isauto)
218         {
219                 mwindow->gui->draw_overlays(1);
220         }
221         else
222         {
223                 switch(toggleinf.ref)
224                 {
225                         case NON_AUTOMATION_ASSETS:
226                         case NON_AUTOMATION_TITLES:
227                                 mwindow->gui->update(1, 1, 0, 0, 1, 0, 0);
228                                 break;
229
230                         case NON_AUTOMATION_TRANSITIONS:
231                         case NON_AUTOMATION_PLUGIN_AUTOS:
232                                 mwindow->gui->draw_overlays(1);
233                                 break;
234                 }
235         }
236
237         mwindow->gui->unlock_window();
238         lock_window("GWindowToggle::handle_event");
239
240         return 1;
241 }
242
243 int* GWindowToggle::get_main_value(MWindow *mwindow, toggleinfo toggleinf)
244 {
245         if(toggleinf.isauto)
246         {
247                 return &mwindow->edl->session->auto_conf->autos[toggleinf.ref];
248         }
249         else
250         {
251                 switch(toggleinf.ref)
252                 {
253                         case NON_AUTOMATION_ASSETS:
254                                 return &mwindow->edl->session->show_assets;
255                         case NON_AUTOMATION_TITLES:
256                                 return &mwindow->edl->session->show_titles;
257                         case NON_AUTOMATION_TRANSITIONS:
258                                 return &mwindow->edl->session->auto_conf->transitions;
259                         case NON_AUTOMATION_PLUGIN_AUTOS:
260                                 return &mwindow->edl->session->auto_conf->plugins;
261                 }
262         }
263         return 0;
264 }
265
266 void GWindowToggle::update()
267 {
268         set_value(*get_main_value(mwindow, toggleinf));
269 }
270
271
272