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, 2008 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"
41 #include "autorecover.h"
43 #include <ETL/stringf>
49 /* === U S I N G =========================================================== */
53 using namespace synfig;
54 using namespace studio;
56 /* === M A C R O S ========================================================= */
58 /* === G L O B A L S ======================================================= */
60 /* === P R O C E D U R E S ================================================= */
62 /* === M E T H O D S ======================================================= */
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"))
77 Gtk::Button *ok_button(manage(new class Gtk::Button(Gtk::StockID("gtk-ok"))));
79 add_action_widget(*ok_button,2);
80 ok_button->signal_clicked().connect(sigc::mem_fun(*this, &Dialog_Setup::on_ok_pressed));
82 Gtk::Button *apply_button(manage(new class Gtk::Button(Gtk::StockID("gtk-apply"))));
84 add_action_widget(*apply_button,1);
85 apply_button->signal_clicked().connect(sigc::mem_fun(*this, &Dialog_Setup::on_apply_pressed));
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));
94 Gtk::Notebook *notebook=manage(new class Gtk::Notebook());
95 get_vbox()->pack_start(*notebook);
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);
103 gamma_table->attach(gamma_pattern, 0, 2, 0, 1, Gtk::EXPAND, Gtk::SHRINK|Gtk::FILL, 0, 0);
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));
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));
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));
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));
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));
130 Gtk::Table *misc_table=manage(new Gtk::Table(2,2,false));
131 notebook->append_page(*misc_table,_("Misc."));
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);
138 #define ADD_TIMESTAMP(desc,x) \
139 timestamp_menu->items().push_back( \
140 Gtk::Menu_Helpers::MenuElem( \
145 &studio::Dialog_Setup::set_time_format \
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);
157 timestamp_optionmenu.set_menu(*timestamp_menu);
162 ParamDesc param_desc;
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"));
173 widget_enum=manage(new Widget_Enum());
174 widget_enum->set_param_desc(param_desc);
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);
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);
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);
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);
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);
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);
201 Dialog_Setup::~Dialog_Setup()
206 Dialog_Setup::on_ok_pressed()
213 Dialog_Setup::on_apply_pressed()
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());
217 App::set_max_recent_files((int)adj_recent_files.get_value());
219 // Set the time format
220 App::set_time_format(get_time_format());
222 // Set the use_colorspace_gamma flag
223 App::use_colorspace_gamma=toggle_use_colorspace_gamma.get_active();
225 // Set the single_threaded flag
226 App::single_threaded=toggle_single_threaded.get_active();
228 // Set the auto backup interval
229 App::auto_recover->set_timeout(auto_backup_interval.get_value() * 1000);
231 App::distance_system=Distance::System(widget_enum->get_value());
233 // Set the restrict_radius_ducks flag
234 App::restrict_radius_ducks=toggle_restrict_radius_ducks.get_active();
236 App::save_settings();
240 Dialog_Setup::on_gamma_r_change()
242 gamma_pattern.set_gamma_r(1.0/adj_gamma_r.get_value());
243 gamma_pattern.refresh();
244 gamma_pattern.queue_draw();
248 Dialog_Setup::on_gamma_g_change()
250 gamma_pattern.set_gamma_g(1.0/adj_gamma_g.get_value());
251 gamma_pattern.refresh();
252 gamma_pattern.queue_draw();
256 Dialog_Setup::on_gamma_b_change()
258 gamma_pattern.set_gamma_b(1.0/adj_gamma_b.get_value());
259 gamma_pattern.refresh();
260 gamma_pattern.queue_draw();
264 Dialog_Setup::on_black_level_change()
266 gamma_pattern.set_black_level(black_level_selector.get_value());
267 gamma_pattern.refresh();
268 gamma_pattern.queue_draw();
272 Dialog_Setup::on_red_blue_level_change()
274 gamma_pattern.set_red_blue_level(red_blue_level_selector.get_value());
275 gamma_pattern.refresh();
276 gamma_pattern.queue_draw();
281 Dialog_Setup::refresh()
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());
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());
297 gamma_pattern.refresh();
299 adj_recent_files.set_value(App::get_max_recent_files());
301 // Refresh the time format
302 set_time_format(App::get_time_format());
304 widget_enum->set_value(App::distance_system);
306 // Refresh the status of the use_colorspace_gamma flag
307 toggle_use_colorspace_gamma.set_active(App::use_colorspace_gamma);
309 // Refresh the status of the single_threaded flag
310 toggle_single_threaded.set_active(App::single_threaded);
312 // Refresh the value of the auto backup interval
313 auto_backup_interval.set_value(App::auto_recover->get_timeout() / 1000);
315 // Refresh the status of the restrict_radius_ducks flag
316 toggle_restrict_radius_ducks.set_active(App::restrict_radius_ducks);
319 GammaPattern::GammaPattern():
323 set_size_request(tile_w*4,tile_h*3);
324 signal_expose_event().connect(sigc::mem_fun(*this, &studio::GammaPattern::redraw));
327 GammaPattern::~GammaPattern()
332 GammaPattern::refresh()
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);
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);
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());
375 GammaPattern::redraw(GdkEventExpose */*bleh*/)
377 static const char hlines[] = { 3, 0 };
379 Glib::RefPtr<Gdk::GC> gc(Gdk::GC::create(get_window()));
382 Gdk::Color trueblack("#000000");
387 gc->set_rgb_fg_color(black[i]);
388 get_window()->draw_rectangle(gc, true, i*tile_w, 0, tile_w, tile_h);
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);
395 gc->set_fill(Gdk::SOLID);
396 gc->set_rgb_fg_color(gray50[i]);
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);
404 gc->set_rgb_fg_color(black[i]);
405 get_window()->draw_rectangle(gc, true, i*tile_w, tile_h, tile_w, tile_h);
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);
412 gc->set_fill(Gdk::SOLID);
413 gc->set_rgb_fg_color(gray25[i]);
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);
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);
424 gc->set_rgb_fg_color(black[i]);
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);
433 BlackLevelSelector::BlackLevelSelector()
435 set_size_request(-1,24);
436 signal_expose_event().connect(sigc::mem_fun(*this, &studio::BlackLevelSelector::redraw));
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);
443 BlackLevelSelector::~BlackLevelSelector()
448 BlackLevelSelector::redraw(GdkEventExpose */*bleh*/)
450 const int w(get_width()),h(get_height());
454 Glib::RefPtr<Gdk::GC> gc(Gdk::GC::create(get_window()));
461 color.set_rgb(i*65536/w,i*65536/w,i*65536/w);
463 gc->set_rgb_fg_color(color);
464 get_window()->draw_rectangle(gc, true, i, 0, 1, h);
468 gc->set_rgb_fg_color(Gdk::Color("#000000"));
469 get_window()->draw_rectangle(gc, false, 0, 0, w-1, h-1);
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);
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);
489 BlackLevelSelector::on_event(GdkEvent *event)
491 int x(round_to_int(event->button.x));
492 //int y(round_to_int(event->button.y));
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_();
504 case GDK_BUTTON_PRESS:
505 case GDK_BUTTON_RELEASE:
506 if(event->button.button==1)
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_();
525 Dialog_Setup::set_time_format(synfig::Time::Format x)
528 if(x<=Time::FORMAT_VIDEO)
529 timestamp_optionmenu.set_history(0);
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);
539 timestamp_optionmenu.set_history(1);
558 RedBlueLevelSelector::RedBlueLevelSelector()
560 set_size_request(-1,24);
561 signal_expose_event().connect(sigc::mem_fun(*this, &studio::RedBlueLevelSelector::redraw));
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);
568 RedBlueLevelSelector::~RedBlueLevelSelector()
573 RedBlueLevelSelector::redraw(GdkEventExpose */*bleh*/)
575 const int w(get_width()),h(get_height());
579 Glib::RefPtr<Gdk::GC> gc(Gdk::GC::create(get_window()));
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;
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)
597 gc->set_rgb_fg_color(color);
598 get_window()->draw_rectangle(gc, true, i, 0, 1, h);
602 gc->set_rgb_fg_color(Gdk::Color("#000000"));
603 get_window()->draw_rectangle(gc, false, 0, 0, w-1, h-1);
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);
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);
623 RedBlueLevelSelector::on_event(GdkEvent *event)
625 int x(round_to_int(event->button.x));
626 //int y(round_to_int(event->button.y));
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_();
638 case GDK_BUTTON_PRESS:
639 case GDK_BUTTON_RELEASE:
640 if(event->button.button==1)
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_();