15e61cdfa23c85be241c6b40ec91ef11d2ab529b
[goodguy/history.git] / cinelerra-5.1 / cinelerra / appearanceprefs.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 "appearanceprefs.h"
23 #include "deleteallindexes.h"
24 #include "edl.h"
25 #include "edlsession.h"
26 #include "file.h"
27 #include "filesystem.h"
28 #include "language.h"
29 #include "mwindow.h"
30 #include "preferences.h"
31 #include "preferencesthread.h"
32 #include "shbtnprefs.h"
33 #include "theme.h"
34
35
36 AppearancePrefs::AppearancePrefs(MWindow *mwindow, PreferencesWindow *pwindow)
37  : PreferencesDialog(mwindow, pwindow)
38 {
39         hms = 0;
40         hmsf = 0;
41         samples = 0;
42         frames = 0;
43         hex = 0;
44         feet = 0;
45         thumbnails = 0;
46 }
47
48 AppearancePrefs::~AppearancePrefs()
49 {
50         delete hms;
51         delete hmsf;
52         delete samples;
53         delete frames;
54         delete hex;
55         delete feet;
56         delete thumbnails;
57 }
58
59
60 void AppearancePrefs::create_objects()
61 {
62         BC_Resources *resources = BC_WindowBase::get_resources();
63         int margin = mwindow->theme->widget_border;
64         char string[BCTEXTLEN];
65         int x0 = mwindow->theme->preferencesoptions_x;
66         int y0 = mwindow->theme->preferencesoptions_y;
67         int x = x0, y = y0, x1 = x + 100;
68
69         add_subwindow(new BC_Title(x, y, _("Layout:"), LARGEFONT,
70                 resources->text_default));
71         y += 35;
72
73         ViewTheme *theme;
74         add_subwindow(new BC_Title(x, y, _("Theme:")));
75         add_subwindow(theme = new ViewTheme(x1, y, pwindow));
76         theme->create_objects();
77         y += theme->get_h() + 5;
78
79         x = x0;
80         ViewPluginIcons *plugin_icons;
81         add_subwindow(new BC_Title(x, y, _("Plugin Icons:")));
82         add_subwindow(plugin_icons = new ViewPluginIcons(x1, y, pwindow));
83         plugin_icons->create_objects();
84         y += plugin_icons->get_h() + 5;
85
86         y += 10;
87         add_subwindow(new BC_Bar(5, y,  get_w() - 10));
88         y += 15;
89
90         add_subwindow(new BC_Title(x, y, _("Time Format:"), LARGEFONT,
91                 resources->text_default));
92
93         x1 = get_w()/2;
94         add_subwindow(new BC_Title(x1, y, _("Flags:"), LARGEFONT,
95                 resources->text_default));
96
97         y += get_text_height(LARGEFONT) + 5;
98         y += 10;
99         int y1 = y;
100
101         add_subwindow(hms = new TimeFormatHMS(pwindow, this,
102                 pwindow->thread->edl->session->time_format == TIME_HMS,
103                 x, y));
104         y += 20;
105         add_subwindow(hmsf = new TimeFormatHMSF(pwindow, this,
106                 pwindow->thread->edl->session->time_format == TIME_HMSF,
107                 x, y));
108         y += 20;
109         add_subwindow(samples = new TimeFormatSamples(pwindow, this,
110                 pwindow->thread->edl->session->time_format == TIME_SAMPLES,
111                 x, y));
112         y += 20;
113         add_subwindow(hex = new TimeFormatHex(pwindow, this,
114                 pwindow->thread->edl->session->time_format == TIME_SAMPLES_HEX,
115                 x, y));
116         y += 20;
117         add_subwindow(frames = new TimeFormatFrames(pwindow, this,
118                 pwindow->thread->edl->session->time_format == TIME_FRAMES,
119                 x, y));
120         y += 20;
121         add_subwindow(feet = new TimeFormatFeet(pwindow, this,
122                 pwindow->thread->edl->session->time_format == TIME_FEET_FRAMES,
123                 x, y));
124         x += feet->get_w() + 15;
125         BC_Title *title;
126         add_subwindow(title = new BC_Title(x, y, _("Frames per foot:")));
127         x += title->get_w() + margin;
128         sprintf(string, "%0.2f", pwindow->thread->edl->session->frames_per_foot);
129         add_subwindow(new TimeFormatFeetSetting(pwindow,
130                 x, y - 5,       string));
131         x = x0;
132         y += 20;
133         add_subwindow(seconds = new TimeFormatSeconds(pwindow, this,
134                 pwindow->thread->edl->session->time_format == TIME_SECONDS,
135                 x, y));
136         x = x0;
137         y += 35;
138         add_subwindow(new BC_Bar(5, y,  get_w()/2 - 30));
139         y += 15;
140
141         add_subwindow(new BC_Title(x, y, _("Color:"), LARGEFONT,
142                 resources->text_default));
143         y += 35;
144         add_subwindow(title = new BC_Title(x, y, _("Highlighting Inversion color:")));
145         x += title->get_w() + margin;
146         char hex_color[BCSTRLEN];
147         sprintf(hex_color, "%06x", preferences->highlight_inverse);
148         add_subwindow(new HighlightInverseColor(pwindow, x, y, hex_color));
149         y += 35;
150
151         x = x0;
152         add_subwindow(title = new BC_Title(x, y, _("YUV color space:")));
153         x += title->get_w() + margin;
154         add_subwindow(yuv_color_space = new YuvColorSpace(x, y, pwindow));
155         yuv_color_space->create_objects();
156         y += yuv_color_space->get_h() + 5;
157
158         x = x0;
159         add_subwindow(title = new BC_Title(x, y, _("YUV color range:")));
160         x += title->get_w() + margin;
161         add_subwindow(yuv_color_range = new YuvColorRange(x, y, pwindow));
162         yuv_color_range->create_objects();
163         y += yuv_color_range->get_h() + 5;
164
165         UseTipWindow *tip_win = new UseTipWindow(pwindow, x1, y1);
166         add_subwindow(tip_win);
167         y1 += tip_win->get_h() + 5;
168         UseWarnIndecies *idx_win = new UseWarnIndecies(pwindow, x1, y1);
169         add_subwindow(idx_win);
170         y1 += idx_win->get_h() + 5;
171         UseWarnVersion *ver_win = new UseWarnVersion(pwindow, x1, y1);
172         add_subwindow(ver_win);
173         y1 += ver_win->get_h() + 5;
174         BD_WarnRoot *bdwr_win = new BD_WarnRoot(pwindow, x1, y1);
175         add_subwindow(bdwr_win);
176         y1 += bdwr_win->get_h() + 5;
177         PopupMenuBtnup *pop_win = new PopupMenuBtnup(pwindow, x1, y1);
178         add_subwindow(pop_win);
179         y1 += pop_win->get_h() + 5;
180         GrabFocusPolicy *grab_input_focus = new GrabFocusPolicy(pwindow, x1, y1);
181         add_subwindow(grab_input_focus);
182         y1 += grab_input_focus->get_h() + 5;
183         ActivateFocusPolicy *focus_activate = new ActivateFocusPolicy(pwindow, x1, y1);
184         add_subwindow(focus_activate);
185         y1 += focus_activate->get_h() + 5;
186         DeactivateFocusPolicy *focus_deactivate = new DeactivateFocusPolicy(pwindow, x1, y1);
187         add_subwindow(focus_deactivate);
188         y1 += focus_deactivate->get_h() + 5;
189         ForwardRenderDisplacement *displacement = new ForwardRenderDisplacement(pwindow, x1, y1);
190         add_subwindow(displacement);
191         y1 += displacement->get_h() + 5;
192         add_subwindow(thumbnails = new ViewThumbnails(x1, y1, pwindow));
193         y1 += thumbnails->get_h() + 5;
194         add_subwindow(perpetual = new PerpetualSession(x1, y1, pwindow));
195         if( y < y1 ) y = y1;
196 }
197
198 int AppearancePrefs::update(int new_value)
199 {
200         pwindow->thread->redraw_times = 1;
201         pwindow->thread->edl->session->time_format = new_value;
202         hms->update(new_value == TIME_HMS);
203         hmsf->update(new_value == TIME_HMSF);
204         samples->update(new_value == TIME_SAMPLES);
205         hex->update(new_value == TIME_SAMPLES_HEX);
206         frames->update(new_value == TIME_FRAMES);
207         feet->update(new_value == TIME_FEET_FRAMES);
208         seconds->update(new_value == TIME_SECONDS);
209         return 0;
210 }
211
212
213 TimeFormatHMS::TimeFormatHMS(PreferencesWindow *pwindow, AppearancePrefs *tfwindow, int value, int x, int y)
214  : BC_Radial(x, y, value, TIME_HMS_TEXT)
215 { this->pwindow = pwindow; this->tfwindow = tfwindow; }
216
217 int TimeFormatHMS::handle_event()
218 {
219         tfwindow->update(TIME_HMS);
220         return 1;
221 }
222
223 TimeFormatHMSF::TimeFormatHMSF(PreferencesWindow *pwindow, AppearancePrefs *tfwindow, int value, int x, int y)
224  : BC_Radial(x, y, value, TIME_HMSF_TEXT)
225 { this->pwindow = pwindow; this->tfwindow = tfwindow; }
226
227 int TimeFormatHMSF::handle_event()
228 {
229         tfwindow->update(TIME_HMSF);
230         return 1;
231 }
232
233 TimeFormatSamples::TimeFormatSamples(PreferencesWindow *pwindow, AppearancePrefs *tfwindow, int value, int x, int y)
234  : BC_Radial(x, y, value, TIME_SAMPLES_TEXT)
235 { this->pwindow = pwindow; this->tfwindow = tfwindow; }
236
237 int TimeFormatSamples::handle_event()
238 {
239         tfwindow->update(TIME_SAMPLES);
240         return 1;
241 }
242
243 TimeFormatFrames::TimeFormatFrames(PreferencesWindow *pwindow, AppearancePrefs *tfwindow, int value, int x, int y)
244  : BC_Radial(x, y, value, TIME_FRAMES_TEXT)
245 { this->pwindow = pwindow; this->tfwindow = tfwindow; }
246
247 int TimeFormatFrames::handle_event()
248 {
249         tfwindow->update(TIME_FRAMES);
250         return 1;
251 }
252
253 TimeFormatHex::TimeFormatHex(PreferencesWindow *pwindow, AppearancePrefs *tfwindow, int value, int x, int y)
254  : BC_Radial(x, y, value, TIME_SAMPLES_HEX_TEXT)
255 { this->pwindow = pwindow; this->tfwindow = tfwindow; }
256
257 int TimeFormatHex::handle_event()
258 {
259         tfwindow->update(TIME_SAMPLES_HEX);
260         return 1;
261 }
262
263 TimeFormatSeconds::TimeFormatSeconds(PreferencesWindow *pwindow, AppearancePrefs *tfwindow, int value, int x, int y)
264  : BC_Radial(x, y, value, TIME_SECONDS_TEXT)
265 {
266         this->pwindow = pwindow;
267         this->tfwindow = tfwindow;
268 }
269
270 int TimeFormatSeconds::handle_event()
271 {
272         tfwindow->update(TIME_SECONDS);
273         return 1;
274 }
275
276 TimeFormatFeet::TimeFormatFeet(PreferencesWindow *pwindow, AppearancePrefs *tfwindow, int value, int x, int y)
277  : BC_Radial(x, y, value, TIME_FEET_FRAMES_TEXT)
278 { this->pwindow = pwindow; this->tfwindow = tfwindow; }
279
280 int TimeFormatFeet::handle_event()
281 {
282         tfwindow->update(TIME_FEET_FRAMES);
283         return 1;
284 }
285
286 TimeFormatFeetSetting::TimeFormatFeetSetting(PreferencesWindow *pwindow, int x, int y, char *string)
287  : BC_TextBox(x, y, 90, 1, string)
288 { this->pwindow = pwindow; }
289
290 int TimeFormatFeetSetting::handle_event()
291 {
292         pwindow->thread->edl->session->frames_per_foot = atof(get_text());
293         if(pwindow->thread->edl->session->frames_per_foot < 1) pwindow->thread->edl->session->frames_per_foot = 1;
294         return 0;
295 }
296
297
298 ViewTheme::ViewTheme(int x, int y, PreferencesWindow *pwindow)
299  : BC_PopupMenu(x, y, 200, pwindow->thread->preferences->theme, 1)
300 {
301         this->pwindow = pwindow;
302 }
303 ViewTheme::~ViewTheme()
304 {
305 }
306
307 void ViewTheme::create_objects()
308 {
309         ArrayList<PluginServer*> themes;
310         MWindow::search_plugindb(0, 0, 0, 0, 1, themes);
311
312         for(int i = 0; i < themes.total; i++) {
313                 add_item(new ViewThemeItem(this, themes.values[i]->title));
314         }
315 }
316
317 int ViewTheme::handle_event()
318 {
319         return 1;
320 }
321
322 ViewThemeItem::ViewThemeItem(ViewTheme *popup, const char *text)
323  : BC_MenuItem(text)
324 {
325         this->popup = popup;
326 }
327
328 int ViewThemeItem::handle_event()
329 {
330         popup->set_text(get_text());
331         strcpy(popup->pwindow->thread->preferences->theme, get_text());
332         popup->handle_event();
333         return 1;
334 }
335
336
337 ViewPluginIcons::ViewPluginIcons(int x, int y, PreferencesWindow *pwindow)
338  : BC_PopupMenu(x, y, 200, pwindow->thread->preferences->plugin_icons, 1)
339 {
340         this->pwindow = pwindow;
341 }
342 ViewPluginIcons::~ViewPluginIcons()
343 {
344 }
345
346 void ViewPluginIcons::create_objects()
347 {
348         add_item(new ViewPluginIconItem(this, DEFAULT_PICON));
349         FileSystem fs;
350         const char *plugin_path = File::get_plugin_path();
351         char picon_path[BCTEXTLEN];
352         snprintf(picon_path,sizeof(picon_path)-1,"%s/picon", plugin_path);
353         if( fs.update(picon_path) ) return;
354         for( int i=0; i<fs.dir_list.total; ++i ) {
355                 char *fs_path = fs.dir_list[i]->path;
356                 if( !fs.is_dir(fs_path) ) continue;
357                 char *cp = strrchr(fs_path,'/');
358                 cp = !cp ? fs_path : cp+1;
359                 if( !strcmp(cp,DEFAULT_PICON) ) continue;
360                 add_item(new ViewPluginIconItem(this, cp));
361         }
362 }
363
364 int ViewPluginIcons::handle_event()
365 {
366         return 1;
367 }
368
369 ViewPluginIconItem::ViewPluginIconItem(ViewPluginIcons *popup, const char *text)
370  : BC_MenuItem(text)
371 {
372         this->popup = popup;
373 }
374
375 int ViewPluginIconItem::handle_event()
376 {
377         popup->set_text(get_text());
378         strcpy(popup->pwindow->thread->preferences->plugin_icons, get_text());
379         popup->handle_event();
380         return 1;
381 }
382
383
384 ViewThumbnails::ViewThumbnails(int x,
385         int y,
386         PreferencesWindow *pwindow)
387  : BC_CheckBox(x,
388         y,
389         pwindow->thread->preferences->use_thumbnails, _("Use thumbnails in resource window"))
390 {
391         this->pwindow = pwindow;
392 }
393
394 int ViewThumbnails::handle_event()
395 {
396         pwindow->thread->preferences->use_thumbnails = get_value();
397         return 1;
398 }
399
400
401
402 UseTipWindow::UseTipWindow(PreferencesWindow *pwindow, int x, int y)
403  : BC_CheckBox(x,
404         y,
405         pwindow->thread->preferences->use_tipwindow,
406         _("Show tip of the day"))
407 {
408         this->pwindow = pwindow;
409 }
410 int UseTipWindow::handle_event()
411 {
412         pwindow->thread->preferences->use_tipwindow = get_value();
413         return 1;
414 }
415
416
417 UseWarnIndecies::UseWarnIndecies(PreferencesWindow *pwindow, int x, int y)
418  : BC_CheckBox(x, y, pwindow->thread->preferences->warn_indexes,
419         _("ffmpeg probe warns rebuild indexes"))
420 {
421         this->pwindow = pwindow;
422 }
423
424 int UseWarnIndecies::handle_event()
425 {
426         pwindow->thread->preferences->warn_indexes = get_value();
427         return 1;
428 }
429
430 UseWarnVersion::UseWarnVersion(PreferencesWindow *pwindow, int x, int y)
431  : BC_CheckBox(x, y, pwindow->thread->preferences->warn_version,
432         _("EDL version warns if mismatched"))
433 {
434         this->pwindow = pwindow;
435 }
436
437 int UseWarnVersion::handle_event()
438 {
439         pwindow->thread->preferences->warn_version = get_value();
440         return 1;
441 }
442
443 BD_WarnRoot::BD_WarnRoot(PreferencesWindow *pwindow, int x, int y)
444  : BC_CheckBox(x, y, pwindow->thread->preferences->bd_warn_root,
445         _("Create Bluray warns if not root"))
446 {
447         this->pwindow = pwindow;
448 }
449
450 int BD_WarnRoot::handle_event()
451 {
452         pwindow->thread->preferences->bd_warn_root = get_value();
453         return 1;
454 }
455
456 PopupMenuBtnup::PopupMenuBtnup(PreferencesWindow *pwindow, int x, int y)
457  : BC_CheckBox(x, y, pwindow->thread->preferences->popupmenu_btnup,
458         _("Popups activate on button up"))
459 {
460         this->pwindow = pwindow;
461 }
462
463 int PopupMenuBtnup::handle_event()
464 {
465         pwindow->thread->preferences->popupmenu_btnup = get_value();
466         return 1;
467 }
468
469 GrabFocusPolicy::GrabFocusPolicy(PreferencesWindow *pwindow, int x, int y)
470  : BC_CheckBox(x, y, (pwindow->thread->preferences->grab_input_focus) != 0,
471         _("Set Input Focus when window entered"))
472 {
473         this->pwindow = pwindow;
474 }
475
476 int GrabFocusPolicy::handle_event()
477 {
478         pwindow->thread->preferences->grab_input_focus = get_value();
479         return 1;
480 }
481
482 ActivateFocusPolicy::ActivateFocusPolicy(PreferencesWindow *pwindow, int x, int y)
483  : BC_CheckBox(x, y, (pwindow->thread->preferences->textbox_focus_policy & CLICK_ACTIVATE) != 0,
484         _("Click to activate text focus"))
485 {
486         this->pwindow = pwindow;
487 }
488
489 int ActivateFocusPolicy::handle_event()
490 {
491         if( get_value() )
492                 pwindow->thread->preferences->textbox_focus_policy |= CLICK_ACTIVATE;
493         else
494                 pwindow->thread->preferences->textbox_focus_policy &= ~CLICK_ACTIVATE;
495         return 1;
496 }
497
498 DeactivateFocusPolicy::DeactivateFocusPolicy(PreferencesWindow *pwindow, int x, int y)
499  : BC_CheckBox(x, y, (pwindow->thread->preferences->textbox_focus_policy & CLICK_DEACTIVATE) != 0,
500         _("Click to deactivate text focus"))
501 {
502         this->pwindow = pwindow;
503 }
504
505 int DeactivateFocusPolicy::handle_event()
506 {
507         if( get_value() )
508                 pwindow->thread->preferences->textbox_focus_policy |= CLICK_DEACTIVATE;
509         else
510                 pwindow->thread->preferences->textbox_focus_policy &= ~CLICK_DEACTIVATE;
511         return 1;
512 }
513
514 ForwardRenderDisplacement::ForwardRenderDisplacement(PreferencesWindow *pwindow, int x, int y)
515  : BC_CheckBox(x, y, pwindow->thread->preferences->forward_render_displacement,
516         _("Always show next frame"))
517 {
518         this->pwindow = pwindow;
519 }
520
521 int ForwardRenderDisplacement::handle_event()
522 {
523         pwindow->thread->preferences->forward_render_displacement = get_value();
524         return 1;
525 }
526
527 HighlightInverseColor::HighlightInverseColor(PreferencesWindow *pwindow, int x, int y, const char *hex)
528  : BC_TextBox(x, y, 80, 1, hex)
529 {
530         this->pwindow = pwindow;
531 }
532
533 int HighlightInverseColor::handle_event()
534 {
535         int inverse_color = strtoul(get_text(),0,16);
536         if( (inverse_color &= 0xffffff) == 0 ) {
537                 inverse_color = 0xffffff;
538                 char string[BCSTRLEN];
539                 sprintf(string,"%06x", inverse_color);
540                 update(string);
541         }
542         pwindow->thread->preferences->highlight_inverse = inverse_color;
543         return 1;
544 }
545
546
547 const char *YuvColorSpace::color_space[] = {
548         N_("BT601"),
549         N_("BT709"),
550         N_("BT2020"),
551 };
552
553 YuvColorSpace::YuvColorSpace(int x, int y, PreferencesWindow *pwindow)
554  : BC_PopupMenu(x, y, 100,
555         _(color_space[pwindow->thread->preferences->yuv_color_space]), 1)
556 {
557         this->pwindow = pwindow;
558 }
559 YuvColorSpace::~YuvColorSpace()
560 {
561 }
562
563 void YuvColorSpace::create_objects()
564 {
565         for( int id=0,nid=sizeof(color_space)/sizeof(color_space[0]); id<nid; ++id )
566                 add_item(new YuvColorSpaceItem(this, _(color_space[id]), id));
567         handle_event();
568 }
569
570 int YuvColorSpace::handle_event()
571 {
572         set_text(color_space[pwindow->thread->preferences->yuv_color_space]);
573         return 1;
574 }
575
576 YuvColorSpaceItem::YuvColorSpaceItem(YuvColorSpace *popup, const char *text, int id)
577  : BC_MenuItem(text)
578 {
579         this->popup = popup;
580         this->id = id;
581 }
582
583 int YuvColorSpaceItem::handle_event()
584 {
585         popup->set_text(get_text());
586         popup->pwindow->thread->preferences->yuv_color_space = id;
587         return popup->handle_event();
588 }
589
590
591 const char *YuvColorRange::color_range[] = {
592         N_("JPEG"),
593         N_("MPEG"),
594 };
595
596 YuvColorRange::YuvColorRange(int x, int y, PreferencesWindow *pwindow)
597  : BC_PopupMenu(x, y, 100,
598         _(color_range[pwindow->thread->preferences->yuv_color_range]), 1)
599 {
600         this->pwindow = pwindow;
601 }
602 YuvColorRange::~YuvColorRange()
603 {
604 }
605
606 void YuvColorRange::create_objects()
607 {
608         for( int id=0,nid=sizeof(color_range)/sizeof(color_range[0]); id<nid; ++id )
609                 add_item(new YuvColorRangeItem(this, _(color_range[id]), id));
610         handle_event();
611 }
612
613 int YuvColorRange::handle_event()
614 {
615         set_text(color_range[pwindow->thread->preferences->yuv_color_range]);
616         return 1;
617 }
618
619 YuvColorRangeItem::YuvColorRangeItem(YuvColorRange *popup, const char *text, int id)
620  : BC_MenuItem(text)
621 {
622         this->popup = popup;
623         this->id = id;
624 }
625
626 int YuvColorRangeItem::handle_event()
627 {
628         popup->set_text(get_text());
629         popup->pwindow->thread->preferences->yuv_color_range = id;
630         return popup->handle_event();
631 }
632
633
634 PerpetualSession::PerpetualSession(int x, int y, PreferencesWindow *pwindow)
635  : BC_CheckBox(x, y,
636         pwindow->thread->preferences->perpetual_session, _("Perpetual session"))
637 {
638         this->pwindow = pwindow;
639 }
640
641 int PerpetualSession::handle_event()
642 {
643         pwindow->thread->preferences->perpetual_session = get_value();
644         return 1;
645 }
646