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