Documentation for target_scanline.h
[synfig.git] / synfig-studio / src / gui / dialogs / dialog_setup.cpp
1 /* === S Y N F I G ========================================================= */
2 /*!     \file dialog_setup.cpp
3 **      \brief Template File
4 **
5 **      $Id$
6 **
7 **      \legal
8 **      Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
9 **      Copyright (c) 2007, 2008 Chris Moore
10 **      Copyright (c) 2008, 2009 Carlos López
11 **
12 **      This package is free software; you can redistribute it and/or
13 **      modify it under the terms of the GNU General Public License as
14 **      published by the Free Software Foundation; either version 2 of
15 **      the License, or (at your option) any later version.
16 **
17 **      This package is distributed in the hope that it will be useful,
18 **      but WITHOUT ANY WARRANTY; without even the implied warranty of
19 **      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 **      General Public License for more details.
21 **      \endlegal
22 */
23 /* ========================================================================= */
24
25 /* === H E A D E R S ======================================================= */
26
27 #ifdef USING_PCH
28 #       include "pch.h"
29 #else
30 #ifdef HAVE_CONFIG_H
31 #       include <config.h>
32 #endif
33
34 #include "dialogs/dialog_setup.h"
35 #include "app.h"
36 #include <gtkmm/scale.h>
37 #include <gtkmm/table.h>
38 #include <gtkmm/frame.h>
39 #include <gtkmm/notebook.h>
40 #include "widgets/widget_enum.h"
41 #include "autorecover.h"
42
43 #include <ETL/stringf>
44 #include <ETL/misc>
45 #include "general.h"
46
47 #endif
48
49 /* === U S I N G =========================================================== */
50
51 using namespace std;
52 using namespace etl;
53 using namespace synfig;
54 using namespace studio;
55
56 /* === M A C R O S ========================================================= */
57
58 /* === G L O B A L S ======================================================= */
59
60 /* === P R O C E D U R E S ================================================= */
61
62 /* === M E T H O D S ======================================================= */
63
64 static void
65 attach_label(Gtk::Table *table, String str, guint col, guint xpadding, guint ypadding)
66 {
67         Gtk::Label* label(manage(new Gtk::Label((str + ":").c_str())));
68         label->set_alignment(Gtk::ALIGN_RIGHT, Gtk::ALIGN_CENTER);
69         table->attach(*label, 0, 1, col, col+1, Gtk::SHRINK|Gtk::FILL, Gtk::SHRINK|Gtk::FILL, xpadding, ypadding);
70 }
71
72 Dialog_Setup::Dialog_Setup():
73         Dialog(_("Synfig Studio Setup"),false,true),
74         adj_gamma_r(2.2,0.1,3.0,0.025,0.025,0.025),
75         adj_gamma_g(2.2,0.1,3.0,0.025,0.025,0.025),
76         adj_gamma_b(2.2,0.1,3.0,0.025,0.025,0.025),
77         adj_recent_files(15,1,50,1,1,0),
78         adj_undo_depth(100,10,5000,1,1,1),
79         toggle_use_colorspace_gamma(_("Visually Linear Color Selection")),
80 #ifdef SINGLE_THREADED
81         toggle_single_threaded(_("Use Only a Single Thread")),
82 #endif
83         toggle_restrict_radius_ducks(_("Restrict Real-Valued Ducks to Top Right Quadrant")),
84         toggle_resize_imported_images(_("Scale New Imported Images to Fit Canvas")),
85         adj_pref_x_size(480,1,10000,1,10,0),
86         adj_pref_y_size(270,1,10000,1,10,0),
87         adj_pref_fps(24.0,1.0,100,0.1,1,0)
88
89         {
90         // Setup the buttons
91
92         Gtk::Button *ok_button(manage(new class Gtk::Button(Gtk::StockID("gtk-ok"))));
93         ok_button->show();
94         add_action_widget(*ok_button,2);
95         ok_button->signal_clicked().connect(sigc::mem_fun(*this, &Dialog_Setup::on_ok_pressed));
96
97         Gtk::Button *apply_button(manage(new class Gtk::Button(Gtk::StockID("gtk-apply"))));
98         apply_button->show();
99         add_action_widget(*apply_button,1);
100         apply_button->signal_clicked().connect(sigc::mem_fun(*this, &Dialog_Setup::on_apply_pressed));
101
102         Gtk::Button *cancel_button(manage(new class Gtk::Button(Gtk::StockID("gtk-close"))));
103         cancel_button->show();
104         add_action_widget(*cancel_button,0);
105         cancel_button->signal_clicked().connect(sigc::mem_fun(*this, &Dialog_Setup::hide));
106
107
108         // Notebook
109         Gtk::Notebook *notebook=manage(new class Gtk::Notebook());
110         get_vbox()->pack_start(*notebook);
111
112
113         // Gamma
114         Gtk::Table *gamma_table=manage(new Gtk::Table(2,2,false));
115         notebook->append_page(*gamma_table,_("Gamma"));
116
117         gamma_table->attach(gamma_pattern, 0, 2, 0, 1, Gtk::EXPAND, Gtk::SHRINK|Gtk::FILL, 0, 0);
118
119         Gtk::HScale* scale_gamma_r(manage(new Gtk::HScale(adj_gamma_r)));
120         gamma_table->attach(*manage(new Gtk::Label(_("Red"))), 0, 1, 1, 2, Gtk::SHRINK|Gtk::FILL, Gtk::SHRINK|Gtk::FILL, 0, 0);
121         gamma_table->attach(*scale_gamma_r, 1, 2, 1, 2, Gtk::EXPAND|Gtk::FILL, Gtk::SHRINK|Gtk::FILL, 0, 0);
122         adj_gamma_r.signal_value_changed().connect(sigc::mem_fun(*this,&studio::Dialog_Setup::on_gamma_r_change));
123
124         Gtk::HScale* scale_gamma_g(manage(new Gtk::HScale(adj_gamma_g)));
125         gamma_table->attach(*manage(new Gtk::Label(_("Green"))), 0, 1, 2, 3, Gtk::SHRINK|Gtk::FILL, Gtk::SHRINK|Gtk::FILL, 0, 0);
126         gamma_table->attach(*scale_gamma_g, 1, 2, 2, 3, Gtk::EXPAND|Gtk::FILL, Gtk::SHRINK|Gtk::FILL, 0, 0);
127         adj_gamma_g.signal_value_changed().connect(sigc::mem_fun(*this,&studio::Dialog_Setup::on_gamma_g_change));
128
129         Gtk::HScale* scale_gamma_b(manage(new Gtk::HScale(adj_gamma_b)));
130         gamma_table->attach(*manage(new Gtk::Label(_("Blue"))), 0, 1, 3, 4, Gtk::SHRINK|Gtk::FILL, Gtk::SHRINK|Gtk::FILL, 0, 0);
131         gamma_table->attach(*scale_gamma_b, 1, 2, 3, 4, Gtk::EXPAND|Gtk::FILL, Gtk::SHRINK|Gtk::FILL, 0, 0);
132         adj_gamma_b.signal_value_changed().connect(sigc::mem_fun(*this,&studio::Dialog_Setup::on_gamma_b_change));
133
134         gamma_table->attach(*manage(new Gtk::Label(_("Black Level"))), 0, 1, 4, 5, Gtk::SHRINK|Gtk::FILL, Gtk::SHRINK|Gtk::FILL, 0, 0);
135         gamma_table->attach(black_level_selector, 1, 2, 4, 5, Gtk::EXPAND|Gtk::FILL, Gtk::SHRINK|Gtk::FILL, 0, 0);
136         black_level_selector.signal_value_changed().connect(sigc::mem_fun(*this,&studio::Dialog_Setup::on_black_level_change));
137
138         //gamma_table->attach(*manage(new Gtk::Label(_("Red-Blue Level"))), 0, 1, 5, 6, Gtk::SHRINK|Gtk::FILL, Gtk::SHRINK|Gtk::FILL, 0, 0);
139         //gamma_table->attach(red_blue_level_selector, 1, 2, 5, 6, Gtk::EXPAND|Gtk::FILL, Gtk::SHRINK|Gtk::FILL, 0, 0);
140         //red_blue_level_selector.signal_value_changed().connect(sigc::mem_fun(*this,&studio::Dialog_Setup::on_red_blue_level_change));
141
142
143         // Misc
144         Gtk::Table *misc_table=manage(new Gtk::Table(2,2,false));
145         notebook->append_page(*misc_table,_("Misc."));
146
147         int xpadding(8), ypadding(8);
148
149         // Misc - Timestamp
150         timestamp_menu=manage(new class Gtk::Menu());
151         attach_label(misc_table, _("Timestamp"), 0, xpadding, ypadding);
152         misc_table->attach(timestamp_optionmenu, 1, 2, 0, 1, Gtk::EXPAND|Gtk::FILL, Gtk::SHRINK|Gtk::FILL, xpadding, ypadding);
153
154 #define ADD_TIMESTAMP(desc,x)                                                                   \
155         timestamp_menu->items().push_back(                                                      \
156                 Gtk::Menu_Helpers::MenuElem(                                                    \
157                         desc,                                                                                           \
158                         sigc::bind(                                                                                     \
159                                 sigc::mem_fun(                                                                  \
160                                         *this,                                                                          \
161                                         &studio::Dialog_Setup::set_time_format),        \
162                                 x)));
163         ADD_TIMESTAMP("HH:MM:SS.FF",            Time::FORMAT_VIDEO      );
164         ADD_TIMESTAMP("(HHh MMm SSs) FFf",      Time::FORMAT_NORMAL     );
165         ADD_TIMESTAMP("(HHhMMmSSs)FFf",         Time::FORMAT_NORMAL     | Time::FORMAT_NOSPACES );
166         ADD_TIMESTAMP("HHh MMm SSs FFf",        Time::FORMAT_NORMAL     | Time::FORMAT_FULL             );
167         ADD_TIMESTAMP("HHhMMmSSsFFf",           Time::FORMAT_NORMAL     | Time::FORMAT_NOSPACES | Time::FORMAT_FULL);
168         ADD_TIMESTAMP("FFf",                            Time::FORMAT_FRAMES );
169
170         timestamp_optionmenu.set_menu(*timestamp_menu);
171
172 #undef ADD_TIMESTAMP
173
174         {
175                 ParamDesc param_desc;
176                 param_desc
177                         .set_hint("enum")
178                         .add_enum_value(Distance::SYSTEM_UNITS,"u",_("Units"))
179                         .add_enum_value(Distance::SYSTEM_PIXELS,"px",_("Pixels"))
180                         .add_enum_value(Distance::SYSTEM_POINTS,"pt",_("Points"))
181                         .add_enum_value(Distance::SYSTEM_INCHES,"in",_("Inches"))
182                         .add_enum_value(Distance::SYSTEM_METERS,"m",_("Meters"))
183                         .add_enum_value(Distance::SYSTEM_CENTIMETERS,"cm",_("Centimeters"))
184                         .add_enum_value(Distance::SYSTEM_MILLIMETERS,"mm",_("Millimeters"));
185
186                 widget_enum=manage(new Widget_Enum());
187                 widget_enum->set_param_desc(param_desc);
188
189                 attach_label(misc_table, _("Unit System"), 1, xpadding, ypadding);
190                 misc_table->attach(*widget_enum, 1, 2, 1, 2, Gtk::EXPAND|Gtk::FILL, Gtk::SHRINK|Gtk::FILL, xpadding, ypadding);
191         }
192
193         // Misc - recent files
194         Gtk::SpinButton* recent_files_spinbutton(manage(new Gtk::SpinButton(adj_recent_files,1,0)));
195         attach_label(misc_table, _("Recent Files"), 2, xpadding, ypadding);
196         misc_table->attach(*recent_files_spinbutton, 1, 2, 2, 3, Gtk::EXPAND|Gtk::FILL, Gtk::SHRINK|Gtk::FILL, xpadding, ypadding);
197
198         // Misc - use_colorspace_gamma
199         misc_table->attach(toggle_use_colorspace_gamma, 0, 2, 7, 8, Gtk::EXPAND|Gtk::FILL, Gtk::SHRINK|Gtk::FILL, xpadding, ypadding);
200
201 #ifdef SINGLE_THREADED
202         // Misc - single_threaded
203         misc_table->attach(toggle_single_threaded, 0, 2, 10, 11, Gtk::EXPAND|Gtk::FILL, Gtk::SHRINK|Gtk::FILL, xpadding, ypadding);
204 #endif
205
206         // Misc - auto backup interval
207         attach_label(misc_table, _("Auto Backup Interval (0 to disable)"), 3, xpadding, ypadding);
208         misc_table->attach(auto_backup_interval, 1, 2, 3, 4, Gtk::EXPAND|Gtk::FILL, Gtk::SHRINK|Gtk::FILL, xpadding, ypadding);
209
210         // Misc - restrict_radius_ducks
211         misc_table->attach(toggle_restrict_radius_ducks, 0, 2, 8, 9, Gtk::EXPAND|Gtk::FILL, Gtk::SHRINK|Gtk::FILL, xpadding, ypadding);
212
213         // Misc - resize_imported_images
214         misc_table->attach(toggle_resize_imported_images, 0, 2, 9, 10, Gtk::EXPAND|Gtk::FILL, Gtk::SHRINK|Gtk::FILL, xpadding, ypadding);
215
216         // Misc - browser_command
217         attach_label(misc_table, _("Browser Command"), 4, xpadding, ypadding);
218         misc_table->attach(textbox_browser_command, 1, 2, 4, 5, Gtk::EXPAND|Gtk::FILL, Gtk::SHRINK|Gtk::FILL, xpadding, ypadding);
219
220         // Document
221         Gtk::Table *document_table = manage(new Gtk::Table(2, 4, false));
222         notebook->append_page(*document_table, _("Document"));
223
224         // Document - Preferred file name prefix
225         attach_label(document_table, _("New Document filename prefix"), 0, xpadding, ypadding);
226         document_table->attach(textbox_custom_filename_prefix, 1, 4, 0, 1, Gtk::EXPAND|Gtk::FILL, Gtk::SHRINK|Gtk::FILL, xpadding, ypadding);
227         tooltips_.set_tip(textbox_custom_filename_prefix, _("File name prefix for the new created document"));
228
229         // Document - New Document X size
230         pref_x_size_spinbutton = Gtk::manage(new Gtk::SpinButton(adj_pref_x_size, 1, 0));
231         attach_label(document_table, _("New Document X size"),1, xpadding, ypadding);
232         document_table->attach(*pref_x_size_spinbutton, 1, 2, 1, 2, Gtk::EXPAND|Gtk::FILL, Gtk::SHRINK|Gtk::FILL, xpadding, ypadding);
233         tooltips_.set_tip(*pref_x_size_spinbutton, _("Width in pixels of the new created document"));
234
235         // Document - New Document Y size
236         pref_y_size_spinbutton = Gtk::manage(new Gtk::SpinButton(adj_pref_y_size, 1, 0));
237         attach_label(document_table,_("New Document Y size"), 2, xpadding, ypadding);
238         document_table->attach(*pref_y_size_spinbutton, 1, 2, 2, 3,Gtk::EXPAND|Gtk::FILL, Gtk::SHRINK|Gtk::FILL, xpadding, ypadding);
239         tooltips_.set_tip(*pref_y_size_spinbutton, _("High in pixels of the new created document"));
240
241         //Document - Template for predefined sizes of canvases.
242         size_template_combo = Gtk::manage(new Gtk::ComboBoxText());
243         Gtk::Label* label(manage(new Gtk::Label(_("Predefined Resolutions:"))));
244         label->set_alignment(Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER);
245         document_table->attach(*label, 2, 3, 1, 2, Gtk::SHRINK|Gtk::FILL, Gtk::SHRINK|Gtk::FILL, xpadding, ypadding);
246         document_table->attach(*size_template_combo, 2, 3, 2, 3, Gtk::EXPAND|Gtk::FILL, Gtk::SHRINK|Gtk::FILL, xpadding, ypadding);
247         size_template_combo->signal_changed().connect(sigc::mem_fun(*this, &studio::Dialog_Setup::on_size_template_combo_change));
248         size_template_combo->prepend_text(_("4096x3112 Full Aperture 4K"));
249         size_template_combo->prepend_text(_("2048x1556 Full Aperture Native 2K"));
250         size_template_combo->prepend_text(_("1920x1080 HDTV 1080p/i"));
251         size_template_combo->prepend_text(_("1280x720  HDTV 720p"));
252         size_template_combo->prepend_text(_("720x576   DVD PAL"));
253         size_template_combo->prepend_text(_("720x480   DVD NTSC"));
254         size_template_combo->prepend_text(_("720x540   Web 720x"));
255         size_template_combo->prepend_text(_("720x405   Web 720x HD"));
256         size_template_combo->prepend_text(_("640x480   Web 640x"));
257         size_template_combo->prepend_text(_("640x360   Web 640x HD"));
258         size_template_combo->prepend_text(_("480x360   Web 480x"));
259         size_template_combo->prepend_text(_("480x270   Web 480x HD"));
260         size_template_combo->prepend_text(_("360x270   Web 360x"));
261         size_template_combo->prepend_text(_("360x203   Web 360x HD"));
262         size_template_combo->prepend_text(DEFAULT_PREDEFINED_SIZE);
263
264         //Document - Template for predefined fps
265         fps_template_combo = Gtk::manage(new Gtk::ComboBoxText());
266         Gtk::Label* label1(manage(new Gtk::Label(_("Predefined FPS:"))));
267         label1->set_alignment(Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER);
268         document_table->attach(*label1, 2, 3, 3, 4, Gtk::SHRINK|Gtk::FILL, Gtk::SHRINK|Gtk::FILL, xpadding, ypadding);
269         document_table->attach(*fps_template_combo,2, 3, 4, 5, Gtk::EXPAND|Gtk::FILL, Gtk::SHRINK|Gtk::FILL, xpadding, ypadding);
270         fps_template_combo->signal_changed().connect(sigc::mem_fun(*this, &studio::Dialog_Setup::on_fps_template_combo_change));
271         //Document - Fill the FPS combo box with proper strings (not localised)
272         float f[8];
273         f[0] = 60;
274         f[1] = 50;
275         f[2] = 30;
276         f[3] = 25;
277         f[4] = 24.967;
278         f[5] = 24;
279         f[6] = 15;
280         f[7] = 12;
281         for (int i=0; i<8; i++)
282                 fps_template_combo->prepend_text(strprintf("%5.3f", f[i]));
283
284         fps_template_combo->prepend_text(DEFAULT_PREDEFINED_FPS);
285
286         // Document - New Document FPS
287         pref_fps_spinbutton = Gtk::manage(new Gtk::SpinButton(adj_pref_fps, 1, 3));
288         attach_label(document_table,_("New Document FPS"), 4, xpadding, ypadding);
289         document_table->attach(*pref_fps_spinbutton, 1, 2, 4, 5, Gtk::EXPAND|Gtk::FILL, Gtk::SHRINK|Gtk::FILL, xpadding, ypadding);
290         tooltips_.set_tip(*pref_fps_spinbutton, _("Frames per second of the new created document"));
291
292         show_all_children();
293 }
294
295 Dialog_Setup::~Dialog_Setup()
296 {
297 }
298
299 void
300 Dialog_Setup::on_ok_pressed()
301 {
302     on_apply_pressed();
303         hide();
304 }
305
306 void
307 Dialog_Setup::on_apply_pressed()
308 {
309         App::gamma.set_all(1.0/adj_gamma_r.get_value(),1.0/adj_gamma_g.get_value(),1.0/adj_gamma_b.get_value(),black_level_selector.get_value(),red_blue_level_selector.get_value());
310
311         App::set_max_recent_files((int)adj_recent_files.get_value());
312
313         // Set the time format
314         App::set_time_format(get_time_format());
315
316         // Set the use_colorspace_gamma flag
317         App::use_colorspace_gamma=toggle_use_colorspace_gamma.get_active();
318
319 #ifdef SINGLE_THREADED
320         // Set the single_threaded flag
321         App::single_threaded=toggle_single_threaded.get_active();
322 #endif
323
324         // Set the auto backup interval
325         App::auto_recover->set_timeout(auto_backup_interval.get_value() * 1000);
326
327         App::distance_system=Distance::System(widget_enum->get_value());
328
329         // Set the restrict_radius_ducks flag
330         App::restrict_radius_ducks=toggle_restrict_radius_ducks.get_active();
331
332         // Set the resize_imported_images flag
333         App::resize_imported_images=toggle_resize_imported_images.get_active();
334
335         // Set the browser_command textbox
336         App::browser_command=textbox_browser_command.get_text();
337
338         // Set the preferred file name prefix
339         App::custom_filename_prefix=textbox_custom_filename_prefix.get_text();
340
341         // Set the preferred new Document X dimension
342         App::preferred_x_size=int(adj_pref_x_size.get_value());
343
344         // Set the preferred new Document Y dimension
345         App::preferred_y_size=int(adj_pref_y_size.get_value());
346
347         // Set the preferred Predefined size
348         App::predefined_size=size_template_combo->get_active_text();
349
350         // Set the preferred Predefined fps
351         App::predefined_fps=fps_template_combo->get_active_text();
352
353         // Set the preferred FPS
354         App::preferred_fps=Real(adj_pref_fps.get_value());
355
356         App::save_settings();
357 }
358
359 void
360 Dialog_Setup::on_gamma_r_change()
361 {
362         gamma_pattern.set_gamma_r(1.0/adj_gamma_r.get_value());
363         gamma_pattern.refresh();
364         gamma_pattern.queue_draw();
365 }
366
367 void
368 Dialog_Setup::on_gamma_g_change()
369 {
370         gamma_pattern.set_gamma_g(1.0/adj_gamma_g.get_value());
371         gamma_pattern.refresh();
372         gamma_pattern.queue_draw();
373 }
374
375 void
376 Dialog_Setup::on_gamma_b_change()
377 {
378         gamma_pattern.set_gamma_b(1.0/adj_gamma_b.get_value());
379         gamma_pattern.refresh();
380         gamma_pattern.queue_draw();
381 }
382
383 void
384 Dialog_Setup::on_black_level_change()
385 {
386         gamma_pattern.set_black_level(black_level_selector.get_value());
387         gamma_pattern.refresh();
388         gamma_pattern.queue_draw();
389 }
390
391 void
392 Dialog_Setup::on_red_blue_level_change()
393 {
394         gamma_pattern.set_red_blue_level(red_blue_level_selector.get_value());
395         gamma_pattern.refresh();
396         gamma_pattern.queue_draw();
397 }
398
399 void
400 Dialog_Setup::on_size_template_combo_change()
401 {
402         String selection(size_template_combo->get_active_text());
403         if(selection==DEFAULT_PREDEFINED_SIZE)
404         {
405                 pref_y_size_spinbutton->set_sensitive(true);
406                 pref_x_size_spinbutton->set_sensitive(true);
407                 return;
408         }
409         String::size_type locx=selection.find_first_of("x"); // here should be some comparison with string::npos
410         String::size_type locspace=selection.find_first_of(" ");
411         String x_size(selection.substr(0,locx));
412         String y_size(selection.substr(locx+1,locspace));
413         int x=atoi(x_size.c_str());
414         int y=atoi(y_size.c_str());
415         adj_pref_x_size.set_value(x);
416         adj_pref_y_size.set_value(y);
417         pref_y_size_spinbutton->set_sensitive(false);
418         pref_x_size_spinbutton->set_sensitive(false);
419
420         return;
421 }
422
423 void
424 Dialog_Setup::on_fps_template_combo_change()
425 {
426         String selection(fps_template_combo->get_active_text());
427         if(selection==DEFAULT_PREDEFINED_FPS)
428         {
429                 pref_fps_spinbutton->set_sensitive(true);
430                 return;
431         }
432         adj_pref_fps.set_value(atof(selection.c_str()));
433         pref_fps_spinbutton->set_sensitive(false);
434         return;
435 }
436
437 void
438 Dialog_Setup::refresh()
439 {
440         // Refresh the temporary gamma; do this before adjusting the sliders,
441         // or variables will be used before their initialization.
442         gamma_pattern.set_gamma_r(App::gamma.get_gamma_r());
443         gamma_pattern.set_gamma_g(App::gamma.get_gamma_g());
444         gamma_pattern.set_gamma_b(App::gamma.get_gamma_b());
445         gamma_pattern.set_black_level(App::gamma.get_black_level());
446         gamma_pattern.set_red_blue_level(App::gamma.get_red_blue_level());
447
448         adj_gamma_r.set_value(1.0/App::gamma.get_gamma_r());
449         adj_gamma_g.set_value(1.0/App::gamma.get_gamma_g());
450         adj_gamma_b.set_value(1.0/App::gamma.get_gamma_b());
451         black_level_selector.set_value(App::gamma.get_black_level());
452         red_blue_level_selector.set_value(App::gamma.get_red_blue_level());
453
454         gamma_pattern.refresh();
455
456         adj_recent_files.set_value(App::get_max_recent_files());
457
458         // Refresh the time format
459         set_time_format(App::get_time_format());
460
461         widget_enum->set_value(App::distance_system);
462
463         // Refresh the status of the use_colorspace_gamma flag
464         toggle_use_colorspace_gamma.set_active(App::use_colorspace_gamma);
465
466 #ifdef SINGLE_THREADED
467         // Refresh the status of the single_threaded flag
468         toggle_single_threaded.set_active(App::single_threaded);
469 #endif
470
471         // Refresh the value of the auto backup interval
472         auto_backup_interval.set_value(App::auto_recover->get_timeout() / 1000);
473
474         // Refresh the status of the restrict_radius_ducks flag
475         toggle_restrict_radius_ducks.set_active(App::restrict_radius_ducks);
476
477         // Refresh the status of the resize_imported_images flag
478         toggle_resize_imported_images.set_active(App::resize_imported_images);
479
480         // Refresh the browser_command textbox
481         textbox_browser_command.set_text(App::browser_command);
482
483         // Refresh the preferred filename prefix
484         textbox_custom_filename_prefix.set_text(App::custom_filename_prefix);
485
486         // Refresh the preferred new Document X dimension
487         adj_pref_x_size.set_value(App::preferred_x_size);
488
489         // Refresh the preferred new Document Y dimension
490         adj_pref_y_size.set_value(App::preferred_y_size);
491
492         // Refresh the preferred Predefined size
493         size_template_combo->set_active_text(App::predefined_size);
494
495         //Refresh the preferred FPS
496         adj_pref_fps.set_value(App::preferred_fps);
497
498         //Refresh the predefined FPS
499         fps_template_combo->set_active_text(App::predefined_fps);
500 }
501
502 GammaPattern::GammaPattern():
503         tile_w(80),
504         tile_h(80)
505 {
506         set_size_request(tile_w*4,tile_h*3);
507         signal_expose_event().connect(sigc::mem_fun(*this, &studio::GammaPattern::redraw));
508 }
509
510 GammaPattern::~GammaPattern()
511 {
512 }
513
514 void
515 GammaPattern::refresh()
516 {
517         black[0].set_rgb_p(
518                 r_F32_to_F32(0.0),
519                 g_F32_to_F32(0.0),
520                 b_F32_to_F32(0.0)
521         );
522         white[0].set_rgb_p(
523                 r_F32_to_F32(1.0),
524                 g_F32_to_F32(1.0),
525                 b_F32_to_F32(1.0)
526         );
527         gray50[0].set_rgb_p(
528                 r_F32_to_F32(0.5),
529                 g_F32_to_F32(0.5),
530                 b_F32_to_F32(0.5)
531         );
532         gray25[0].set_rgb_p(
533                 r_F32_to_F32(0.25),
534                 g_F32_to_F32(0.25),
535                 b_F32_to_F32(0.25)
536         );
537
538         // Reds
539         black[1].set_rgb(black[0].get_red(),0,0);
540         gray25[1].set_rgb(gray25[0].get_red(),0,0);
541         gray50[1].set_rgb(gray50[0].get_red(),0,0);
542         white[1].set_rgb(white[0].get_red(),0,0);
543
544         // Greens
545         black[2].set_rgb(0,black[0].get_green(),0);
546         gray25[2].set_rgb(0,gray25[0].get_green(),0);
547         gray50[2].set_rgb(0,gray50[0].get_green(),0);
548         white[2].set_rgb(0,white[0].get_green(),0);
549
550         // blues
551         black[3].set_rgb(0,0,black[0].get_blue());
552         gray25[3].set_rgb(0,0,gray25[0].get_blue());
553         gray50[3].set_rgb(0,0,gray50[0].get_blue());
554         white[3].set_rgb(0,0,white[0].get_blue());
555 }
556
557 bool
558 GammaPattern::redraw(GdkEventExpose */*bleh*/)
559 {
560         static const char hlines[] = { 3, 0 };
561
562         Glib::RefPtr<Gdk::GC> gc(Gdk::GC::create(get_window()));
563
564         int i;
565         Gdk::Color trueblack("#000000");
566
567         // 50% Pattern
568         for(i=0;i<4;i++)
569         {
570                 gc->set_rgb_fg_color(black[i]);
571                 get_window()->draw_rectangle(gc, true, i*tile_w, 0, tile_w, tile_h);
572
573                 gc->set_stipple(Gdk::Bitmap::create(hlines,2,2));
574                 gc->set_fill(Gdk::STIPPLED);
575                 gc->set_rgb_fg_color(white[i]);
576                 get_window()->draw_rectangle(gc, true, i*tile_w, 0, tile_w, tile_h);
577
578                 gc->set_fill(Gdk::SOLID);
579                 gc->set_rgb_fg_color(gray50[i]);
580
581                 get_window()->draw_rectangle(gc, true, i*tile_w+tile_w/4, tile_h/4, tile_w-tile_w/2, tile_h-tile_h/2);
582         }
583
584         // 25% Pattern
585         for(i=0;i<4;i++)
586         {
587                 gc->set_rgb_fg_color(black[i]);
588                 get_window()->draw_rectangle(gc, true, i*tile_w, tile_h, tile_w, tile_h);
589
590                 gc->set_stipple(Gdk::Bitmap::create(hlines,2,2));
591                 gc->set_fill(Gdk::STIPPLED);
592                 gc->set_rgb_fg_color(gray50[i]);
593                 get_window()->draw_rectangle(gc, true, i*tile_w, tile_h, tile_w, tile_h);
594
595                 gc->set_fill(Gdk::SOLID);
596                 gc->set_rgb_fg_color(gray25[i]);
597
598                 get_window()->draw_rectangle(gc, true, i*tile_w+tile_w/4, tile_h+tile_h/4, tile_w-tile_w/2, tile_h-tile_h/2);
599         }
600
601         // Black-level Pattern
602         gc->set_rgb_fg_color(trueblack);
603         get_window()->draw_rectangle(gc, true, 0, tile_h*2, tile_w*4, tile_h);
604         gc->set_fill(Gdk::SOLID);
605         for(i=0;i<4;i++)
606         {
607                 gc->set_rgb_fg_color(black[i]);
608
609                 get_window()->draw_rectangle(gc, true, i*tile_w+tile_w/4, tile_h*2+tile_h/4, tile_w-tile_w/2, tile_h-tile_h/2);
610         }
611
612         return true;
613 }
614
615
616 BlackLevelSelector::BlackLevelSelector()
617 {
618         set_size_request(-1,24);
619         signal_expose_event().connect(sigc::mem_fun(*this, &studio::BlackLevelSelector::redraw));
620
621         add_events(Gdk::BUTTON_PRESS_MASK | Gdk::BUTTON_RELEASE_MASK);
622         add_events(Gdk::BUTTON1_MOTION_MASK);
623         add_events(Gdk::BUTTON1_MOTION_MASK);
624 }
625
626 BlackLevelSelector::~BlackLevelSelector()
627 {
628 }
629
630 bool
631 BlackLevelSelector::redraw(GdkEventExpose */*bleh*/)
632 {
633         const int w(get_width()),h(get_height());
634
635         Gdk::Color color;
636
637         Glib::RefPtr<Gdk::GC> gc(Gdk::GC::create(get_window()));
638
639         int i;
640
641         // Draw the gradient
642         for(i=0;i<w;i++)
643         {
644                 color.set_rgb(i*65536/w,i*65536/w,i*65536/w);
645
646                 gc->set_rgb_fg_color(color);
647                 get_window()->draw_rectangle(gc, true, i, 0, 1, h);
648         }
649
650         // Draw a frame
651         gc->set_rgb_fg_color(Gdk::Color("#000000"));
652         get_window()->draw_rectangle(gc, false, 0, 0, w-1, h-1);
653
654         // Draw the position of the current value
655         i=(int)(level*w+0.5);
656         gc->set_rgb_fg_color(Gdk::Color("#ff0000"));
657         get_window()->draw_rectangle(gc, true, i, 1, 1, h-1);
658
659         // Print out the value
660         Glib::RefPtr<Pango::Layout> layout(Pango::Layout::create(get_pango_context()));
661         layout->set_text(etl::strprintf("%0.01f%%",level*100.0f));
662         layout->set_alignment(Pango::ALIGN_CENTER);
663         gc->set_rgb_fg_color(Gdk::Color("#a00000"));
664         get_window()->draw_layout(gc, w/2, 4, layout);
665
666         return true;
667 }
668
669
670
671 bool
672 BlackLevelSelector::on_event(GdkEvent *event)
673 {
674         int x(round_to_int(event->button.x));
675         //int y(round_to_int(event->button.y));
676
677     switch(event->type)
678     {
679         case GDK_MOTION_NOTIFY:
680                 level=(float)x/(float)get_width();
681                 if(level<0.0f)level=0.0f;
682                 if(level>1.0f)level=1.0f;
683                 signal_value_changed_();
684                 queue_draw();
685                 return true;
686                 break;
687         case GDK_BUTTON_PRESS:
688         case GDK_BUTTON_RELEASE:
689                 if(event->button.button==1)
690                 {
691                         level=(float)x/(float)get_width();
692                         if(level<0.0f)level=0.0f;
693                         if(level>1.0f)level=1.0f;
694                         signal_value_changed_();
695                         queue_draw();
696                         return true;
697                 }
698                 break;
699         default:
700                 break;
701         }
702
703         return false;
704 }
705
706
707 void
708 Dialog_Setup::set_time_format(synfig::Time::Format x)
709 {
710         time_format=x;
711         if (x <= Time::FORMAT_VIDEO)
712                 timestamp_optionmenu.set_history(0);
713         else if (x == (Time::FORMAT_NORMAL))
714                 timestamp_optionmenu.set_history(1);
715         else if (x == (Time::FORMAT_NORMAL | Time::FORMAT_NOSPACES))
716                 timestamp_optionmenu.set_history(2);
717         else if (x == (Time::FORMAT_NORMAL | Time::FORMAT_FULL))
718                 timestamp_optionmenu.set_history(3);
719         else if (x == (Time::FORMAT_NORMAL | Time::FORMAT_NOSPACES | Time::FORMAT_FULL))
720                 timestamp_optionmenu.set_history(4);
721         else if (x == (Time::FORMAT_FRAMES))
722                 timestamp_optionmenu.set_history(5);
723         else
724                 timestamp_optionmenu.set_history(1);
725 }
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742 RedBlueLevelSelector::RedBlueLevelSelector()
743 {
744         set_size_request(-1,24);
745         signal_expose_event().connect(sigc::mem_fun(*this, &studio::RedBlueLevelSelector::redraw));
746
747         add_events(Gdk::BUTTON_PRESS_MASK | Gdk::BUTTON_RELEASE_MASK);
748         add_events(Gdk::BUTTON1_MOTION_MASK);
749         add_events(Gdk::BUTTON1_MOTION_MASK);
750 }
751
752 RedBlueLevelSelector::~RedBlueLevelSelector()
753 {
754 }
755
756 bool
757 RedBlueLevelSelector::redraw(GdkEventExpose */*bleh*/)
758 {
759         const int w(get_width()),h(get_height());
760
761         Gdk::Color color;
762
763         Glib::RefPtr<Gdk::GC> gc(Gdk::GC::create(get_window()));
764
765         int i;
766
767         // Draw the gradient
768         for(i=0;i<w;i++)
769         {
770                 float red_blue(((float(i)/float(w)+0.5f)-1.0f)/2.0f+1.0f);
771                 float blue_red(2.0f-(red_blue));
772                 if(red_blue>1.0f)red_blue=1.0f;
773                 if(blue_red>1.0f)blue_red=1.0f;
774
775                 color.set_rgb(
776                         round_to_int(min(red_blue,1.0f)*65535),
777                         round_to_int(sqrt(min(red_blue,blue_red))*65535),
778                         round_to_int(min(blue_red,1.0f)*65535)
779                 );
780
781                 gc->set_rgb_fg_color(color);
782                 get_window()->draw_rectangle(gc, true, i, 0, 1, h);
783         }
784
785         // Draw a frame
786         gc->set_rgb_fg_color(Gdk::Color("#000000"));
787         get_window()->draw_rectangle(gc, false, 0, 0, w-1, h-1);
788
789         // Draw the position of the current value
790         i=(int)(((level-1.0f)*2.0f+1.0f-0.5f)*w+0.5);
791         gc->set_rgb_fg_color(Gdk::Color("#00ff00"));
792         get_window()->draw_rectangle(gc, true, i, 1, 1, h-1);
793
794         // Print out the value
795         Glib::RefPtr<Pango::Layout> layout(Pango::Layout::create(get_pango_context()));
796         layout->set_text(etl::strprintf("%0.02f",level));
797         layout->set_alignment(Pango::ALIGN_CENTER);
798         gc->set_rgb_fg_color(Gdk::Color("#a00000"));
799         get_window()->draw_layout(gc, w/2, 4, layout);
800
801         return true;
802 }
803
804
805
806 bool
807 RedBlueLevelSelector::on_event(GdkEvent *event)
808 {
809         int x(round_to_int(event->button.x));
810         //int y(round_to_int(event->button.y));
811
812     switch(event->type)
813     {
814         case GDK_MOTION_NOTIFY:
815                 level=(((float)(x)/(float)get_width()+0.5)-1.0f)/2.0f+1.0f;
816                 if(level<0.5f)level=0.5f;
817                 if(level>1.5f)level=1.5f;
818                 signal_value_changed_();
819                 queue_draw();
820                 return true;
821                 break;
822         case GDK_BUTTON_PRESS:
823         case GDK_BUTTON_RELEASE:
824                 if(event->button.button==1)
825                 {
826                         level=(((float)(x)/(float)get_width()+0.5)-1.0f)/2.0f+1.0f;
827                         if(level<0.5f)level=0.5f;
828                         if(level>1.5f)level=1.5f;
829                         signal_value_changed_();
830                         queue_draw();
831                         return true;
832                 }
833                 break;
834         default:
835                 break;
836         }
837
838         return false;
839 }