Add 2 new valuenode types: "Angle String" and "Int String".
[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 {
85         // Setup the buttons
86
87         Gtk::Button *ok_button(manage(new class Gtk::Button(Gtk::StockID("gtk-ok"))));
88         ok_button->show();
89         add_action_widget(*ok_button,2);
90         ok_button->signal_clicked().connect(sigc::mem_fun(*this, &Dialog_Setup::on_ok_pressed));
91
92         Gtk::Button *apply_button(manage(new class Gtk::Button(Gtk::StockID("gtk-apply"))));
93         apply_button->show();
94         add_action_widget(*apply_button,1);
95         apply_button->signal_clicked().connect(sigc::mem_fun(*this, &Dialog_Setup::on_apply_pressed));
96
97         Gtk::Button *cancel_button(manage(new class Gtk::Button(Gtk::StockID("gtk-close"))));
98         cancel_button->show();
99         add_action_widget(*cancel_button,0);
100         cancel_button->signal_clicked().connect(sigc::mem_fun(*this, &Dialog_Setup::hide));
101
102
103         // Notebook
104         Gtk::Notebook *notebook=manage(new class Gtk::Notebook());
105         get_vbox()->pack_start(*notebook);
106
107
108         // Gamma
109         Gtk::Table *gamma_table=manage(new Gtk::Table(2,2,false));
110         notebook->append_page(*gamma_table,_("Gamma"));
111         //gamma_frame->add(*gamma_table);
112
113         gamma_table->attach(gamma_pattern, 0, 2, 0, 1, Gtk::EXPAND, Gtk::SHRINK|Gtk::FILL, 0, 0);
114
115         Gtk::HScale* scale_gamma_r(manage(new Gtk::HScale(adj_gamma_r)));
116         gamma_table->attach(*manage(new Gtk::Label(_("Red"))), 0, 1, 1, 2, Gtk::SHRINK|Gtk::FILL, Gtk::SHRINK|Gtk::FILL, 0, 0);
117         gamma_table->attach(*scale_gamma_r, 1, 2, 1, 2, Gtk::EXPAND|Gtk::FILL, Gtk::SHRINK|Gtk::FILL, 0, 0);
118         adj_gamma_r.signal_value_changed().connect(sigc::mem_fun(*this,&studio::Dialog_Setup::on_gamma_r_change));
119
120         Gtk::HScale* scale_gamma_g(manage(new Gtk::HScale(adj_gamma_g)));
121         gamma_table->attach(*manage(new Gtk::Label(_("Green"))), 0, 1, 2, 3, Gtk::SHRINK|Gtk::FILL, Gtk::SHRINK|Gtk::FILL, 0, 0);
122         gamma_table->attach(*scale_gamma_g, 1, 2, 2, 3, Gtk::EXPAND|Gtk::FILL, Gtk::SHRINK|Gtk::FILL, 0, 0);
123         adj_gamma_g.signal_value_changed().connect(sigc::mem_fun(*this,&studio::Dialog_Setup::on_gamma_g_change));
124
125         Gtk::HScale* scale_gamma_b(manage(new Gtk::HScale(adj_gamma_b)));
126         gamma_table->attach(*manage(new Gtk::Label(_("Blue"))), 0, 1, 3, 4, Gtk::SHRINK|Gtk::FILL, Gtk::SHRINK|Gtk::FILL, 0, 0);
127         gamma_table->attach(*scale_gamma_b, 1, 2, 3, 4, Gtk::EXPAND|Gtk::FILL, Gtk::SHRINK|Gtk::FILL, 0, 0);
128         adj_gamma_b.signal_value_changed().connect(sigc::mem_fun(*this,&studio::Dialog_Setup::on_gamma_b_change));
129
130         gamma_table->attach(*manage(new Gtk::Label(_("Black Level"))), 0, 1, 4, 5, Gtk::SHRINK|Gtk::FILL, Gtk::SHRINK|Gtk::FILL, 0, 0);
131         gamma_table->attach(black_level_selector, 1, 2, 4, 5, Gtk::EXPAND|Gtk::FILL, Gtk::SHRINK|Gtk::FILL, 0, 0);
132         black_level_selector.signal_value_changed().connect(sigc::mem_fun(*this,&studio::Dialog_Setup::on_black_level_change));
133
134         //gamma_table->attach(*manage(new Gtk::Label(_("Red-Blue Level"))), 0, 1, 5, 6, Gtk::SHRINK|Gtk::FILL, Gtk::SHRINK|Gtk::FILL, 0, 0);
135         //gamma_table->attach(red_blue_level_selector, 1, 2, 5, 6, Gtk::EXPAND|Gtk::FILL, Gtk::SHRINK|Gtk::FILL, 0, 0);
136         //red_blue_level_selector.signal_value_changed().connect(sigc::mem_fun(*this,&studio::Dialog_Setup::on_red_blue_level_change));
137
138
139         // Misc
140         Gtk::Table *misc_table=manage(new Gtk::Table(2,2,false));
141         notebook->append_page(*misc_table,_("Misc."));
142
143         int xpadding(8), ypadding(8);
144
145         // Misc - Timestamp
146         timestamp_menu=manage(new class Gtk::Menu());
147         attach_label(misc_table, _("Timestamp"), 0, xpadding, ypadding);
148         misc_table->attach(timestamp_optionmenu, 1, 2, 0, 1, Gtk::EXPAND|Gtk::FILL, Gtk::SHRINK|Gtk::FILL, xpadding, ypadding);
149
150 #define ADD_TIMESTAMP(desc,x)                                                                   \
151         timestamp_menu->items().push_back(                                                      \
152                 Gtk::Menu_Helpers::MenuElem(                                                    \
153                         desc,                                                                                           \
154                         sigc::bind(                                                                                     \
155                                 sigc::mem_fun(                                                                  \
156                                         *this,                                                                          \
157                                         &studio::Dialog_Setup::set_time_format),        \
158                                 x)));
159         ADD_TIMESTAMP("HH:MM:SS.FF",            Time::FORMAT_VIDEO      );
160         ADD_TIMESTAMP("(HHh MMm SSs) FFf",      Time::FORMAT_NORMAL     );
161         ADD_TIMESTAMP("(HHhMMmSSs)FFf",         Time::FORMAT_NORMAL     | Time::FORMAT_NOSPACES );
162         ADD_TIMESTAMP("HHh MMm SSs FFf",        Time::FORMAT_NORMAL     | Time::FORMAT_FULL             );
163         ADD_TIMESTAMP("HHhMMmSSsFFf",           Time::FORMAT_NORMAL     | Time::FORMAT_NOSPACES | Time::FORMAT_FULL);
164         ADD_TIMESTAMP("FFf",                            Time::FORMAT_FRAMES );
165
166         timestamp_optionmenu.set_menu(*timestamp_menu);
167
168 #undef ADD_TIMESTAMP
169
170         {
171                 ParamDesc param_desc;
172                 param_desc
173                         .set_hint("enum")
174                         .add_enum_value(Distance::SYSTEM_UNITS,"u",_("Units"))
175                         .add_enum_value(Distance::SYSTEM_PIXELS,"px",_("Pixels"))
176                         .add_enum_value(Distance::SYSTEM_POINTS,"pt",_("Points"))
177                         .add_enum_value(Distance::SYSTEM_INCHES,"in",_("Inches"))
178                         .add_enum_value(Distance::SYSTEM_METERS,"m",_("Meters"))
179                         .add_enum_value(Distance::SYSTEM_CENTIMETERS,"cm",_("Centimeters"))
180                         .add_enum_value(Distance::SYSTEM_MILLIMETERS,"mm",_("Millimeters"));
181
182                 widget_enum=manage(new Widget_Enum());
183                 widget_enum->set_param_desc(param_desc);
184
185                 attach_label(misc_table, _("Unit System"), 1, xpadding, ypadding);
186                 misc_table->attach(*widget_enum, 1, 2, 1, 2, Gtk::EXPAND|Gtk::FILL, Gtk::SHRINK|Gtk::FILL, xpadding, ypadding);
187         }
188
189         // Misc - recent files
190         Gtk::SpinButton* recent_files_spinbutton(manage(new Gtk::SpinButton(adj_recent_files,1,0)));
191         attach_label(misc_table, _("Recent Files"), 2, xpadding, ypadding);
192         misc_table->attach(*recent_files_spinbutton, 1, 2, 2, 3, Gtk::EXPAND|Gtk::FILL, Gtk::SHRINK|Gtk::FILL, xpadding, ypadding);
193
194         // Misc - use_colorspace_gamma
195         misc_table->attach(toggle_use_colorspace_gamma, 0, 2, 5, 6, Gtk::EXPAND|Gtk::FILL, Gtk::SHRINK|Gtk::FILL, xpadding, ypadding);
196
197 #ifdef SINGLE_THREADED
198         // Misc - single_threaded
199         misc_table->attach(toggle_single_threaded, 0, 2, 7, 8, Gtk::EXPAND|Gtk::FILL, Gtk::SHRINK|Gtk::FILL, xpadding, ypadding);
200 #endif
201
202         // Misc - auto backup interval
203         attach_label(misc_table, _("Auto Backup Interval (0 to disable)"), 3, xpadding, ypadding);
204         misc_table->attach(auto_backup_interval, 1, 2, 3, 4, Gtk::EXPAND|Gtk::FILL, Gtk::SHRINK|Gtk::FILL, xpadding, ypadding);
205
206         // Misc - restrict_radius_ducks
207         misc_table->attach(toggle_restrict_radius_ducks, 0, 2, 6, 7, Gtk::EXPAND|Gtk::FILL, Gtk::SHRINK|Gtk::FILL, xpadding, ypadding);
208
209         // Misc - browser_command
210         attach_label(misc_table, _("Browser Command"), 4, xpadding, ypadding);
211         misc_table->attach(textbox_browser_command, 1, 2, 4, 5, Gtk::EXPAND|Gtk::FILL, Gtk::SHRINK|Gtk::FILL, xpadding, ypadding);
212
213         show_all_children();
214 }
215
216 Dialog_Setup::~Dialog_Setup()
217 {
218 }
219
220 void
221 Dialog_Setup::on_ok_pressed()
222 {
223     on_apply_pressed();
224         hide();
225 }
226
227 void
228 Dialog_Setup::on_apply_pressed()
229 {
230         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());
231
232         App::set_max_recent_files((int)adj_recent_files.get_value());
233
234         // Set the time format
235         App::set_time_format(get_time_format());
236
237         // Set the use_colorspace_gamma flag
238         App::use_colorspace_gamma=toggle_use_colorspace_gamma.get_active();
239
240 #ifdef SINGLE_THREADED
241         // Set the single_threaded flag
242         App::single_threaded=toggle_single_threaded.get_active();
243 #endif
244
245         // Set the auto backup interval
246         App::auto_recover->set_timeout(auto_backup_interval.get_value() * 1000);
247
248         App::distance_system=Distance::System(widget_enum->get_value());
249
250         // Set the restrict_radius_ducks flag
251         App::restrict_radius_ducks=toggle_restrict_radius_ducks.get_active();
252
253         // Set the browser_command textbox
254         App::browser_command=textbox_browser_command.get_text();
255
256         App::save_settings();
257 }
258
259 void
260 Dialog_Setup::on_gamma_r_change()
261 {
262         gamma_pattern.set_gamma_r(1.0/adj_gamma_r.get_value());
263         gamma_pattern.refresh();
264         gamma_pattern.queue_draw();
265 }
266
267 void
268 Dialog_Setup::on_gamma_g_change()
269 {
270         gamma_pattern.set_gamma_g(1.0/adj_gamma_g.get_value());
271         gamma_pattern.refresh();
272         gamma_pattern.queue_draw();
273 }
274
275 void
276 Dialog_Setup::on_gamma_b_change()
277 {
278         gamma_pattern.set_gamma_b(1.0/adj_gamma_b.get_value());
279         gamma_pattern.refresh();
280         gamma_pattern.queue_draw();
281 }
282
283 void
284 Dialog_Setup::on_black_level_change()
285 {
286         gamma_pattern.set_black_level(black_level_selector.get_value());
287         gamma_pattern.refresh();
288         gamma_pattern.queue_draw();
289 }
290
291 void
292 Dialog_Setup::on_red_blue_level_change()
293 {
294         gamma_pattern.set_red_blue_level(red_blue_level_selector.get_value());
295         gamma_pattern.refresh();
296         gamma_pattern.queue_draw();
297 }
298
299
300 void
301 Dialog_Setup::refresh()
302 {
303         // Refresh the temporary gamma; do this before adjusting the sliders,
304         // or variables will be used before their initialization.
305         gamma_pattern.set_gamma_r(App::gamma.get_gamma_r());
306         gamma_pattern.set_gamma_g(App::gamma.get_gamma_g());
307         gamma_pattern.set_gamma_b(App::gamma.get_gamma_b());
308         gamma_pattern.set_black_level(App::gamma.get_black_level());
309         gamma_pattern.set_red_blue_level(App::gamma.get_red_blue_level());
310
311         adj_gamma_r.set_value(1.0/App::gamma.get_gamma_r());
312         adj_gamma_g.set_value(1.0/App::gamma.get_gamma_g());
313         adj_gamma_b.set_value(1.0/App::gamma.get_gamma_b());
314         black_level_selector.set_value(App::gamma.get_black_level());
315         red_blue_level_selector.set_value(App::gamma.get_red_blue_level());
316
317         gamma_pattern.refresh();
318
319         adj_recent_files.set_value(App::get_max_recent_files());
320
321         // Refresh the time format
322         set_time_format(App::get_time_format());
323
324         widget_enum->set_value(App::distance_system);
325
326         // Refresh the status of the use_colorspace_gamma flag
327         toggle_use_colorspace_gamma.set_active(App::use_colorspace_gamma);
328
329 #ifdef SINGLE_THREADED
330         // Refresh the status of the single_threaded flag
331         toggle_single_threaded.set_active(App::single_threaded);
332 #endif
333
334         // Refresh the value of the auto backup interval
335         auto_backup_interval.set_value(App::auto_recover->get_timeout() / 1000);
336
337         // Refresh the status of the restrict_radius_ducks flag
338         toggle_restrict_radius_ducks.set_active(App::restrict_radius_ducks);
339
340         // Refresh the browser_command textbox
341         textbox_browser_command.set_text(App::browser_command);
342 }
343
344 GammaPattern::GammaPattern():
345         tile_w(80),
346         tile_h(80)
347 {
348         set_size_request(tile_w*4,tile_h*3);
349         signal_expose_event().connect(sigc::mem_fun(*this, &studio::GammaPattern::redraw));
350 }
351
352 GammaPattern::~GammaPattern()
353 {
354 }
355
356 void
357 GammaPattern::refresh()
358 {
359         black[0].set_rgb_p(
360                 r_F32_to_F32(0.0),
361                 g_F32_to_F32(0.0),
362                 b_F32_to_F32(0.0)
363         );
364         white[0].set_rgb_p(
365                 r_F32_to_F32(1.0),
366                 g_F32_to_F32(1.0),
367                 b_F32_to_F32(1.0)
368         );
369         gray50[0].set_rgb_p(
370                 r_F32_to_F32(0.5),
371                 g_F32_to_F32(0.5),
372                 b_F32_to_F32(0.5)
373         );
374         gray25[0].set_rgb_p(
375                 r_F32_to_F32(0.25),
376                 g_F32_to_F32(0.25),
377                 b_F32_to_F32(0.25)
378         );
379
380         // Reds
381         black[1].set_rgb(black[0].get_red(),0,0);
382         gray25[1].set_rgb(gray25[0].get_red(),0,0);
383         gray50[1].set_rgb(gray50[0].get_red(),0,0);
384         white[1].set_rgb(white[0].get_red(),0,0);
385
386         // Greens
387         black[2].set_rgb(0,black[0].get_green(),0);
388         gray25[2].set_rgb(0,gray25[0].get_green(),0);
389         gray50[2].set_rgb(0,gray50[0].get_green(),0);
390         white[2].set_rgb(0,white[0].get_green(),0);
391
392         // blues
393         black[3].set_rgb(0,0,black[0].get_blue());
394         gray25[3].set_rgb(0,0,gray25[0].get_blue());
395         gray50[3].set_rgb(0,0,gray50[0].get_blue());
396         white[3].set_rgb(0,0,white[0].get_blue());
397 }
398
399 bool
400 GammaPattern::redraw(GdkEventExpose */*bleh*/)
401 {
402         static const char hlines[] = { 3, 0 };
403
404         Glib::RefPtr<Gdk::GC> gc(Gdk::GC::create(get_window()));
405
406         int i;
407         Gdk::Color trueblack("#000000");
408
409         // 50% Pattern
410         for(i=0;i<4;i++)
411         {
412                 gc->set_rgb_fg_color(black[i]);
413                 get_window()->draw_rectangle(gc, true, i*tile_w, 0, tile_w, tile_h);
414
415                 gc->set_stipple(Gdk::Bitmap::create(hlines,2,2));
416                 gc->set_fill(Gdk::STIPPLED);
417                 gc->set_rgb_fg_color(white[i]);
418                 get_window()->draw_rectangle(gc, true, i*tile_w, 0, tile_w, tile_h);
419
420                 gc->set_fill(Gdk::SOLID);
421                 gc->set_rgb_fg_color(gray50[i]);
422
423                 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);
424         }
425
426         // 25% Pattern
427         for(i=0;i<4;i++)
428         {
429                 gc->set_rgb_fg_color(black[i]);
430                 get_window()->draw_rectangle(gc, true, i*tile_w, tile_h, tile_w, tile_h);
431
432                 gc->set_stipple(Gdk::Bitmap::create(hlines,2,2));
433                 gc->set_fill(Gdk::STIPPLED);
434                 gc->set_rgb_fg_color(gray50[i]);
435                 get_window()->draw_rectangle(gc, true, i*tile_w, tile_h, tile_w, tile_h);
436
437                 gc->set_fill(Gdk::SOLID);
438                 gc->set_rgb_fg_color(gray25[i]);
439
440                 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);
441         }
442
443         // Black-level Pattern
444         gc->set_rgb_fg_color(trueblack);
445         get_window()->draw_rectangle(gc, true, 0, tile_h*2, tile_w*4, tile_h);
446         gc->set_fill(Gdk::SOLID);
447         for(i=0;i<4;i++)
448         {
449                 gc->set_rgb_fg_color(black[i]);
450
451                 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);
452         }
453
454         return true;
455 }
456
457
458 BlackLevelSelector::BlackLevelSelector()
459 {
460         set_size_request(-1,24);
461         signal_expose_event().connect(sigc::mem_fun(*this, &studio::BlackLevelSelector::redraw));
462
463         add_events(Gdk::BUTTON_PRESS_MASK | Gdk::BUTTON_RELEASE_MASK);
464         add_events(Gdk::BUTTON1_MOTION_MASK);
465         add_events(Gdk::BUTTON1_MOTION_MASK);
466 }
467
468 BlackLevelSelector::~BlackLevelSelector()
469 {
470 }
471
472 bool
473 BlackLevelSelector::redraw(GdkEventExpose */*bleh*/)
474 {
475         const int w(get_width()),h(get_height());
476
477         Gdk::Color color;
478
479         Glib::RefPtr<Gdk::GC> gc(Gdk::GC::create(get_window()));
480
481         int i;
482
483         // Draw the gradient
484         for(i=0;i<w;i++)
485         {
486                 color.set_rgb(i*65536/w,i*65536/w,i*65536/w);
487
488                 gc->set_rgb_fg_color(color);
489                 get_window()->draw_rectangle(gc, true, i, 0, 1, h);
490         }
491
492         // Draw a frame
493         gc->set_rgb_fg_color(Gdk::Color("#000000"));
494         get_window()->draw_rectangle(gc, false, 0, 0, w-1, h-1);
495
496         // Draw the position of the current value
497         i=(int)(level*w+0.5);
498         gc->set_rgb_fg_color(Gdk::Color("#ff0000"));
499         get_window()->draw_rectangle(gc, true, i, 1, 1, h-1);
500
501         // Print out the value
502         Glib::RefPtr<Pango::Layout> layout(Pango::Layout::create(get_pango_context()));
503         layout->set_text(etl::strprintf("%0.01f%%",level*100.0f));
504         layout->set_alignment(Pango::ALIGN_CENTER);
505         gc->set_rgb_fg_color(Gdk::Color("#a00000"));
506         get_window()->draw_layout(gc, w/2, 4, layout);
507
508         return true;
509 }
510
511
512
513 bool
514 BlackLevelSelector::on_event(GdkEvent *event)
515 {
516         int x(round_to_int(event->button.x));
517         //int y(round_to_int(event->button.y));
518
519     switch(event->type)
520     {
521         case GDK_MOTION_NOTIFY:
522                 level=(float)x/(float)get_width();
523                 if(level<0.0f)level=0.0f;
524                 if(level>1.0f)level=1.0f;
525                 signal_value_changed_();
526                 queue_draw();
527                 return true;
528                 break;
529         case GDK_BUTTON_PRESS:
530         case GDK_BUTTON_RELEASE:
531                 if(event->button.button==1)
532                 {
533                         level=(float)x/(float)get_width();
534                         if(level<0.0f)level=0.0f;
535                         if(level>1.0f)level=1.0f;
536                         signal_value_changed_();
537                         queue_draw();
538                         return true;
539                 }
540                 break;
541         default:
542                 break;
543         }
544
545         return false;
546 }
547
548
549 void
550 Dialog_Setup::set_time_format(synfig::Time::Format x)
551 {
552         time_format=x;
553         if (x <= Time::FORMAT_VIDEO)
554                 timestamp_optionmenu.set_history(0);
555         else if (x == (Time::FORMAT_NORMAL))
556                 timestamp_optionmenu.set_history(1);
557         else if (x == (Time::FORMAT_NORMAL | Time::FORMAT_NOSPACES))
558                 timestamp_optionmenu.set_history(2);
559         else if (x == (Time::FORMAT_NORMAL | Time::FORMAT_FULL))
560                 timestamp_optionmenu.set_history(3);
561         else if (x == (Time::FORMAT_NORMAL | Time::FORMAT_NOSPACES | Time::FORMAT_FULL))
562                 timestamp_optionmenu.set_history(4);
563         else if (x == (Time::FORMAT_FRAMES))
564                 timestamp_optionmenu.set_history(5);
565         else
566                 timestamp_optionmenu.set_history(1);
567 }
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584 RedBlueLevelSelector::RedBlueLevelSelector()
585 {
586         set_size_request(-1,24);
587         signal_expose_event().connect(sigc::mem_fun(*this, &studio::RedBlueLevelSelector::redraw));
588
589         add_events(Gdk::BUTTON_PRESS_MASK | Gdk::BUTTON_RELEASE_MASK);
590         add_events(Gdk::BUTTON1_MOTION_MASK);
591         add_events(Gdk::BUTTON1_MOTION_MASK);
592 }
593
594 RedBlueLevelSelector::~RedBlueLevelSelector()
595 {
596 }
597
598 bool
599 RedBlueLevelSelector::redraw(GdkEventExpose */*bleh*/)
600 {
601         const int w(get_width()),h(get_height());
602
603         Gdk::Color color;
604
605         Glib::RefPtr<Gdk::GC> gc(Gdk::GC::create(get_window()));
606
607         int i;
608
609         // Draw the gradient
610         for(i=0;i<w;i++)
611         {
612                 float red_blue(((float(i)/float(w)+0.5f)-1.0f)/2.0f+1.0f);
613                 float blue_red(2.0f-(red_blue));
614                 if(red_blue>1.0f)red_blue=1.0f;
615                 if(blue_red>1.0f)blue_red=1.0f;
616
617                 color.set_rgb(
618                         round_to_int(min(red_blue,1.0f)*65535),
619                         round_to_int(sqrt(min(red_blue,blue_red))*65535),
620                         round_to_int(min(blue_red,1.0f)*65535)
621                 );
622
623                 gc->set_rgb_fg_color(color);
624                 get_window()->draw_rectangle(gc, true, i, 0, 1, h);
625         }
626
627         // Draw a frame
628         gc->set_rgb_fg_color(Gdk::Color("#000000"));
629         get_window()->draw_rectangle(gc, false, 0, 0, w-1, h-1);
630
631         // Draw the position of the current value
632         i=(int)(((level-1.0f)*2.0f+1.0f-0.5f)*w+0.5);
633         gc->set_rgb_fg_color(Gdk::Color("#00ff00"));
634         get_window()->draw_rectangle(gc, true, i, 1, 1, h-1);
635
636         // Print out the value
637         Glib::RefPtr<Pango::Layout> layout(Pango::Layout::create(get_pango_context()));
638         layout->set_text(etl::strprintf("%0.02f",level));
639         layout->set_alignment(Pango::ALIGN_CENTER);
640         gc->set_rgb_fg_color(Gdk::Color("#a00000"));
641         get_window()->draw_layout(gc, w/2, 4, layout);
642
643         return true;
644 }
645
646
647
648 bool
649 RedBlueLevelSelector::on_event(GdkEvent *event)
650 {
651         int x(round_to_int(event->button.x));
652         //int y(round_to_int(event->button.y));
653
654     switch(event->type)
655     {
656         case GDK_MOTION_NOTIFY:
657                 level=(((float)(x)/(float)get_width()+0.5)-1.0f)/2.0f+1.0f;
658                 if(level<0.5f)level=0.5f;
659                 if(level>1.5f)level=1.5f;
660                 signal_value_changed_();
661                 queue_draw();
662                 return true;
663                 break;
664         case GDK_BUTTON_PRESS:
665         case GDK_BUTTON_RELEASE:
666                 if(event->button.button==1)
667                 {
668                         level=(((float)(x)/(float)get_width()+0.5)-1.0f)/2.0f+1.0f;
669                         if(level<0.5f)level=0.5f;
670                         if(level>1.5f)level=1.5f;
671                         signal_value_changed_();
672                         queue_draw();
673                         return true;
674                 }
675                 break;
676         default:
677                 break;
678         }
679
680         return false;
681 }