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