add zoom slider, fix stop_playback on quit, new msg.txt, rework filelist
[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;
83         subwindow->add_subwindow(cpanel_zoom = new CPanelZoom(mwindow, this, x, y+15, h-y-15));
84 }
85
86 void CPanel::reposition_buttons(int x, int y)
87 {
88         this->x = x;
89         this->y = y;
90
91         for(int i = 0; i < CPANEL_OPERATIONS; i++)
92         {
93                 operation[i]->reposition_window(x, y);
94                 y += operation[i]->get_h();
95         }
96         x += (w - BC_Slider::get_span(1)) / 2;
97         cpanel_zoom->reposition_window(x, y+15);
98 }
99
100
101 void CPanel::set_operation(int value)
102 {
103         for(int i = 0; i < CPANEL_OPERATIONS; i++)
104         {
105                 if(i == CWINDOW_TOOL_WINDOW)
106                 {
107                         operation[i]->update(mwindow->edl->session->tool_window);
108                 }
109                 else
110                 if(i == CWINDOW_TITLESAFE)
111                 {
112                         operation[i]->update(mwindow->edl->session->safe_regions);
113                 }
114                 else
115 //              if(i == CWINDOW_SHOW_METERS)
116 //              {
117 //                      operation[i]->update(mwindow->edl->session->cwindow_meter);
118 //              }
119 //              else
120                 {
121                         if(i != value)
122                                 operation[i]->update(0);
123                         else
124                                 operation[i]->update(1);
125                 }
126         }
127         if( operation[CWINDOW_ZOOM]->get_value() ||
128             operation[CWINDOW_CAMERA]->get_value() ||
129             operation[CWINDOW_PROJECTOR]->get_value() ) {
130                 cpanel_zoom->set_shown(1);
131         }
132         else
133                 cpanel_zoom->set_shown(0);
134 }
135
136
137
138
139
140 CPanelProtect::CPanelProtect(MWindow *mwindow, CPanel *gui, int x, int y)
141  : BC_Toggle(x,
142         y,
143         mwindow->theme->get_image_set("protect"),
144         mwindow->edl->session->cwindow_operation == CWINDOW_PROTECT)
145 {
146         this->mwindow = mwindow;
147         this->gui = gui;
148         set_tooltip(_("Protect video from changes"));
149 }
150 CPanelProtect::~CPanelProtect()
151 {
152 }
153 int CPanelProtect::handle_event()
154 {
155         gui->subwindow->set_operation(CWINDOW_PROTECT);
156         return 1;
157 }
158
159
160
161
162
163
164 CPanelMask::CPanelMask(MWindow *mwindow, CPanel *gui, int x, int y)
165  : BC_Toggle(x,
166         y,
167         mwindow->theme->get_image_set("mask"),
168         mwindow->edl->session->cwindow_operation == CWINDOW_MASK)
169 {
170         this->mwindow = mwindow;
171         this->gui = gui;
172         set_tooltip(_("Edit mask"));
173 }
174 CPanelMask::~CPanelMask()
175 {
176 }
177 int CPanelMask::handle_event()
178 {
179         gui->subwindow->set_operation(CWINDOW_MASK);
180         return 1;
181 }
182
183
184
185
186 CPanelRuler::CPanelRuler(MWindow *mwindow, CPanel *gui, int x, int y)
187  : BC_Toggle(x,
188         y,
189         mwindow->theme->get_image_set("ruler"),
190         mwindow->edl->session->cwindow_operation == CWINDOW_RULER)
191 {
192         this->mwindow = mwindow;
193         this->gui = gui;
194         set_tooltip(_("Ruler"));
195 }
196 CPanelRuler::~CPanelRuler()
197 {
198 }
199 int CPanelRuler::handle_event()
200 {
201         gui->subwindow->set_operation(CWINDOW_RULER);
202         return 1;
203 }
204
205
206
207
208 CPanelMagnify::CPanelMagnify(MWindow *mwindow, CPanel *gui, int x, int y)
209  : BC_Toggle(x,
210         y,
211         mwindow->theme->get_image_set("magnify"),
212         mwindow->edl->session->cwindow_operation == CWINDOW_ZOOM)
213 {
214         this->mwindow = mwindow;
215         this->gui = gui;
216         set_tooltip(_("Zoom view"));
217 }
218 CPanelMagnify::~CPanelMagnify()
219 {
220 }
221 int CPanelMagnify::handle_event()
222 {
223         gui->subwindow->set_operation(CWINDOW_ZOOM);
224         return 1;
225 }
226
227
228 CPanelCamera::CPanelCamera(MWindow *mwindow, CPanel *gui, int x, int y)
229  : BC_Toggle(x,
230         y,
231         mwindow->theme->get_image_set("camera"),
232         mwindow->edl->session->cwindow_operation == CWINDOW_CAMERA)
233 {
234         this->mwindow = mwindow;
235         this->gui = gui;
236         set_tooltip(_("Adjust camera automation"));
237 }
238 CPanelCamera::~CPanelCamera()
239 {
240 }
241 int CPanelCamera::handle_event()
242 {
243         gui->subwindow->set_operation(CWINDOW_CAMERA);
244         return 1;
245 }
246
247
248 CPanelProj::CPanelProj(MWindow *mwindow, CPanel *gui, int x, int y)
249  : BC_Toggle(x,
250         y,
251         mwindow->theme->get_image_set("projector"),
252         mwindow->edl->session->cwindow_operation == CWINDOW_PROJECTOR)
253 {
254         this->mwindow = mwindow;
255         this->gui = gui;
256         set_tooltip(_("Adjust projector automation"));
257 }
258 CPanelProj::~CPanelProj()
259 {
260 }
261 int CPanelProj::handle_event()
262 {
263         gui->subwindow->set_operation(CWINDOW_PROJECTOR);
264         return 1;
265 }
266
267
268 CPanelCrop::CPanelCrop(MWindow *mwindow, CPanel *gui, int x, int y)
269  : BC_Toggle(x,
270         y,
271         mwindow->theme->get_image_set("crop"),
272         mwindow->edl->session->cwindow_operation == CWINDOW_CROP)
273 {
274         this->mwindow = mwindow;
275         this->gui = gui;
276         set_tooltip(_("Crop a layer or output"));
277 }
278
279 CPanelCrop::~CPanelCrop()
280 {
281 }
282
283 int CPanelCrop::handle_event()
284 {
285         gui->subwindow->set_operation(CWINDOW_CROP);
286         return 1;
287 }
288
289
290
291
292 CPanelEyedrop::CPanelEyedrop(MWindow *mwindow, CPanel *gui, int x, int y)
293  : BC_Toggle(x,
294         y,
295         mwindow->theme->get_image_set("eyedrop"),
296         mwindow->edl->session->cwindow_operation == CWINDOW_EYEDROP)
297 {
298         this->mwindow = mwindow;
299         this->gui = gui;
300         set_tooltip(_("Get color"));
301 }
302
303 CPanelEyedrop::~CPanelEyedrop()
304 {
305 }
306
307 int CPanelEyedrop::handle_event()
308 {
309         gui->subwindow->set_operation(CWINDOW_EYEDROP);
310         return 1;
311 }
312
313
314
315
316 CPanelToolWindow::CPanelToolWindow(MWindow *mwindow, CPanel *gui, int x, int y)
317  : BC_Toggle(x,
318         y,
319         mwindow->theme->get_image_set("tool"),
320         mwindow->edl->session->tool_window)
321 {
322         this->mwindow = mwindow;
323         this->gui = gui;
324         set_tooltip(_("Show tool info"));
325 }
326
327 CPanelToolWindow::~CPanelToolWindow()
328 {
329 }
330
331 int CPanelToolWindow::handle_event()
332 {
333         mwindow->edl->session->tool_window = get_value();
334         gui->subwindow->tool_panel->update_show_window();
335         return 1;
336 }
337
338 int CPanelToolWindow::set_shown(int shown)
339 {
340         set_value(shown);
341         mwindow->edl->session->tool_window = shown;
342         gui->subwindow->tool_panel->update_show_window();
343         return 1;
344 }
345
346
347 CPanelTitleSafe::CPanelTitleSafe(MWindow *mwindow, CPanel *gui, int x, int y)
348  : BC_Toggle(x,
349         y,
350         mwindow->theme->get_image_set("titlesafe"),
351         mwindow->edl->session->safe_regions)
352 {
353         this->mwindow = mwindow;
354         this->gui = gui;
355         set_tooltip(_("Show safe regions"));
356 }
357 CPanelTitleSafe::~CPanelTitleSafe()
358 {
359 }
360 int CPanelTitleSafe::handle_event()
361 {
362         mwindow->edl->session->safe_regions = get_value();
363         gui->subwindow->canvas->draw_refresh();
364         return 1;
365 }
366
367 CPanelZoom::CPanelZoom(MWindow *mwindow, CPanel *gui, int x, int y, int h)
368  : BC_FSlider(x, y, 1, h-30, h, -2., 2., 0, 0)
369 {
370         this->mwindow = mwindow;
371         this->gui = gui;
372         set_precision(0.001);
373         set_tooltip(_("Zoom"));
374 }
375 CPanelZoom::~CPanelZoom()
376 {
377 }
378 int CPanelZoom::handle_event()
379 {
380         FloatAuto *z_auto = 0;
381         int aidx = -1;
382         float value = get_value();
383         BC_FSlider::update(value);
384         double zoom = pow(10.,value);
385         switch( mwindow->edl->session->cwindow_operation ) {
386         case CWINDOW_ZOOM:
387                 gui->subwindow->zoom_canvas(0, zoom, 1);
388                 break;
389         case CWINDOW_CAMERA:
390                 aidx = AUTOMATION_CAMERA_Z;
391                 break;
392         case CWINDOW_PROJECTOR:
393                 aidx = AUTOMATION_PROJECTOR_Z;
394                 break;
395         }
396         if( aidx < 0 ) return 1;
397         Track *track = mwindow->cwindow->calculate_affected_track();
398         if( !track ) return 1;
399         z_auto = (FloatAuto*)mwindow->cwindow->calculate_affected_auto(
400                         track->automation->autos[aidx], 1);
401         if( !z_auto ) return 1;
402         z_auto->set_value(zoom);
403         gui->subwindow->update_tool();
404         mwindow->gui->lock_window("CPanelZoom::handle_event 1");
405         mwindow->gui->draw_overlays(1);
406         mwindow->gui->unlock_window();
407         mwindow->sync_parameters(CHANGE_PARAMS);
408         return 1;
409 }
410
411 int CPanelZoom::set_shown(int shown)
412 {
413         if( shown ) {
414                 float zoom = gui->subwindow->canvas->get_zoom();
415                 gui->subwindow->zoom_canvas(0, zoom, 1);
416                 show_window();
417         }
418         else
419                 hide_window();
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 = log(zoom) / log(10.);
438                 BC_FSlider::update(value);
439         }
440 }
441