8788b047ab3361f84fba3ef4ba93c9f1378eb299
[goodguy/history.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 += 15;
83         subwindow->add_subwindow(cpanel_zoom = new CPanelZoom(mwindow, this, x, y, h-y-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 += 15;
99         h = this->h - this->y;
100         cpanel_zoom->reposition_window(x, y, w, h-y-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         }
136         else
137                 cpanel_zoom->set_shown(0);
138 }
139
140
141
142
143
144 CPanelProtect::CPanelProtect(MWindow *mwindow, CPanel *gui, int x, int y)
145  : BC_Toggle(x,
146         y,
147         mwindow->theme->get_image_set("protect"),
148         mwindow->edl->session->cwindow_operation == CWINDOW_PROTECT)
149 {
150         this->mwindow = mwindow;
151         this->gui = gui;
152         set_tooltip(_("Protect video from changes"));
153 }
154 CPanelProtect::~CPanelProtect()
155 {
156 }
157 int CPanelProtect::handle_event()
158 {
159         gui->subwindow->set_operation(CWINDOW_PROTECT);
160         return 1;
161 }
162
163
164
165
166
167
168 CPanelMask::CPanelMask(MWindow *mwindow, CPanel *gui, int x, int y)
169  : BC_Toggle(x,
170         y,
171         mwindow->theme->get_image_set("mask"),
172         mwindow->edl->session->cwindow_operation == CWINDOW_MASK)
173 {
174         this->mwindow = mwindow;
175         this->gui = gui;
176         set_tooltip(_("Edit mask"));
177 }
178 CPanelMask::~CPanelMask()
179 {
180 }
181 int CPanelMask::handle_event()
182 {
183         gui->subwindow->set_operation(CWINDOW_MASK);
184         return 1;
185 }
186
187
188
189
190 CPanelRuler::CPanelRuler(MWindow *mwindow, CPanel *gui, int x, int y)
191  : BC_Toggle(x,
192         y,
193         mwindow->theme->get_image_set("ruler"),
194         mwindow->edl->session->cwindow_operation == CWINDOW_RULER)
195 {
196         this->mwindow = mwindow;
197         this->gui = gui;
198         set_tooltip(_("Ruler"));
199 }
200 CPanelRuler::~CPanelRuler()
201 {
202 }
203 int CPanelRuler::handle_event()
204 {
205         gui->subwindow->set_operation(CWINDOW_RULER);
206         return 1;
207 }
208
209
210
211
212 CPanelMagnify::CPanelMagnify(MWindow *mwindow, CPanel *gui, int x, int y)
213  : BC_Toggle(x,
214         y,
215         mwindow->theme->get_image_set("magnify"),
216         mwindow->edl->session->cwindow_operation == CWINDOW_ZOOM)
217 {
218         this->mwindow = mwindow;
219         this->gui = gui;
220         set_tooltip(_("Zoom view"));
221 }
222 CPanelMagnify::~CPanelMagnify()
223 {
224 }
225 int CPanelMagnify::handle_event()
226 {
227         gui->subwindow->set_operation(CWINDOW_ZOOM);
228         return 1;
229 }
230
231
232 CPanelCamera::CPanelCamera(MWindow *mwindow, CPanel *gui, int x, int y)
233  : BC_Toggle(x,
234         y,
235         mwindow->theme->get_image_set("camera"),
236         mwindow->edl->session->cwindow_operation == CWINDOW_CAMERA)
237 {
238         this->mwindow = mwindow;
239         this->gui = gui;
240         set_tooltip(_("Adjust camera automation"));
241 }
242 CPanelCamera::~CPanelCamera()
243 {
244 }
245 int CPanelCamera::handle_event()
246 {
247         gui->subwindow->set_operation(CWINDOW_CAMERA);
248         return 1;
249 }
250
251
252 CPanelProj::CPanelProj(MWindow *mwindow, CPanel *gui, int x, int y)
253  : BC_Toggle(x,
254         y,
255         mwindow->theme->get_image_set("projector"),
256         mwindow->edl->session->cwindow_operation == CWINDOW_PROJECTOR)
257 {
258         this->mwindow = mwindow;
259         this->gui = gui;
260         set_tooltip(_("Adjust projector automation"));
261 }
262 CPanelProj::~CPanelProj()
263 {
264 }
265 int CPanelProj::handle_event()
266 {
267         gui->subwindow->set_operation(CWINDOW_PROJECTOR);
268         return 1;
269 }
270
271
272 CPanelCrop::CPanelCrop(MWindow *mwindow, CPanel *gui, int x, int y)
273  : BC_Toggle(x,
274         y,
275         mwindow->theme->get_image_set("crop"),
276         mwindow->edl->session->cwindow_operation == CWINDOW_CROP)
277 {
278         this->mwindow = mwindow;
279         this->gui = gui;
280         set_tooltip(_("Crop a layer or output"));
281 }
282
283 CPanelCrop::~CPanelCrop()
284 {
285 }
286
287 int CPanelCrop::handle_event()
288 {
289         gui->subwindow->set_operation(CWINDOW_CROP);
290         return 1;
291 }
292
293
294
295
296 CPanelEyedrop::CPanelEyedrop(MWindow *mwindow, CPanel *gui, int x, int y)
297  : BC_Toggle(x,
298         y,
299         mwindow->theme->get_image_set("eyedrop"),
300         mwindow->edl->session->cwindow_operation == CWINDOW_EYEDROP)
301 {
302         this->mwindow = mwindow;
303         this->gui = gui;
304         set_tooltip(_("Get color"));
305 }
306
307 CPanelEyedrop::~CPanelEyedrop()
308 {
309 }
310
311 int CPanelEyedrop::handle_event()
312 {
313         gui->subwindow->set_operation(CWINDOW_EYEDROP);
314         return 1;
315 }
316
317
318
319
320 CPanelToolWindow::CPanelToolWindow(MWindow *mwindow, CPanel *gui, int x, int y)
321  : BC_Toggle(x,
322         y,
323         mwindow->theme->get_image_set("tool"),
324         mwindow->edl->session->tool_window)
325 {
326         this->mwindow = mwindow;
327         this->gui = gui;
328         set_tooltip(_("Show tool info"));
329 }
330
331 CPanelToolWindow::~CPanelToolWindow()
332 {
333 }
334
335 int CPanelToolWindow::handle_event()
336 {
337         mwindow->edl->session->tool_window = get_value();
338         gui->subwindow->tool_panel->update_show_window();
339         return 1;
340 }
341
342 int CPanelToolWindow::set_shown(int shown)
343 {
344         set_value(shown);
345         mwindow->edl->session->tool_window = shown;
346         gui->subwindow->tool_panel->update_show_window();
347         return 1;
348 }
349
350
351 CPanelTitleSafe::CPanelTitleSafe(MWindow *mwindow, CPanel *gui, int x, int y)
352  : BC_Toggle(x,
353         y,
354         mwindow->theme->get_image_set("titlesafe"),
355         mwindow->edl->session->safe_regions)
356 {
357         this->mwindow = mwindow;
358         this->gui = gui;
359         set_tooltip(_("Show safe regions"));
360 }
361 CPanelTitleSafe::~CPanelTitleSafe()
362 {
363 }
364 int CPanelTitleSafe::handle_event()
365 {
366         mwindow->edl->session->safe_regions = get_value();
367         gui->subwindow->canvas->draw_refresh();
368         return 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->zoom_canvas(zoom, 1);
392                 break;
393         case CWINDOW_CAMERA:
394                 aidx = AUTOMATION_CAMERA_Z;
395                 break;
396         case CWINDOW_PROJECTOR:
397                 aidx = AUTOMATION_PROJECTOR_Z;
398                 break;
399         }
400         if( aidx < 0 ) return 1;
401         Track *track = mwindow->cwindow->calculate_affected_track();
402         if( !track ) return 1;
403         z_auto = (FloatAuto*)mwindow->cwindow->calculate_affected_auto(
404                         track->automation->autos[aidx], 1);
405         if( !z_auto ) return 1;
406         z_auto->set_value(zoom);
407         gui->subwindow->update_tool();
408         mwindow->gui->lock_window("CPanelZoom::handle_event 1");
409         mwindow->gui->draw_overlays(1);
410         mwindow->gui->unlock_window();
411         mwindow->sync_parameters(CHANGE_PARAMS);
412         return 1;
413 }
414
415 int CPanelZoom::set_shown(int shown)
416 {
417         if( shown ) {
418                 show_window();
419                 update(gui->subwindow->canvas->get_zoom());
420         }
421         else
422                 hide_window();
423         return 1;
424 }
425
426 char *CPanelZoom::get_caption()
427 {
428         double value = get_value();
429         int frac = value >= 0. ? 1 : value >= -1. ? 2 : 3;
430         double zoom = pow(10., value);
431         char *caption = BC_Slider::get_caption();
432         sprintf(caption, "%.*f", frac, zoom);
433         return caption;
434 }
435
436 void CPanelZoom::update(float zoom)
437 {
438         if( !is_hidden() ) {
439                 if( zoom < 0.01 ) zoom = 0.01;
440                 float value = log(zoom) / log(10.);
441                 BC_FSlider::update(value);
442         }
443 }
444