1 /* === S Y N F I G ========================================================= */
2 /*! \file dialog_setup.cpp
3 ** \brief Template File
8 ** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
9 ** Copyright (c) 2007 Chris Moore
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.
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.
22 /* ========================================================================= */
24 /* === H E A D E R S ======================================================= */
33 #include "dialog_setup.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"
42 #include <ETL/stringf>
46 /* === U S I N G =========================================================== */
50 using namespace synfig;
51 using namespace studio;
53 /* === M A C R O S ========================================================= */
55 /* === G L O B A L S ======================================================= */
57 /* === P R O C E D U R E S ================================================= */
59 /* === M E T H O D S ======================================================= */
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"))
73 Gtk::Button *ok_button(manage(new class Gtk::Button(Gtk::StockID("gtk-ok"))));
75 add_action_widget(*ok_button,2);
76 ok_button->signal_clicked().connect(sigc::mem_fun(*this, &Dialog_Setup::on_ok_pressed));
78 Gtk::Button *apply_button(manage(new class Gtk::Button(Gtk::StockID("gtk-apply"))));
80 add_action_widget(*apply_button,1);
81 apply_button->signal_clicked().connect(sigc::mem_fun(*this, &Dialog_Setup::on_apply_pressed));
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));
90 Gtk::Notebook *notebook=manage(new class Gtk::Notebook());
91 get_vbox()->pack_start(*notebook);
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);
99 gamma_table->attach(gamma_pattern, 0, 2, 0, 1, Gtk::EXPAND, Gtk::SHRINK|Gtk::FILL, 0, 0);
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));
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));
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));
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));
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));
126 Gtk::Table *misc_table=manage(new Gtk::Table(2,2,false));
127 notebook->append_page(*misc_table,_("Misc."));
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);
134 #define ADD_TIMESTAMP(desc,x) \
135 timestamp_menu->items().push_back( \
136 Gtk::Menu_Helpers::MenuElem( \
141 &studio::Dialog_Setup::set_time_format \
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);
153 timestamp_optionmenu.set_menu(*timestamp_menu);
158 ParamDesc param_desc;
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"));
169 widget_enum=manage(new Widget_Enum());
170 widget_enum->set_param_desc(param_desc);
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);
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);
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);
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);
190 Dialog_Setup::~Dialog_Setup()
195 Dialog_Setup::on_ok_pressed()
202 Dialog_Setup::on_apply_pressed()
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());
206 App::set_max_recent_files((int)adj_recent_files.get_value());
208 // Set the time format
209 App::set_time_format(get_time_format());
211 // Set the use_colorspace_gamma flag
212 App::use_colorspace_gamma=toggle_use_colorspace_gamma.get_active();
214 // Set the single_threaded flag
215 App::single_threaded=toggle_single_threaded.get_active();
217 App::distance_system=Distance::System(widget_enum->get_value());
219 App::save_settings();
223 Dialog_Setup::on_gamma_r_change()
225 gamma_pattern.set_gamma_r(1.0/adj_gamma_r.get_value());
226 gamma_pattern.refresh();
227 gamma_pattern.queue_draw();
231 Dialog_Setup::on_gamma_g_change()
233 gamma_pattern.set_gamma_g(1.0/adj_gamma_g.get_value());
234 gamma_pattern.refresh();
235 gamma_pattern.queue_draw();
239 Dialog_Setup::on_gamma_b_change()
241 gamma_pattern.set_gamma_b(1.0/adj_gamma_b.get_value());
242 gamma_pattern.refresh();
243 gamma_pattern.queue_draw();
247 Dialog_Setup::on_black_level_change()
249 gamma_pattern.set_black_level(black_level_selector.get_value());
250 gamma_pattern.refresh();
251 gamma_pattern.queue_draw();
255 Dialog_Setup::on_red_blue_level_change()
257 gamma_pattern.set_red_blue_level(red_blue_level_selector.get_value());
258 gamma_pattern.refresh();
259 gamma_pattern.queue_draw();
264 Dialog_Setup::refresh()
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());
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());
280 gamma_pattern.refresh();
282 adj_recent_files.set_value(App::get_max_recent_files());
284 // Refresh the time format
285 set_time_format(App::get_time_format());
287 widget_enum->set_value(App::distance_system);
289 // Refresh the status of the use_colorspace_gamma flag
290 toggle_use_colorspace_gamma.set_active(App::use_colorspace_gamma);
292 // Refresh the status of the single_threaded flag
293 toggle_single_threaded.set_active(App::single_threaded);
296 GammaPattern::GammaPattern():
300 set_size_request(tile_w*4,tile_h*3);
301 signal_expose_event().connect(sigc::mem_fun(*this, &studio::GammaPattern::redraw));
304 GammaPattern::~GammaPattern()
309 GammaPattern::refresh()
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);
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);
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());
352 GammaPattern::redraw(GdkEventExpose */*bleh*/)
354 static const char hlines[] = { 3, 0 };
356 Glib::RefPtr<Gdk::GC> gc(Gdk::GC::create(get_window()));
359 Gdk::Color trueblack("#000000");
364 gc->set_rgb_fg_color(black[i]);
365 get_window()->draw_rectangle(gc, true, i*tile_w, 0, tile_w, tile_h);
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);
372 gc->set_fill(Gdk::SOLID);
373 gc->set_rgb_fg_color(gray50[i]);
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);
381 gc->set_rgb_fg_color(black[i]);
382 get_window()->draw_rectangle(gc, true, i*tile_w, tile_h, tile_w, tile_h);
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);
389 gc->set_fill(Gdk::SOLID);
390 gc->set_rgb_fg_color(gray25[i]);
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);
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);
401 gc->set_rgb_fg_color(black[i]);
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);
410 BlackLevelSelector::BlackLevelSelector()
412 set_size_request(-1,24);
413 signal_expose_event().connect(sigc::mem_fun(*this, &studio::BlackLevelSelector::redraw));
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);
420 BlackLevelSelector::~BlackLevelSelector()
425 BlackLevelSelector::redraw(GdkEventExpose */*bleh*/)
427 const int w(get_width()),h(get_height());
431 Glib::RefPtr<Gdk::GC> gc(Gdk::GC::create(get_window()));
438 color.set_rgb(i*65536/w,i*65536/w,i*65536/w);
440 gc->set_rgb_fg_color(color);
441 get_window()->draw_rectangle(gc, true, i, 0, 1, h);
445 gc->set_rgb_fg_color(Gdk::Color("#000000"));
446 get_window()->draw_rectangle(gc, false, 0, 0, w-1, h-1);
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);
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);
466 BlackLevelSelector::on_event(GdkEvent *event)
468 int x(round_to_int(event->button.x));
469 //int y(round_to_int(event->button.y));
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_();
481 case GDK_BUTTON_PRESS:
482 case GDK_BUTTON_RELEASE:
483 if(event->button.button==1)
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_();
502 Dialog_Setup::set_time_format(Time::Format x)
505 if(x<=Time::FORMAT_VIDEO)
506 timestamp_optionmenu.set_history(0);
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);
516 timestamp_optionmenu.set_history(1);
535 RedBlueLevelSelector::RedBlueLevelSelector()
537 set_size_request(-1,24);
538 signal_expose_event().connect(sigc::mem_fun(*this, &studio::RedBlueLevelSelector::redraw));
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);
545 RedBlueLevelSelector::~RedBlueLevelSelector()
550 RedBlueLevelSelector::redraw(GdkEventExpose */*bleh*/)
552 const int w(get_width()),h(get_height());
556 Glib::RefPtr<Gdk::GC> gc(Gdk::GC::create(get_window()));
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;
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)
574 gc->set_rgb_fg_color(color);
575 get_window()->draw_rectangle(gc, true, i, 0, 1, h);
579 gc->set_rgb_fg_color(Gdk::Color("#000000"));
580 get_window()->draw_rectangle(gc, false, 0, 0, w-1, h-1);
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);
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);
600 RedBlueLevelSelector::on_event(GdkEvent *event)
602 int x(round_to_int(event->button.x));
603 //int y(round_to_int(event->button.y));
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_();
615 case GDK_BUTTON_PRESS:
616 case GDK_BUTTON_RELEASE:
617 if(event->button.button==1)
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_();