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