add missing GPL information in guicast program files
[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 // *** CONTEXT_HELP ***
155         context_help_set_keyword("Compositor Toolbar");
156 }
157 CPanelProtect::~CPanelProtect()
158 {
159 }
160 int CPanelProtect::handle_event()
161 {
162         gui->subwindow->set_operation(CWINDOW_PROTECT);
163         return 1;
164 }
165
166
167
168
169
170
171 CPanelMask::CPanelMask(MWindow *mwindow, CPanel *gui, int x, int y)
172  : BC_Toggle(x,
173         y,
174         mwindow->theme->get_image_set("mask"),
175         mwindow->edl->session->cwindow_operation == CWINDOW_MASK)
176 {
177         this->mwindow = mwindow;
178         this->gui = gui;
179         set_tooltip(_("Edit mask (F3)"));
180 // *** CONTEXT_HELP ***
181         context_help_set_keyword("Masks");
182 }
183 CPanelMask::~CPanelMask()
184 {
185 }
186 int CPanelMask::handle_event()
187 {
188         gui->subwindow->set_operation(CWINDOW_MASK);
189         return 1;
190 }
191
192
193
194
195 CPanelRuler::CPanelRuler(MWindow *mwindow, CPanel *gui, int x, int y)
196  : BC_Toggle(x,
197         y,
198         mwindow->theme->get_image_set("ruler"),
199         mwindow->edl->session->cwindow_operation == CWINDOW_RULER)
200 {
201         this->mwindow = mwindow;
202         this->gui = gui;
203         set_tooltip(_("Ruler (F4)"));
204 // *** CONTEXT_HELP ***
205         context_help_set_keyword("Compositor Toolbar");
206 }
207 CPanelRuler::~CPanelRuler()
208 {
209 }
210 int CPanelRuler::handle_event()
211 {
212         gui->subwindow->set_operation(CWINDOW_RULER);
213         return 1;
214 }
215
216
217
218
219 CPanelMagnify::CPanelMagnify(MWindow *mwindow, CPanel *gui, int x, int y)
220  : BC_Toggle(x,
221         y,
222         mwindow->theme->get_image_set("magnify"),
223         mwindow->edl->session->cwindow_operation == CWINDOW_ZOOM)
224 {
225         this->mwindow = mwindow;
226         this->gui = gui;
227         set_tooltip(_("Zoom view (F2)"));
228 // *** CONTEXT_HELP ***
229         context_help_set_keyword("Compositor Toolbar");
230 }
231 CPanelMagnify::~CPanelMagnify()
232 {
233 }
234 int CPanelMagnify::handle_event()
235 {
236         gui->subwindow->set_operation(CWINDOW_ZOOM);
237         return 1;
238 }
239
240
241 CPanelCamera::CPanelCamera(MWindow *mwindow, CPanel *gui, int x, int y)
242  : BC_Toggle(x,
243         y,
244         mwindow->theme->get_image_set("camera"),
245         mwindow->edl->session->cwindow_operation == CWINDOW_CAMERA)
246 {
247         this->mwindow = mwindow;
248         this->gui = gui;
249         set_tooltip(_("Adjust camera automation (F5)"));
250 // *** CONTEXT_HELP ***
251         context_help_set_keyword("Camera and Projector");
252 }
253 CPanelCamera::~CPanelCamera()
254 {
255 }
256 int CPanelCamera::handle_event()
257 {
258         gui->subwindow->set_operation(CWINDOW_CAMERA);
259         return 1;
260 }
261
262
263 CPanelProj::CPanelProj(MWindow *mwindow, CPanel *gui, int x, int y)
264  : BC_Toggle(x,
265         y,
266         mwindow->theme->get_image_set("projector"),
267         mwindow->edl->session->cwindow_operation == CWINDOW_PROJECTOR)
268 {
269         this->mwindow = mwindow;
270         this->gui = gui;
271         set_tooltip(_("Adjust projector automation (F6)"));
272 // *** CONTEXT_HELP ***
273         context_help_set_keyword("Camera and Projector");
274 }
275 CPanelProj::~CPanelProj()
276 {
277 }
278 int CPanelProj::handle_event()
279 {
280         gui->subwindow->set_operation(CWINDOW_PROJECTOR);
281         return 1;
282 }
283
284
285 CPanelCrop::CPanelCrop(MWindow *mwindow, CPanel *gui, int x, int y)
286  : BC_Toggle(x,
287         y,
288         mwindow->theme->get_image_set("crop"),
289         mwindow->edl->session->cwindow_operation == CWINDOW_CROP)
290 {
291         this->mwindow = mwindow;
292         this->gui = gui;
293         set_tooltip(_("Crop a layer or output (F7)"));
294 // *** CONTEXT_HELP ***
295         context_help_set_keyword("Cropping");
296 }
297
298 CPanelCrop::~CPanelCrop()
299 {
300 }
301
302 int CPanelCrop::handle_event()
303 {
304         gui->subwindow->set_operation(CWINDOW_CROP);
305         return 1;
306 }
307
308
309
310
311 CPanelEyedrop::CPanelEyedrop(MWindow *mwindow, CPanel *gui, int x, int y)
312  : BC_Toggle(x,
313         y,
314         mwindow->theme->get_image_set("eyedrop"),
315         mwindow->edl->session->cwindow_operation == CWINDOW_EYEDROP)
316 {
317         this->mwindow = mwindow;
318         this->gui = gui;
319         set_tooltip(_("Get color (F8)"));
320 // *** CONTEXT_HELP ***
321         context_help_set_keyword("Compositor Toolbar");
322 }
323
324 CPanelEyedrop::~CPanelEyedrop()
325 {
326 }
327
328 int CPanelEyedrop::handle_event()
329 {
330         gui->subwindow->set_operation(CWINDOW_EYEDROP);
331         return 1;
332 }
333
334
335
336
337 CPanelToolWindow::CPanelToolWindow(MWindow *mwindow, CPanel *gui, int x, int y)
338  : BC_Toggle(x,
339         y,
340         mwindow->theme->get_image_set("tool"),
341         mwindow->edl->session->tool_window)
342 {
343         this->mwindow = mwindow;
344         this->gui = gui;
345         set_tooltip(_("Show tool info (F9)"));
346 // *** CONTEXT_HELP ***
347         context_help_set_keyword("Compositor Toolbar");
348 }
349
350 CPanelToolWindow::~CPanelToolWindow()
351 {
352 }
353
354 int CPanelToolWindow::handle_event()
355 {
356         mwindow->edl->session->tool_window = get_value();
357         gui->subwindow->tool_panel->update_show_window();
358         return 1;
359 }
360
361 int CPanelToolWindow::set_shown(int shown)
362 {
363         set_value(shown);
364         mwindow->edl->session->tool_window = shown;
365         gui->subwindow->tool_panel->update_show_window();
366         return 1;
367 }
368
369
370 CPanelTitleSafe::CPanelTitleSafe(MWindow *mwindow, CPanel *gui, int x, int y)
371  : BC_Toggle(x,
372         y,
373         mwindow->theme->get_image_set("titlesafe"),
374         mwindow->edl->session->safe_regions)
375 {
376         this->mwindow = mwindow;
377         this->gui = gui;
378         set_tooltip(_("Show safe regions (F10)"));
379 // *** CONTEXT_HELP ***
380         context_help_set_keyword("Compositor Toolbar");
381 }
382 CPanelTitleSafe::~CPanelTitleSafe()
383 {
384 }
385 int CPanelTitleSafe::handle_event()
386 {
387         mwindow->edl->session->safe_regions = get_value();
388         return gui->subwindow->canvas->refresh(1);
389 }
390
391 CPanelZoom::CPanelZoom(MWindow *mwindow, CPanel *gui, int x, int y, int h)
392  : BC_FSlider(x, y, 1, h, h, -2., 2., 0, 0)
393 {
394         this->mwindow = mwindow;
395         this->gui = gui;
396         set_precision(0.001);
397         set_tooltip(_("Zoom"));
398 }
399 CPanelZoom::~CPanelZoom()
400 {
401 }
402 int CPanelZoom::handle_event()
403 {
404         FloatAuto *z_auto = 0;
405         int aidx = -1;
406         float value = get_value();
407         BC_FSlider::update(value);
408         double zoom = pow(10.,value);
409         switch( mwindow->edl->session->cwindow_operation ) {
410         case CWINDOW_ZOOM:
411                 gui->subwindow->canvas->set_zoom(mwindow->edl, zoom);
412                 gui->subwindow->update_canvas();
413                 break;
414         case CWINDOW_CAMERA:
415                 aidx = AUTOMATION_CAMERA_Z;
416                 break;
417         case CWINDOW_PROJECTOR:
418                 aidx = AUTOMATION_PROJECTOR_Z;
419                 break;
420         }
421         if( aidx < 0 ) return 1;
422         Track *track = mwindow->cwindow->calculate_affected_track();
423         if( !track ) return 1;
424         z_auto = (FloatAuto*)mwindow->cwindow->calculate_affected_auto(
425                         track->automation->autos[aidx], 1);
426         if( !z_auto ) return 1;
427         z_auto->set_value(zoom);
428         gui->subwindow->sync_parameters(CHANGE_PARAMS, 1, 1);
429         return 1;
430 }
431
432 int CPanelZoom::set_shown(int shown)
433 {
434         if( shown ) {
435                 show();
436                 update(gui->subwindow->canvas->get_zoom());
437         }
438         else
439                 hide();
440         return 1;
441 }
442
443 char *CPanelZoom::get_caption()
444 {
445         double value = get_value();
446         int frac = value >= 0. ? 1 : value >= -1. ? 2 : 3;
447         double zoom = pow(10., value);
448         char *caption = BC_Slider::get_caption();
449         sprintf(caption, "%.*f", frac, zoom);
450         return caption;
451 }
452
453 void CPanelZoom::update(float zoom)
454 {
455         if( !is_hidden() ) {
456                 if( zoom < 0.01 ) zoom = 0.01;
457                 float value = log10f(zoom);
458                 BC_FSlider::update(value);
459         }
460 }
461