alt transport keys, snap editing, grab focus, inv hilight clr, subtitle fix
[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 #define MOVE_ALL_EDITS_TITLE N_("Drag all following edits")
37 #define MOVE_ONE_EDIT_TITLE N_("Drag only one edit")
38 #define MOVE_NO_EDITS_TITLE N_("Drag source only")
39 #define MOVE_EDITS_DISABLED_TITLE N_("No effect")
40
41
42 AppearancePrefs::AppearancePrefs(MWindow *mwindow, PreferencesWindow *pwindow)
43  : PreferencesDialog(mwindow, pwindow)
44 {
45         hms = 0;
46         hmsf = 0;
47         samples = 0;
48         frames = 0;
49         hex = 0;
50         feet = 0;
51         thumbnails = 0;
52 }
53
54 AppearancePrefs::~AppearancePrefs()
55 {
56         delete hms;
57         delete hmsf;
58         delete samples;
59         delete frames;
60         delete hex;
61         delete feet;
62         delete thumbnails;
63 }
64
65
66 void AppearancePrefs::create_objects()
67 {
68         BC_Resources *resources = BC_WindowBase::get_resources();
69         int margin = mwindow->theme->widget_border;
70         char string[BCTEXTLEN];
71         int x0 = mwindow->theme->preferencesoptions_x;
72         int y0 = mwindow->theme->preferencesoptions_y;
73         int x = x0, y = y0, x1 = x + 100;
74
75         add_subwindow(new BC_Title(x, y, _("Layout:"), LARGEFONT,
76                 resources->text_default));
77         y += 35;
78
79         ViewTheme *theme;
80         add_subwindow(new BC_Title(x, y, _("Theme:")));
81         add_subwindow(theme = new ViewTheme(x1, y, pwindow));
82         theme->create_objects();
83         y += theme->get_h() + 5;
84
85         x = x0;
86         ViewPluginIcons *plugin_icons;
87         add_subwindow(new BC_Title(x, y, _("Plugin Icons:")));
88         add_subwindow(plugin_icons = new ViewPluginIcons(x1, y, pwindow));
89         plugin_icons->create_objects();
90         y += plugin_icons->get_h() + 5;
91
92         y += 10;
93         add_subwindow(new BC_Bar(5, y,  get_w() - 10));
94         y += 15;
95
96         add_subwindow(new BC_Title(x, y, _("Time Format:"), LARGEFONT,
97                 resources->text_default));
98
99         x1 = get_w()/2;
100         add_subwindow(new BC_Title(x1, y, _("Flags:"), LARGEFONT,
101                 resources->text_default));
102
103         y += get_text_height(LARGEFONT) + 5;
104         y += 10;
105         int y1 = y;
106
107         add_subwindow(hms = new TimeFormatHMS(pwindow, this,
108                 pwindow->thread->edl->session->time_format == TIME_HMS,
109                 x, y));
110         y += 20;
111         add_subwindow(hmsf = new TimeFormatHMSF(pwindow, this,
112                 pwindow->thread->edl->session->time_format == TIME_HMSF,
113                 x, y));
114         y += 20;
115         add_subwindow(samples = new TimeFormatSamples(pwindow, this,
116                 pwindow->thread->edl->session->time_format == TIME_SAMPLES,
117                 x, y));
118         y += 20;
119         add_subwindow(hex = new TimeFormatHex(pwindow, this,
120                 pwindow->thread->edl->session->time_format == TIME_SAMPLES_HEX,
121                 x, y));
122         y += 20;
123         add_subwindow(frames = new TimeFormatFrames(pwindow, this,
124                 pwindow->thread->edl->session->time_format == TIME_FRAMES,
125                 x, y));
126         y += 20;
127         add_subwindow(feet = new TimeFormatFeet(pwindow, this,
128                 pwindow->thread->edl->session->time_format == TIME_FEET_FRAMES,
129                 x, y));
130         x += feet->get_w() + 15;
131         BC_Title *title;
132         add_subwindow(title = new BC_Title(x, y, _("Frames per foot:")));
133         x += title->get_w() + margin;
134         sprintf(string, "%0.2f", pwindow->thread->edl->session->frames_per_foot);
135         add_subwindow(new TimeFormatFeetSetting(pwindow,
136                 x, y - 5,       string));
137         x = x0;
138         y += 20;
139         add_subwindow(seconds = new TimeFormatSeconds(pwindow, this,
140                 pwindow->thread->edl->session->time_format == TIME_SECONDS,
141                 x, y));
142         x = x0;
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         UseTipWindow *tip_win = new UseTipWindow(pwindow, x1, y1);
152         add_subwindow(tip_win);
153         y1 += tip_win->get_h() + 5;
154         UseWarnIndecies *idx_win = new UseWarnIndecies(pwindow, x1, y1);
155         add_subwindow(idx_win);
156         y1 += idx_win->get_h() + 5;
157         UseWarnVersion *ver_win = new UseWarnVersion(pwindow, x1, y1);
158         add_subwindow(ver_win);
159         y1 += ver_win->get_h() + 5;
160         BD_WarnRoot *bdwr_win = new BD_WarnRoot(pwindow, x1, y1);
161         add_subwindow(bdwr_win);
162         y1 += bdwr_win->get_h() + 5;
163         PopupMenuBtnup *pop_win = new PopupMenuBtnup(pwindow, x1, y1);
164         add_subwindow(pop_win);
165         y1 += pop_win->get_h() + 5;
166         GrabFocusPolicy *grab_input_focus = new GrabFocusPolicy(pwindow, x1, y1);
167         add_subwindow(grab_input_focus);
168         y1 += grab_input_focus->get_h() + 5;
169         ActivateFocusPolicy *focus_activate = new ActivateFocusPolicy(pwindow, x1, y1);
170         add_subwindow(focus_activate);
171         y1 += focus_activate->get_h() + 5;
172         DeactivateFocusPolicy *focus_deactivate = new DeactivateFocusPolicy(pwindow, x1, y1);
173         add_subwindow(focus_deactivate);
174         y1 += focus_deactivate->get_h() + 5;
175         ForwardRenderDisplacement *displacement = new ForwardRenderDisplacement(pwindow, x1, y1);
176         add_subwindow(displacement);
177         y1 += displacement->get_h() + 5;
178         add_subwindow(thumbnails = new ViewThumbnails(x1, y1, pwindow));
179         if( y < y1 ) y = y1;
180 }
181
182 int AppearancePrefs::update(int new_value)
183 {
184         pwindow->thread->redraw_times = 1;
185         pwindow->thread->edl->session->time_format = new_value;
186         hms->update(new_value == TIME_HMS);
187         hmsf->update(new_value == TIME_HMSF);
188         samples->update(new_value == TIME_SAMPLES);
189         hex->update(new_value == TIME_SAMPLES_HEX);
190         frames->update(new_value == TIME_FRAMES);
191         feet->update(new_value == TIME_FEET_FRAMES);
192         seconds->update(new_value == TIME_SECONDS);
193         return 0;
194 }
195
196
197 TimeFormatHMS::TimeFormatHMS(PreferencesWindow *pwindow, AppearancePrefs *tfwindow, int value, int x, int y)
198  : BC_Radial(x, y, value, TIME_HMS_TEXT)
199 { this->pwindow = pwindow; this->tfwindow = tfwindow; }
200
201 int TimeFormatHMS::handle_event()
202 {
203         tfwindow->update(TIME_HMS);
204         return 1;
205 }
206
207 TimeFormatHMSF::TimeFormatHMSF(PreferencesWindow *pwindow, AppearancePrefs *tfwindow, int value, int x, int y)
208  : BC_Radial(x, y, value, TIME_HMSF_TEXT)
209 { this->pwindow = pwindow; this->tfwindow = tfwindow; }
210
211 int TimeFormatHMSF::handle_event()
212 {
213         tfwindow->update(TIME_HMSF);
214         return 1;
215 }
216
217 TimeFormatSamples::TimeFormatSamples(PreferencesWindow *pwindow, AppearancePrefs *tfwindow, int value, int x, int y)
218  : BC_Radial(x, y, value, TIME_SAMPLES_TEXT)
219 { this->pwindow = pwindow; this->tfwindow = tfwindow; }
220
221 int TimeFormatSamples::handle_event()
222 {
223         tfwindow->update(TIME_SAMPLES);
224         return 1;
225 }
226
227 TimeFormatFrames::TimeFormatFrames(PreferencesWindow *pwindow, AppearancePrefs *tfwindow, int value, int x, int y)
228  : BC_Radial(x, y, value, TIME_FRAMES_TEXT)
229 { this->pwindow = pwindow; this->tfwindow = tfwindow; }
230
231 int TimeFormatFrames::handle_event()
232 {
233         tfwindow->update(TIME_FRAMES);
234         return 1;
235 }
236
237 TimeFormatHex::TimeFormatHex(PreferencesWindow *pwindow, AppearancePrefs *tfwindow, int value, int x, int y)
238  : BC_Radial(x, y, value, TIME_SAMPLES_HEX_TEXT)
239 { this->pwindow = pwindow; this->tfwindow = tfwindow; }
240
241 int TimeFormatHex::handle_event()
242 {
243         tfwindow->update(TIME_SAMPLES_HEX);
244         return 1;
245 }
246
247 TimeFormatSeconds::TimeFormatSeconds(PreferencesWindow *pwindow, AppearancePrefs *tfwindow, int value, int x, int y)
248  : BC_Radial(x, y, value, TIME_SECONDS_TEXT)
249 {
250         this->pwindow = pwindow;
251         this->tfwindow = tfwindow;
252 }
253
254 int TimeFormatSeconds::handle_event()
255 {
256         tfwindow->update(TIME_SECONDS);
257         return 1;
258 }
259
260 TimeFormatFeet::TimeFormatFeet(PreferencesWindow *pwindow, AppearancePrefs *tfwindow, int value, int x, int y)
261  : BC_Radial(x, y, value, TIME_FEET_FRAMES_TEXT)
262 { this->pwindow = pwindow; this->tfwindow = tfwindow; }
263
264 int TimeFormatFeet::handle_event()
265 {
266         tfwindow->update(TIME_FEET_FRAMES);
267         return 1;
268 }
269
270 TimeFormatFeetSetting::TimeFormatFeetSetting(PreferencesWindow *pwindow, int x, int y, char *string)
271  : BC_TextBox(x, y, 90, 1, string)
272 { this->pwindow = pwindow; }
273
274 int TimeFormatFeetSetting::handle_event()
275 {
276         pwindow->thread->edl->session->frames_per_foot = atof(get_text());
277         if(pwindow->thread->edl->session->frames_per_foot < 1) pwindow->thread->edl->session->frames_per_foot = 1;
278         return 0;
279 }
280
281
282 ViewTheme::ViewTheme(int x, int y, PreferencesWindow *pwindow)
283  : BC_PopupMenu(x, y, 200, pwindow->thread->preferences->theme, 1)
284 {
285         this->pwindow = pwindow;
286 }
287 ViewTheme::~ViewTheme()
288 {
289 }
290
291 void ViewTheme::create_objects()
292 {
293         ArrayList<PluginServer*> themes;
294         MWindow::search_plugindb(0, 0, 0, 0, 1, themes);
295
296         for(int i = 0; i < themes.total; i++) {
297                 add_item(new ViewThemeItem(this, themes.values[i]->title));
298         }
299 }
300
301 int ViewTheme::handle_event()
302 {
303         return 1;
304 }
305
306 ViewThemeItem::ViewThemeItem(ViewTheme *popup, const char *text)
307  : BC_MenuItem(text)
308 {
309         this->popup = popup;
310 }
311
312 int ViewThemeItem::handle_event()
313 {
314         popup->set_text(get_text());
315         strcpy(popup->pwindow->thread->preferences->theme, get_text());
316         popup->handle_event();
317         return 1;
318 }
319
320
321 ViewPluginIcons::ViewPluginIcons(int x, int y, PreferencesWindow *pwindow)
322  : BC_PopupMenu(x, y, 200, pwindow->thread->preferences->plugin_icons, 1)
323 {
324         this->pwindow = pwindow;
325 }
326 ViewPluginIcons::~ViewPluginIcons()
327 {
328 }
329
330 void ViewPluginIcons::create_objects()
331 {
332         add_item(new ViewPluginIconItem(this, DEFAULT_PICON));
333         FileSystem fs;
334         const char *plugin_path = File::get_plugin_path();
335         if( fs.update(plugin_path) ) return;
336         for( int i=0; i<fs.dir_list.total; ++i ) {
337                 char *fs_path = fs.dir_list[i]->path;
338                 if( !fs.is_dir(fs_path) ) continue;
339                 char *cp = strrchr(fs_path,'/');
340                 cp = !cp ? fs_path : cp+1;
341                 if( strncmp("picon_", cp, 6) ) continue;
342                 if( !strcmp(cp += 6,DEFAULT_PICON) ) continue;
343                 add_item(new ViewPluginIconItem(this, cp));
344         }
345 }
346
347 int ViewPluginIcons::handle_event()
348 {
349         return 1;
350 }
351
352 ViewPluginIconItem::ViewPluginIconItem(ViewPluginIcons *popup, const char *text)
353  : BC_MenuItem(text)
354 {
355         this->popup = popup;
356 }
357
358 int ViewPluginIconItem::handle_event()
359 {
360         popup->set_text(get_text());
361         strcpy(popup->pwindow->thread->preferences->plugin_icons, get_text());
362         popup->handle_event();
363         return 1;
364 }
365
366
367 ViewThumbnails::ViewThumbnails(int x,
368         int y,
369         PreferencesWindow *pwindow)
370  : BC_CheckBox(x,
371         y,
372         pwindow->thread->preferences->use_thumbnails, _("Use thumbnails in resource window"))
373 {
374         this->pwindow = pwindow;
375 }
376
377 int ViewThumbnails::handle_event()
378 {
379         pwindow->thread->preferences->use_thumbnails = get_value();
380         return 1;
381 }
382
383
384
385 UseTipWindow::UseTipWindow(PreferencesWindow *pwindow, int x, int y)
386  : BC_CheckBox(x,
387         y,
388         pwindow->thread->preferences->use_tipwindow,
389         _("Show tip of the day"))
390 {
391         this->pwindow = pwindow;
392 }
393 int UseTipWindow::handle_event()
394 {
395         pwindow->thread->preferences->use_tipwindow = get_value();
396         return 1;
397 }
398
399
400 UseWarnIndecies::UseWarnIndecies(PreferencesWindow *pwindow, int x, int y)
401  : BC_CheckBox(x, y, pwindow->thread->preferences->warn_indexes,
402         _("ffmpeg probe warns rebuild indexes"))
403 {
404         this->pwindow = pwindow;
405 }
406
407 int UseWarnIndecies::handle_event()
408 {
409         pwindow->thread->preferences->warn_indexes = get_value();
410         return 1;
411 }
412
413 UseWarnVersion::UseWarnVersion(PreferencesWindow *pwindow, int x, int y)
414  : BC_CheckBox(x, y, pwindow->thread->preferences->warn_version,
415         _("EDL version warns if mismatched"))
416 {
417         this->pwindow = pwindow;
418 }
419
420 int UseWarnVersion::handle_event()
421 {
422         pwindow->thread->preferences->warn_version = get_value();
423         return 1;
424 }
425
426 BD_WarnRoot::BD_WarnRoot(PreferencesWindow *pwindow, int x, int y)
427  : BC_CheckBox(x, y, pwindow->thread->preferences->bd_warn_root,
428         _("Create Bluray warns if not root"))
429 {
430         this->pwindow = pwindow;
431 }
432
433 int BD_WarnRoot::handle_event()
434 {
435         pwindow->thread->preferences->bd_warn_root = get_value();
436         return 1;
437 }
438
439 PopupMenuBtnup::PopupMenuBtnup(PreferencesWindow *pwindow, int x, int y)
440  : BC_CheckBox(x, y, pwindow->thread->preferences->popupmenu_btnup,
441         _("Popups activate on button up"))
442 {
443         this->pwindow = pwindow;
444 }
445
446 int PopupMenuBtnup::handle_event()
447 {
448         pwindow->thread->preferences->popupmenu_btnup = get_value();
449         return 1;
450 }
451
452 GrabFocusPolicy::GrabFocusPolicy(PreferencesWindow *pwindow, int x, int y)
453  : BC_CheckBox(x, y, (pwindow->thread->preferences->grab_input_focus) != 0,
454         _("Set Input Focus when window entered"))
455 {
456         this->pwindow = pwindow;
457 }
458
459 int GrabFocusPolicy::handle_event()
460 {
461         pwindow->thread->preferences->grab_input_focus = get_value();
462         return 1;
463 }
464
465 ActivateFocusPolicy::ActivateFocusPolicy(PreferencesWindow *pwindow, int x, int y)
466  : BC_CheckBox(x, y, (pwindow->thread->preferences->textbox_focus_policy & CLICK_ACTIVATE) != 0,
467         _("Click to activate text focus"))
468 {
469         this->pwindow = pwindow;
470 }
471
472 int ActivateFocusPolicy::handle_event()
473 {
474         if( get_value() )
475                 pwindow->thread->preferences->textbox_focus_policy |= CLICK_ACTIVATE;
476         else
477                 pwindow->thread->preferences->textbox_focus_policy &= ~CLICK_ACTIVATE;
478         return 1;
479 }
480
481 DeactivateFocusPolicy::DeactivateFocusPolicy(PreferencesWindow *pwindow, int x, int y)
482  : BC_CheckBox(x, y, (pwindow->thread->preferences->textbox_focus_policy & CLICK_DEACTIVATE) != 0,
483         _("Click to deactivate text focus"))
484 {
485         this->pwindow = pwindow;
486 }
487
488 int DeactivateFocusPolicy::handle_event()
489 {
490         if( get_value() )
491                 pwindow->thread->preferences->textbox_focus_policy |= CLICK_DEACTIVATE;
492         else
493                 pwindow->thread->preferences->textbox_focus_policy &= ~CLICK_DEACTIVATE;
494         return 1;
495 }
496
497 ForwardRenderDisplacement::ForwardRenderDisplacement(PreferencesWindow *pwindow, int x, int y)
498  : BC_CheckBox(x, y, pwindow->thread->preferences->forward_render_displacement,
499         _("Always show next frame"))
500 {
501         this->pwindow = pwindow;
502 }
503
504 int ForwardRenderDisplacement::handle_event()
505 {
506         pwindow->thread->preferences->forward_render_displacement = get_value();
507         return 1;
508 }
509
510 HighlightInverseColor::HighlightInverseColor(PreferencesWindow *pwindow, int x, int y, const char *hex)
511  : BC_TextBox(x, y, 80, 1, hex)
512 {
513         this->pwindow = pwindow;
514 }
515
516 int HighlightInverseColor::handle_event()
517 {
518         int inverse_color = strtoul(get_text(),0,16);
519         inverse_color &= 0xffffff;
520         pwindow->thread->preferences->highlight_inverse = inverse_color;
521         return 1;
522 }
523