fix awdw solo vicon crash, fix nested clip for binfolders, open edit edl
[goodguy/cinelerra.git] / cinelerra-5.1 / cinelerra / cpanel.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 "automation.h"
23 #include "cpanel.h"
24 #include "cwindow.h"
25 #include "cwindowgui.h"
26 #include "cwindowtool.h"
27 #include "edl.h"
28 #include "edlsession.h"
29 #include "floatauto.h"
30 #include "language.h"
31 #include "mbuttons.h"
32 #include "mwindow.h"
33 #include "mwindowgui.h"
34 #include "theme.h"
35 #include "track.h"
36
37
38
39
40 CPanel::CPanel(MWindow *mwindow,
41         CWindowGUI *subwindow,
42         int x,
43         int y,
44         int w,
45         int h)
46 {
47         this->mwindow = mwindow;
48         this->subwindow = subwindow;
49         this->x = x;
50         this->y = y;
51         this->w = w;
52         this->h = h;
53 }
54
55 CPanel::~CPanel()
56 {
57 }
58
59 void CPanel::create_objects()
60 {
61         int x = this->x, y = this->y;
62         subwindow->add_subwindow(operation[CWINDOW_PROTECT] = new CPanelProtect(mwindow, this, x, y));
63         y += operation[CWINDOW_PROTECT]->get_h();
64         subwindow->add_subwindow(operation[CWINDOW_ZOOM] = new CPanelMagnify(mwindow, this, x, y));
65         y += operation[CWINDOW_ZOOM]->get_h();
66         subwindow->add_subwindow(operation[CWINDOW_MASK] = new CPanelMask(mwindow, this, x, y));
67         y += operation[CWINDOW_MASK]->get_h();
68         subwindow->add_subwindow(operation[CWINDOW_RULER] = new CPanelRuler(mwindow, this, x, y));
69         y += operation[CWINDOW_RULER]->get_h();
70         subwindow->add_subwindow(operation[CWINDOW_CAMERA] = new CPanelCamera(mwindow, this, x, y));
71         y += operation[CWINDOW_CAMERA]->get_h();
72         subwindow->add_subwindow(operation[CWINDOW_PROJECTOR] = new CPanelProj(mwindow, this, x, y));
73         y += operation[CWINDOW_PROJECTOR]->get_h();
74         subwindow->add_subwindow(operation[CWINDOW_CROP] = new CPanelCrop(mwindow, this, x, y));
75         y += operation[CWINDOW_CROP]->get_h();
76         subwindow->add_subwindow(operation[CWINDOW_EYEDROP] = new CPanelEyedrop(mwindow, this, x, y));
77         y += operation[CWINDOW_EYEDROP]->get_h();
78         subwindow->add_subwindow(operation[CWINDOW_TOOL_WINDOW] = new CPanelToolWindow(mwindow, this, x, y));
79         y += operation[CWINDOW_TOOL_WINDOW]->get_h();
80         subwindow->add_subwindow(operation[CWINDOW_TITLESAFE] = new CPanelTitleSafe(mwindow, this, x, y));
81         y += operation[CWINDOW_TITLESAFE]->get_h();
82         x += (w - BC_Slider::get_span(1)) / 2;  y += yS(15);
83         subwindow->add_subwindow(cpanel_zoom = new CPanelZoom(mwindow, this, x, y, h-y-yS(20)));
84 }
85
86 void CPanel::reposition_buttons(int x, int y, int h)
87 {
88         this->x = x;
89         this->y = y;
90         this->h = h;
91
92         for(int i = 0; i < CPANEL_OPERATIONS; i++)
93         {
94                 operation[i]->reposition_window(x, y);
95                 y += operation[i]->get_h();
96         }
97         x += (w - BC_Slider::get_span(1)) / 2;
98         y += yS(15);
99         h = this->h - this->y;
100         cpanel_zoom->reposition_window(x, y, w, h-y-yS(20));
101         cpanel_zoom->set_pointer_motion_range(h);
102 }
103
104
105 void CPanel::set_operation(int value)
106 {
107         for(int i = 0; i < CPANEL_OPERATIONS; i++)
108         {
109                 if(i == CWINDOW_TOOL_WINDOW)
110                 {
111                         operation[i]->update(mwindow->edl->session->tool_window);
112                 }
113                 else
114                 if(i == CWINDOW_TITLESAFE)
115                 {
116                         operation[i]->update(mwindow->edl->session->safe_regions);
117                 }
118                 else
119 //              if(i == CWINDOW_SHOW_METERS)
120 //              {
121 //                      operation[i]->update(mwindow->edl->session->cwindow_meter);
122 //              }
123 //              else
124                 {
125                         if(i != value)
126                                 operation[i]->update(0);
127                         else
128                                 operation[i]->update(1);
129                 }
130         }
131         if( operation[CWINDOW_ZOOM]->get_value() ||
132             operation[CWINDOW_CAMERA]->get_value() ||
133             operation[CWINDOW_PROJECTOR]->get_value() ) {
134                 cpanel_zoom->set_shown(1);
135                 subwindow->update_canvas(0);
136         }
137         else
138                 cpanel_zoom->set_shown(0);
139 }
140
141
142
143
144
145 CPanelProtect::CPanelProtect(MWindow *mwindow, CPanel *gui, int x, int y)
146  : BC_Toggle(x,
147         y,
148         mwindow->theme->get_image_set("protect"),
149         mwindow->edl->session->cwindow_operation == CWINDOW_PROTECT)
150 {
151         this->mwindow = mwindow;
152         this->gui = gui;
153         set_tooltip(_("Protect video from changes (F1)"));
154 }
155 CPanelProtect::~CPanelProtect()
156 {
157 }
158 int CPanelProtect::handle_event()
159 {
160         gui->subwindow->set_operation(CWINDOW_PROTECT);
161         return 1;
162 }
163
164
165
166
167
168
169 CPanelMask::CPanelMask(MWindow *mwindow, CPanel *gui, int x, int y)
170  : BC_Toggle(x,
171         y,
172         mwindow->theme->get_image_set("mask"),
173         mwindow->edl->session->cwindow_operation == CWINDOW_MASK)
174 {
175         this->mwindow = mwindow;
176         this->gui = gui;
177         set_tooltip(_("Edit mask (F3)"));
178 }
179 CPanelMask::~CPanelMask()
180 {
181 }
182 int CPanelMask::handle_event()
183 {
184         gui->subwindow->set_operation(CWINDOW_MASK);
185         return 1;
186 }
187
188
189
190
191 CPanelRuler::CPanelRuler(MWindow *mwindow, CPanel *gui, int x, int y)
192  : BC_Toggle(x,
193         y,
194         mwindow->theme->get_image_set("ruler"),
195         mwindow->edl->session->cwindow_operation == CWINDOW_RULER)
196 {
197         this->mwindow = mwindow;
198         this->gui = gui;
199         set_tooltip(_("Ruler (F4)"));
200 }
201 CPanelRuler::~CPanelRuler()
202 {
203 }
204 int CPanelRuler::handle_event()
205 {
206         gui->subwindow->set_operation(CWINDOW_RULER);
207         return 1;
208 }
209
210
211
212
213 CPanelMagnify::CPanelMagnify(MWindow *mwindow, CPanel *gui, int x, int y)
214  : BC_Toggle(x,
215         y,
216         mwindow->theme->get_image_set("magnify"),
217         mwindow->edl->session->cwindow_operation == CWINDOW_ZOOM)
218 {
219         this->mwindow = mwindow;
220         this->gui = gui;
221         set_tooltip(_("Zoom view (F2)"));
222 }
223 CPanelMagnify::~CPanelMagnify()
224 {
225 }
226 int CPanelMagnify::handle_event()
227 {
228         gui->subwindow->set_operation(CWINDOW_ZOOM);
229         return 1;
230 }
231
232
233 CPanelCamera::CPanelCamera(MWindow *mwindow, CPanel *gui, int x, int y)
234  : BC_Toggle(x,
235         y,
236         mwindow->theme->get_image_set("camera"),
237         mwindow->edl->session->cwindow_operation == CWINDOW_CAMERA)
238 {
239         this->mwindow = mwindow;
240         this->gui = gui;
241         set_tooltip(_("Adjust camera automation (F5)"));
242 }
243 CPanelCamera::~CPanelCamera()
244 {
245 }
246 int CPanelCamera::handle_event()
247 {
248         gui->subwindow->set_operation(CWINDOW_CAMERA);
249         return 1;
250 }
251
252
253 CPanelProj::CPanelProj(MWindow *mwindow, CPanel *gui, int x, int y)
254  : BC_Toggle(x,
255         y,
256         mwindow->theme->get_image_set("projector"),
257         mwindow->edl->session->cwindow_operation == CWINDOW_PROJECTOR)
258 {
259         this->mwindow = mwindow;
260         this->gui = gui;
261         set_tooltip(_("Adjust projector automation (F6)"));
262 }
263 CPanelProj::~CPanelProj()
264 {
265 }
266 int CPanelProj::handle_event()
267 {
268         gui->subwindow->set_operation(CWINDOW_PROJECTOR);
269         return 1;
270 }
271
272
273 CPanelCrop::CPanelCrop(MWindow *mwindow, CPanel *gui, int x, int y)
274  : BC_Toggle(x,
275         y,
276         mwindow->theme->get_image_set("crop"),
277         mwindow->edl->session->cwindow_operation == CWINDOW_CROP)
278 {
279         this->mwindow = mwindow;
280         this->gui = gui;
281         set_tooltip(_("Crop a layer or output (F7)"));
282 }
283
284 CPanelCrop::~CPanelCrop()
285 {
286 }
287
288 int CPanelCrop::handle_event()
289 {
290         gui->subwindow->set_operation(CWINDOW_CROP);
291         return 1;
292 }
293
294
295
296
297 CPanelEyedrop::CPanelEyedrop(MWindow *mwindow, CPanel *gui, int x, int y)
298  : BC_Toggle(x,
299         y,
300         mwindow->theme->get_image_set("eyedrop"),
301         mwindow->edl->session->cwindow_operation == CWINDOW_EYEDROP)
302 {
303         this->mwindow = mwindow;
304         this->gui = gui;
305         set_tooltip(_("Get color (F8)"));
306 }
307
308 CPanelEyedrop::~CPanelEyedrop()
309 {
310 }
311
312 int CPanelEyedrop::handle_event()
313 {
314         gui->subwindow->set_operation(CWINDOW_EYEDROP);
315         return 1;
316 }
317
318
319
320
321 CPanelToolWindow::CPanelToolWindow(MWindow *mwindow, CPanel *gui, int x, int y)
322  : BC_Toggle(x,
323         y,
324         mwindow->theme->get_image_set("tool"),
325         mwindow->edl->session->tool_window)
326 {
327         this->mwindow = mwindow;
328         this->gui = gui;
329         set_tooltip(_("Show tool info (F9)"));
330 }
331
332 CPanelToolWindow::~CPanelToolWindow()
333 {
334 }
335
336 int CPanelToolWindow::handle_event()
337 {
338         mwindow->edl->session->tool_window = get_value();
339         gui->subwindow->tool_panel->update_show_window();
340         return 1;
341 }
342
343 int CPanelToolWindow::set_shown(int shown)
344 {
345         set_value(shown);
346         mwindow->edl->session->tool_window = shown;
347         gui->subwindow->tool_panel->update_show_window();
348         return 1;
349 }
350
351
352 CPanelTitleSafe::CPanelTitleSafe(MWindow *mwindow, CPanel *gui, int x, int y)
353  : BC_Toggle(x,
354         y,
355         mwindow->theme->get_image_set("titlesafe"),
356         mwindow->edl->session->safe_regions)
357 {
358         this->mwindow = mwindow;
359         this->gui = gui;
360         set_tooltip(_("Show safe regions (F10)"));
361 }
362 CPanelTitleSafe::~CPanelTitleSafe()
363 {
364 }
365 int CPanelTitleSafe::handle_event()
366 {
367         mwindow->edl->session->safe_regions = get_value();
368         return gui->subwindow->canvas->refresh(1);
369 }
370
371 CPanelZoom::CPanelZoom(MWindow *mwindow, CPanel *gui, int x, int y, int h)
372  : BC_FSlider(x, y, 1, h, h, -2., 2., 0, 0)
373 {
374         this->mwindow = mwindow;
375         this->gui = gui;
376         set_precision(0.001);
377         set_tooltip(_("Zoom"));
378 }
379 CPanelZoom::~CPanelZoom()
380 {
381 }
382 int CPanelZoom::handle_event()
383 {
384         FloatAuto *z_auto = 0;
385         int aidx = -1;
386         float value = get_value();
387         BC_FSlider::update(value);
388         double zoom = pow(10.,value);
389         switch( mwindow->edl->session->cwindow_operation ) {
390         case CWINDOW_ZOOM:
391                 gui->subwindow->canvas->set_zoom(mwindow->edl, zoom);
392                 gui->subwindow->update_canvas();
393                 break;
394         case CWINDOW_CAMERA:
395                 aidx = AUTOMATION_CAMERA_Z;
396                 break;
397         case CWINDOW_PROJECTOR:
398                 aidx = AUTOMATION_PROJECTOR_Z;
399                 break;
400         }
401         if( aidx < 0 ) return 1;
402         Track *track = mwindow->cwindow->calculate_affected_track();
403         if( !track ) return 1;
404         z_auto = (FloatAuto*)mwindow->cwindow->calculate_affected_auto(
405                         track->automation->autos[aidx], 1);
406         if( !z_auto ) return 1;
407         z_auto->set_value(zoom);
408         gui->subwindow->sync_parameters(CHANGE_PARAMS, 1, 1);
409         return 1;
410 }
411
412 int CPanelZoom::set_shown(int shown)
413 {
414         if( shown ) {
415                 show();
416                 update(gui->subwindow->canvas->get_zoom());
417         }
418         else
419                 hide();
420         return 1;
421 }
422
423 char *CPanelZoom::get_caption()
424 {
425         double value = get_value();
426         int frac = value >= 0. ? 1 : value >= -1. ? 2 : 3;
427         double zoom = pow(10., value);
428         char *caption = BC_Slider::get_caption();
429         sprintf(caption, "%.*f", frac, zoom);
430         return caption;
431 }
432
433 void CPanelZoom::update(float zoom)
434 {
435         if( !is_hidden() ) {
436                 if( zoom < 0.01 ) zoom = 0.01;
437                 float value = log10f(zoom);
438                 BC_FSlider::update(value);
439         }
440 }
441