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