yuv colorspace/range + prefs, ffmpeg colorrange probe, x11 direct force colormodel...
[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(title = new BC_Title(x, y, _("Highlighting Inversion color:")));
139         x += title->get_w() + margin;
140         char hex_color[BCSTRLEN];
141         sprintf(hex_color, "%06x", preferences->highlight_inverse);
142         add_subwindow(new HighlightInverseColor(pwindow, x, y, hex_color));
143         y += 35;
144
145         x = x0;
146         add_subwindow(title = new BC_Title(x, y, _("YUV color space:")));
147         x += title->get_w() + margin;
148         add_subwindow(yuv_color_space = new YuvColorSpace(x, y, pwindow));
149         yuv_color_space->create_objects();
150         y += yuv_color_space->get_h() + 5;
151
152         x = x0;
153         add_subwindow(title = new BC_Title(x, y, _("YUV color range:")));
154         x += title->get_w() + margin;
155         add_subwindow(yuv_color_range = new YuvColorRange(x, y, pwindow));
156         yuv_color_range->create_objects();
157         y += yuv_color_range->get_h() + 5;
158
159         UseTipWindow *tip_win = new UseTipWindow(pwindow, x1, y1);
160         add_subwindow(tip_win);
161         y1 += tip_win->get_h() + 5;
162         UseWarnIndecies *idx_win = new UseWarnIndecies(pwindow, x1, y1);
163         add_subwindow(idx_win);
164         y1 += idx_win->get_h() + 5;
165         UseWarnVersion *ver_win = new UseWarnVersion(pwindow, x1, y1);
166         add_subwindow(ver_win);
167         y1 += ver_win->get_h() + 5;
168         BD_WarnRoot *bdwr_win = new BD_WarnRoot(pwindow, x1, y1);
169         add_subwindow(bdwr_win);
170         y1 += bdwr_win->get_h() + 5;
171         PopupMenuBtnup *pop_win = new PopupMenuBtnup(pwindow, x1, y1);
172         add_subwindow(pop_win);
173         y1 += pop_win->get_h() + 5;
174         GrabFocusPolicy *grab_input_focus = new GrabFocusPolicy(pwindow, x1, y1);
175         add_subwindow(grab_input_focus);
176         y1 += grab_input_focus->get_h() + 5;
177         ActivateFocusPolicy *focus_activate = new ActivateFocusPolicy(pwindow, x1, y1);
178         add_subwindow(focus_activate);
179         y1 += focus_activate->get_h() + 5;
180         DeactivateFocusPolicy *focus_deactivate = new DeactivateFocusPolicy(pwindow, x1, y1);
181         add_subwindow(focus_deactivate);
182         y1 += focus_deactivate->get_h() + 5;
183         ForwardRenderDisplacement *displacement = new ForwardRenderDisplacement(pwindow, x1, y1);
184         add_subwindow(displacement);
185         y1 += displacement->get_h() + 5;
186         add_subwindow(thumbnails = new ViewThumbnails(x1, y1, pwindow));
187         if( y < y1 ) y = y1;
188 }
189
190 int AppearancePrefs::update(int new_value)
191 {
192         pwindow->thread->redraw_times = 1;
193         pwindow->thread->edl->session->time_format = new_value;
194         hms->update(new_value == TIME_HMS);
195         hmsf->update(new_value == TIME_HMSF);
196         samples->update(new_value == TIME_SAMPLES);
197         hex->update(new_value == TIME_SAMPLES_HEX);
198         frames->update(new_value == TIME_FRAMES);
199         feet->update(new_value == TIME_FEET_FRAMES);
200         seconds->update(new_value == TIME_SECONDS);
201         return 0;
202 }
203
204
205 TimeFormatHMS::TimeFormatHMS(PreferencesWindow *pwindow, AppearancePrefs *tfwindow, int value, int x, int y)
206  : BC_Radial(x, y, value, TIME_HMS_TEXT)
207 { this->pwindow = pwindow; this->tfwindow = tfwindow; }
208
209 int TimeFormatHMS::handle_event()
210 {
211         tfwindow->update(TIME_HMS);
212         return 1;
213 }
214
215 TimeFormatHMSF::TimeFormatHMSF(PreferencesWindow *pwindow, AppearancePrefs *tfwindow, int value, int x, int y)
216  : BC_Radial(x, y, value, TIME_HMSF_TEXT)
217 { this->pwindow = pwindow; this->tfwindow = tfwindow; }
218
219 int TimeFormatHMSF::handle_event()
220 {
221         tfwindow->update(TIME_HMSF);
222         return 1;
223 }
224
225 TimeFormatSamples::TimeFormatSamples(PreferencesWindow *pwindow, AppearancePrefs *tfwindow, int value, int x, int y)
226  : BC_Radial(x, y, value, TIME_SAMPLES_TEXT)
227 { this->pwindow = pwindow; this->tfwindow = tfwindow; }
228
229 int TimeFormatSamples::handle_event()
230 {
231         tfwindow->update(TIME_SAMPLES);
232         return 1;
233 }
234
235 TimeFormatFrames::TimeFormatFrames(PreferencesWindow *pwindow, AppearancePrefs *tfwindow, int value, int x, int y)
236  : BC_Radial(x, y, value, TIME_FRAMES_TEXT)
237 { this->pwindow = pwindow; this->tfwindow = tfwindow; }
238
239 int TimeFormatFrames::handle_event()
240 {
241         tfwindow->update(TIME_FRAMES);
242         return 1;
243 }
244
245 TimeFormatHex::TimeFormatHex(PreferencesWindow *pwindow, AppearancePrefs *tfwindow, int value, int x, int y)
246  : BC_Radial(x, y, value, TIME_SAMPLES_HEX_TEXT)
247 { this->pwindow = pwindow; this->tfwindow = tfwindow; }
248
249 int TimeFormatHex::handle_event()
250 {
251         tfwindow->update(TIME_SAMPLES_HEX);
252         return 1;
253 }
254
255 TimeFormatSeconds::TimeFormatSeconds(PreferencesWindow *pwindow, AppearancePrefs *tfwindow, int value, int x, int y)
256  : BC_Radial(x, y, value, TIME_SECONDS_TEXT)
257 {
258         this->pwindow = pwindow;
259         this->tfwindow = tfwindow;
260 }
261
262 int TimeFormatSeconds::handle_event()
263 {
264         tfwindow->update(TIME_SECONDS);
265         return 1;
266 }
267
268 TimeFormatFeet::TimeFormatFeet(PreferencesWindow *pwindow, AppearancePrefs *tfwindow, int value, int x, int y)
269  : BC_Radial(x, y, value, TIME_FEET_FRAMES_TEXT)
270 { this->pwindow = pwindow; this->tfwindow = tfwindow; }
271
272 int TimeFormatFeet::handle_event()
273 {
274         tfwindow->update(TIME_FEET_FRAMES);
275         return 1;
276 }
277
278 TimeFormatFeetSetting::TimeFormatFeetSetting(PreferencesWindow *pwindow, int x, int y, char *string)
279  : BC_TextBox(x, y, 90, 1, string)
280 { this->pwindow = pwindow; }
281
282 int TimeFormatFeetSetting::handle_event()
283 {
284         pwindow->thread->edl->session->frames_per_foot = atof(get_text());
285         if(pwindow->thread->edl->session->frames_per_foot < 1) pwindow->thread->edl->session->frames_per_foot = 1;
286         return 0;
287 }
288
289
290 ViewTheme::ViewTheme(int x, int y, PreferencesWindow *pwindow)
291  : BC_PopupMenu(x, y, 200, pwindow->thread->preferences->theme, 1)
292 {
293         this->pwindow = pwindow;
294 }
295 ViewTheme::~ViewTheme()
296 {
297 }
298
299 void ViewTheme::create_objects()
300 {
301         ArrayList<PluginServer*> themes;
302         MWindow::search_plugindb(0, 0, 0, 0, 1, themes);
303
304         for(int i = 0; i < themes.total; i++) {
305                 add_item(new ViewThemeItem(this, themes.values[i]->title));
306         }
307 }
308
309 int ViewTheme::handle_event()
310 {
311         return 1;
312 }
313
314 ViewThemeItem::ViewThemeItem(ViewTheme *popup, const char *text)
315  : BC_MenuItem(text)
316 {
317         this->popup = popup;
318 }
319
320 int ViewThemeItem::handle_event()
321 {
322         popup->set_text(get_text());
323         strcpy(popup->pwindow->thread->preferences->theme, get_text());
324         popup->handle_event();
325         return 1;
326 }
327
328
329 ViewPluginIcons::ViewPluginIcons(int x, int y, PreferencesWindow *pwindow)
330  : BC_PopupMenu(x, y, 200, pwindow->thread->preferences->plugin_icons, 1)
331 {
332         this->pwindow = pwindow;
333 }
334 ViewPluginIcons::~ViewPluginIcons()
335 {
336 }
337
338 void ViewPluginIcons::create_objects()
339 {
340         add_item(new ViewPluginIconItem(this, DEFAULT_PICON));
341         FileSystem fs;
342         const char *plugin_path = File::get_plugin_path();
343         char picon_path[BCTEXTLEN];
344         snprintf(picon_path,sizeof(picon_path)-1,"%s/picon", plugin_path);
345         if( fs.update(picon_path) ) return;
346         for( int i=0; i<fs.dir_list.total; ++i ) {
347                 char *fs_path = fs.dir_list[i]->path;
348                 if( !fs.is_dir(fs_path) ) continue;
349                 char *cp = strrchr(fs_path,'/');
350                 cp = !cp ? fs_path : cp+1;
351                 if( !strcmp(cp,DEFAULT_PICON) ) continue;
352                 add_item(new ViewPluginIconItem(this, cp));
353         }
354 }
355
356 int ViewPluginIcons::handle_event()
357 {
358         return 1;
359 }
360
361 ViewPluginIconItem::ViewPluginIconItem(ViewPluginIcons *popup, const char *text)
362  : BC_MenuItem(text)
363 {
364         this->popup = popup;
365 }
366
367 int ViewPluginIconItem::handle_event()
368 {
369         popup->set_text(get_text());
370         strcpy(popup->pwindow->thread->preferences->plugin_icons, get_text());
371         popup->handle_event();
372         return 1;
373 }
374
375
376 ViewThumbnails::ViewThumbnails(int x,
377         int y,
378         PreferencesWindow *pwindow)
379  : BC_CheckBox(x,
380         y,
381         pwindow->thread->preferences->use_thumbnails, _("Use thumbnails in resource window"))
382 {
383         this->pwindow = pwindow;
384 }
385
386 int ViewThumbnails::handle_event()
387 {
388         pwindow->thread->preferences->use_thumbnails = get_value();
389         return 1;
390 }
391
392
393
394 UseTipWindow::UseTipWindow(PreferencesWindow *pwindow, int x, int y)
395  : BC_CheckBox(x,
396         y,
397         pwindow->thread->preferences->use_tipwindow,
398         _("Show tip of the day"))
399 {
400         this->pwindow = pwindow;
401 }
402 int UseTipWindow::handle_event()
403 {
404         pwindow->thread->preferences->use_tipwindow = get_value();
405         return 1;
406 }
407
408
409 UseWarnIndecies::UseWarnIndecies(PreferencesWindow *pwindow, int x, int y)
410  : BC_CheckBox(x, y, pwindow->thread->preferences->warn_indexes,
411         _("ffmpeg probe warns rebuild indexes"))
412 {
413         this->pwindow = pwindow;
414 }
415
416 int UseWarnIndecies::handle_event()
417 {
418         pwindow->thread->preferences->warn_indexes = get_value();
419         return 1;
420 }
421
422 UseWarnVersion::UseWarnVersion(PreferencesWindow *pwindow, int x, int y)
423  : BC_CheckBox(x, y, pwindow->thread->preferences->warn_version,
424         _("EDL version warns if mismatched"))
425 {
426         this->pwindow = pwindow;
427 }
428
429 int UseWarnVersion::handle_event()
430 {
431         pwindow->thread->preferences->warn_version = get_value();
432         return 1;
433 }
434
435 BD_WarnRoot::BD_WarnRoot(PreferencesWindow *pwindow, int x, int y)
436  : BC_CheckBox(x, y, pwindow->thread->preferences->bd_warn_root,
437         _("Create Bluray warns if not root"))
438 {
439         this->pwindow = pwindow;
440 }
441
442 int BD_WarnRoot::handle_event()
443 {
444         pwindow->thread->preferences->bd_warn_root = get_value();
445         return 1;
446 }
447
448 PopupMenuBtnup::PopupMenuBtnup(PreferencesWindow *pwindow, int x, int y)
449  : BC_CheckBox(x, y, pwindow->thread->preferences->popupmenu_btnup,
450         _("Popups activate on button up"))
451 {
452         this->pwindow = pwindow;
453 }
454
455 int PopupMenuBtnup::handle_event()
456 {
457         pwindow->thread->preferences->popupmenu_btnup = get_value();
458         return 1;
459 }
460
461 GrabFocusPolicy::GrabFocusPolicy(PreferencesWindow *pwindow, int x, int y)
462  : BC_CheckBox(x, y, (pwindow->thread->preferences->grab_input_focus) != 0,
463         _("Set Input Focus when window entered"))
464 {
465         this->pwindow = pwindow;
466 }
467
468 int GrabFocusPolicy::handle_event()
469 {
470         pwindow->thread->preferences->grab_input_focus = get_value();
471         return 1;
472 }
473
474 ActivateFocusPolicy::ActivateFocusPolicy(PreferencesWindow *pwindow, int x, int y)
475  : BC_CheckBox(x, y, (pwindow->thread->preferences->textbox_focus_policy & CLICK_ACTIVATE) != 0,
476         _("Click to activate text focus"))
477 {
478         this->pwindow = pwindow;
479 }
480
481 int ActivateFocusPolicy::handle_event()
482 {
483         if( get_value() )
484                 pwindow->thread->preferences->textbox_focus_policy |= CLICK_ACTIVATE;
485         else
486                 pwindow->thread->preferences->textbox_focus_policy &= ~CLICK_ACTIVATE;
487         return 1;
488 }
489
490 DeactivateFocusPolicy::DeactivateFocusPolicy(PreferencesWindow *pwindow, int x, int y)
491  : BC_CheckBox(x, y, (pwindow->thread->preferences->textbox_focus_policy & CLICK_DEACTIVATE) != 0,
492         _("Click to deactivate text focus"))
493 {
494         this->pwindow = pwindow;
495 }
496
497 int DeactivateFocusPolicy::handle_event()
498 {
499         if( get_value() )
500                 pwindow->thread->preferences->textbox_focus_policy |= CLICK_DEACTIVATE;
501         else
502                 pwindow->thread->preferences->textbox_focus_policy &= ~CLICK_DEACTIVATE;
503         return 1;
504 }
505
506 ForwardRenderDisplacement::ForwardRenderDisplacement(PreferencesWindow *pwindow, int x, int y)
507  : BC_CheckBox(x, y, pwindow->thread->preferences->forward_render_displacement,
508         _("Always show next frame"))
509 {
510         this->pwindow = pwindow;
511 }
512
513 int ForwardRenderDisplacement::handle_event()
514 {
515         pwindow->thread->preferences->forward_render_displacement = get_value();
516         return 1;
517 }
518
519 HighlightInverseColor::HighlightInverseColor(PreferencesWindow *pwindow, int x, int y, const char *hex)
520  : BC_TextBox(x, y, 80, 1, hex)
521 {
522         this->pwindow = pwindow;
523 }
524
525 int HighlightInverseColor::handle_event()
526 {
527         int inverse_color = strtoul(get_text(),0,16);
528         if( (inverse_color &= 0xffffff) == 0 ) {
529                 inverse_color = 0xffffff;
530                 char string[BCSTRLEN];
531                 sprintf(string,"%06x", inverse_color);
532                 update(string);
533         }
534         pwindow->thread->preferences->highlight_inverse = inverse_color;
535         return 1;
536 }
537
538
539 const char *YuvColorSpace::color_space[] = {
540         N_("BT601"),
541         N_("BT709"),
542 };
543
544 YuvColorSpace::YuvColorSpace(int x, int y, PreferencesWindow *pwindow)
545  : BC_PopupMenu(x, y, 100,
546         _(color_space[pwindow->thread->preferences->yuv_color_space]), 1)
547 {
548         this->pwindow = pwindow;
549 }
550 YuvColorSpace::~YuvColorSpace()
551 {
552 }
553
554 void YuvColorSpace::create_objects()
555 {
556         for( int id=0,nid=sizeof(color_space)/sizeof(color_space[0]); id<nid; ++id )
557                 add_item(new YuvColorSpaceItem(this, _(color_space[id]), id));
558         handle_event();
559 }
560
561 int YuvColorSpace::handle_event()
562 {
563         set_text(color_space[pwindow->thread->preferences->yuv_color_space]);
564         return 1;
565 }
566
567 YuvColorSpaceItem::YuvColorSpaceItem(YuvColorSpace *popup, const char *text, int id)
568  : BC_MenuItem(text)
569 {
570         this->popup = popup;
571         this->id = id;
572 }
573
574 int YuvColorSpaceItem::handle_event()
575 {
576         popup->set_text(get_text());
577         popup->pwindow->thread->preferences->yuv_color_space = id;
578         return popup->handle_event();
579 }
580
581
582 const char *YuvColorRange::color_range[] = {
583         N_("JPEG"),
584         N_("MPEG"),
585 };
586
587 YuvColorRange::YuvColorRange(int x, int y, PreferencesWindow *pwindow)
588  : BC_PopupMenu(x, y, 100,
589         _(color_range[pwindow->thread->preferences->yuv_color_range]), 1)
590 {
591         this->pwindow = pwindow;
592 }
593 YuvColorRange::~YuvColorRange()
594 {
595 }
596
597 void YuvColorRange::create_objects()
598 {
599         for( int id=0,nid=sizeof(color_range)/sizeof(color_range[0]); id<nid; ++id )
600                 add_item(new YuvColorRangeItem(this, _(color_range[id]), id));
601         handle_event();
602 }
603
604 int YuvColorRange::handle_event()
605 {
606         set_text(color_range[pwindow->thread->preferences->yuv_color_range]);
607         return 1;
608 }
609
610 YuvColorRangeItem::YuvColorRangeItem(YuvColorRange *popup, const char *text, int id)
611  : BC_MenuItem(text)
612 {
613         this->popup = popup;
614         this->id = id;
615 }
616
617 int YuvColorRangeItem::handle_event()
618 {
619         popup->set_text(get_text());
620         popup->pwindow->thread->preferences->yuv_color_range = id;
621         return popup->handle_event();
622 }
623