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>
48 /* === U S I N G =========================================================== */
52 using namespace synfig;
53 using namespace studio;
55 /* === M A C R O S ========================================================= */
57 /* === G L O B A L S ======================================================= */
59 /* === P R O C E D U R E S ================================================= */
61 /* === M E T H O D S ======================================================= */
63 Dialog_Setup::Dialog_Setup():
64 Dialog(_("Synfig Studio Setup"),false,true),
65 adj_gamma_r(2.2,0.1,3.0,0.025,0.025,0.025),
66 adj_gamma_g(2.2,0.1,3.0,0.025,0.025,0.025),
67 adj_gamma_b(2.2,0.1,3.0,0.025,0.025,0.025),
68 adj_recent_files(15,1,50,1,1,1),
69 adj_undo_depth(100,10,5000,1,1,1),
70 toggle_use_colorspace_gamma(_("Visually Linear Color Selection")),
71 toggle_single_threaded(_("Use Only a Single Thread"))
75 Gtk::Button *ok_button(manage(new class Gtk::Button(Gtk::StockID("gtk-ok"))));
77 add_action_widget(*ok_button,2);
78 ok_button->signal_clicked().connect(sigc::mem_fun(*this, &Dialog_Setup::on_ok_pressed));
80 Gtk::Button *apply_button(manage(new class Gtk::Button(Gtk::StockID("gtk-apply"))));
82 add_action_widget(*apply_button,1);
83 apply_button->signal_clicked().connect(sigc::mem_fun(*this, &Dialog_Setup::on_apply_pressed));
85 Gtk::Button *cancel_button(manage(new class Gtk::Button(Gtk::StockID("gtk-close"))));
86 cancel_button->show();
87 add_action_widget(*cancel_button,0);
88 cancel_button->signal_clicked().connect(sigc::mem_fun(*this, &Dialog_Setup::hide));
92 Gtk::Notebook *notebook=manage(new class Gtk::Notebook());
93 get_vbox()->pack_start(*notebook);
97 Gtk::Table *gamma_table=manage(new Gtk::Table(2,2,false));
98 notebook->append_page(*gamma_table,_("Gamma"));
99 //gamma_frame->add(*gamma_table);
101 gamma_table->attach(gamma_pattern, 0, 2, 0, 1, Gtk::EXPAND, Gtk::SHRINK|Gtk::FILL, 0, 0);
103 Gtk::HScale* scale_gamma_r(manage(new Gtk::HScale(adj_gamma_r)));
104 gamma_table->attach(*manage(new Gtk::Label(_("Red"))), 0, 1, 1, 2, Gtk::SHRINK|Gtk::FILL, Gtk::SHRINK|Gtk::FILL, 0, 0);
105 gamma_table->attach(*scale_gamma_r, 1, 2, 1, 2, Gtk::EXPAND|Gtk::FILL, Gtk::SHRINK|Gtk::FILL, 0, 0);
106 adj_gamma_r.signal_value_changed().connect(sigc::mem_fun(*this,&studio::Dialog_Setup::on_gamma_r_change));
108 Gtk::HScale* scale_gamma_g(manage(new Gtk::HScale(adj_gamma_g)));
109 gamma_table->attach(*manage(new Gtk::Label(_("Green"))), 0, 1, 2, 3, Gtk::SHRINK|Gtk::FILL, Gtk::SHRINK|Gtk::FILL, 0, 0);
110 gamma_table->attach(*scale_gamma_g, 1, 2, 2, 3, Gtk::EXPAND|Gtk::FILL, Gtk::SHRINK|Gtk::FILL, 0, 0);
111 adj_gamma_g.signal_value_changed().connect(sigc::mem_fun(*this,&studio::Dialog_Setup::on_gamma_g_change));
113 Gtk::HScale* scale_gamma_b(manage(new Gtk::HScale(adj_gamma_b)));
114 gamma_table->attach(*manage(new Gtk::Label(_("Blue"))), 0, 1, 3, 4, Gtk::SHRINK|Gtk::FILL, Gtk::SHRINK|Gtk::FILL, 0, 0);
115 gamma_table->attach(*scale_gamma_b, 1, 2, 3, 4, Gtk::EXPAND|Gtk::FILL, Gtk::SHRINK|Gtk::FILL, 0, 0);
116 adj_gamma_b.signal_value_changed().connect(sigc::mem_fun(*this,&studio::Dialog_Setup::on_gamma_b_change));
118 gamma_table->attach(*manage(new Gtk::Label(_("Black Level"))), 0, 1, 4, 5, Gtk::SHRINK|Gtk::FILL, Gtk::SHRINK|Gtk::FILL, 0, 0);
119 gamma_table->attach(black_level_selector, 1, 2, 4, 5, Gtk::EXPAND|Gtk::FILL, Gtk::SHRINK|Gtk::FILL, 0, 0);
120 black_level_selector.signal_value_changed().connect(sigc::mem_fun(*this,&studio::Dialog_Setup::on_black_level_change));
122 //gamma_table->attach(*manage(new Gtk::Label(_("Red-Blue Level"))), 0, 1, 5, 6, Gtk::SHRINK|Gtk::FILL, Gtk::SHRINK|Gtk::FILL, 0, 0);
123 //gamma_table->attach(red_blue_level_selector, 1, 2, 5, 6, Gtk::EXPAND|Gtk::FILL, Gtk::SHRINK|Gtk::FILL, 0, 0);
124 //red_blue_level_selector.signal_value_changed().connect(sigc::mem_fun(*this,&studio::Dialog_Setup::on_red_blue_level_change));
128 Gtk::Table *misc_table=manage(new Gtk::Table(2,2,false));
129 notebook->append_page(*misc_table,_("Misc."));
132 timestamp_menu=manage(new class Gtk::Menu());
133 misc_table->attach(*manage(new Gtk::Label(_("Timestamp"))), 0, 1, 0, 1, Gtk::SHRINK|Gtk::FILL, Gtk::SHRINK|Gtk::FILL, 0, 0);
134 misc_table->attach(timestamp_optionmenu, 1, 2, 0, 1, Gtk::EXPAND|Gtk::FILL, Gtk::SHRINK|Gtk::FILL, 0, 0);
136 #define ADD_TIMESTAMP(desc,x) \
137 timestamp_menu->items().push_back( \
138 Gtk::Menu_Helpers::MenuElem( \
143 &studio::Dialog_Setup::set_time_format \
149 ADD_TIMESTAMP("HH:MM:SS.FF",Time::FORMAT_VIDEO);
150 ADD_TIMESTAMP("(HHh MMm SSs) FFf",Time::FORMAT_NORMAL);
151 ADD_TIMESTAMP("(HHhMMmSSs)FFf",Time::FORMAT_NORMAL|Time::FORMAT_NOSPACES);
152 ADD_TIMESTAMP("HHh MMm SSs FFf",Time::FORMAT_NORMAL|Time::FORMAT_FULL);
153 ADD_TIMESTAMP("HHhMMmSSsFFf",Time::FORMAT_NORMAL|Time::FORMAT_NOSPACES|Time::FORMAT_FULL);
155 timestamp_optionmenu.set_menu(*timestamp_menu);
160 ParamDesc param_desc;
163 .add_enum_value(Distance::SYSTEM_UNITS,"u",_("Units"))
164 .add_enum_value(Distance::SYSTEM_PIXELS,"px",_("Pixels"))
165 .add_enum_value(Distance::SYSTEM_POINTS,"pt",_("Points"))
166 .add_enum_value(Distance::SYSTEM_INCHES,"in",_("Inches"))
167 .add_enum_value(Distance::SYSTEM_METERS,"m",_("Meters"))
168 .add_enum_value(Distance::SYSTEM_CENTIMETERS,"cm",_("Centimeters"))
169 .add_enum_value(Distance::SYSTEM_MILLIMETERS,"mm",_("Millimeters"));
171 widget_enum=manage(new Widget_Enum());
172 widget_enum->set_param_desc(param_desc);
174 misc_table->attach(*manage(new Gtk::Label(_("Unit System"))), 0, 1, 3, 4, Gtk::SHRINK|Gtk::FILL, Gtk::SHRINK|Gtk::FILL, 0, 0);
175 misc_table->attach(*widget_enum, 1, 2, 3, 4, Gtk::EXPAND|Gtk::FILL, Gtk::SHRINK|Gtk::FILL, 0, 0);
178 // Misc - recent files
179 Gtk::SpinButton* recent_files_spinbutton(manage(new Gtk::SpinButton(adj_recent_files,1,0)));
180 misc_table->attach(*manage(new Gtk::Label(_("Recent Files"))), 0, 1, 1, 2, Gtk::SHRINK|Gtk::FILL, Gtk::SHRINK|Gtk::FILL, 0, 0);
181 misc_table->attach(*recent_files_spinbutton, 1, 2, 1, 2, Gtk::EXPAND|Gtk::FILL, Gtk::SHRINK|Gtk::FILL, 0, 0);
183 // Misc - use_colorspace_gamma
184 misc_table->attach(toggle_use_colorspace_gamma, 0, 2, 2, 3, Gtk::EXPAND|Gtk::FILL, Gtk::SHRINK|Gtk::FILL, 0, 0);
186 // Misc - single_threaded
187 misc_table->attach(toggle_single_threaded, 0, 2, 4, 5, Gtk::EXPAND|Gtk::FILL, Gtk::SHRINK|Gtk::FILL, 0, 0);
192 Dialog_Setup::~Dialog_Setup()
197 Dialog_Setup::on_ok_pressed()
204 Dialog_Setup::on_apply_pressed()
206 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());
208 App::set_max_recent_files((int)adj_recent_files.get_value());
210 // Set the time format
211 App::set_time_format(get_time_format());
213 // Set the use_colorspace_gamma flag
214 App::use_colorspace_gamma=toggle_use_colorspace_gamma.get_active();
216 // Set the single_threaded flag
217 App::single_threaded=toggle_single_threaded.get_active();
219 App::distance_system=Distance::System(widget_enum->get_value());
221 App::save_settings();
225 Dialog_Setup::on_gamma_r_change()
227 gamma_pattern.set_gamma_r(1.0/adj_gamma_r.get_value());
228 gamma_pattern.refresh();
229 gamma_pattern.queue_draw();
233 Dialog_Setup::on_gamma_g_change()
235 gamma_pattern.set_gamma_g(1.0/adj_gamma_g.get_value());
236 gamma_pattern.refresh();
237 gamma_pattern.queue_draw();
241 Dialog_Setup::on_gamma_b_change()
243 gamma_pattern.set_gamma_b(1.0/adj_gamma_b.get_value());
244 gamma_pattern.refresh();
245 gamma_pattern.queue_draw();
249 Dialog_Setup::on_black_level_change()
251 gamma_pattern.set_black_level(black_level_selector.get_value());
252 gamma_pattern.refresh();
253 gamma_pattern.queue_draw();
257 Dialog_Setup::on_red_blue_level_change()
259 gamma_pattern.set_red_blue_level(red_blue_level_selector.get_value());
260 gamma_pattern.refresh();
261 gamma_pattern.queue_draw();
266 Dialog_Setup::refresh()
268 // Refresh the temporary gamma; do this before adjusting the sliders,
269 // or variables will be used before their initialization.
270 gamma_pattern.set_gamma_r(App::gamma.get_gamma_r());
271 gamma_pattern.set_gamma_g(App::gamma.get_gamma_g());
272 gamma_pattern.set_gamma_b(App::gamma.get_gamma_b());
273 gamma_pattern.set_black_level(App::gamma.get_black_level());
274 gamma_pattern.set_red_blue_level(App::gamma.get_red_blue_level());
276 adj_gamma_r.set_value(1.0/App::gamma.get_gamma_r());
277 adj_gamma_g.set_value(1.0/App::gamma.get_gamma_g());
278 adj_gamma_b.set_value(1.0/App::gamma.get_gamma_b());
279 black_level_selector.set_value(App::gamma.get_black_level());
280 red_blue_level_selector.set_value(App::gamma.get_red_blue_level());
282 gamma_pattern.refresh();
284 adj_recent_files.set_value(App::get_max_recent_files());
286 // Refresh the time format
287 set_time_format(App::get_time_format());
289 widget_enum->set_value(App::distance_system);
291 // Refresh the status of the use_colorspace_gamma flag
292 toggle_use_colorspace_gamma.set_active(App::use_colorspace_gamma);
294 // Refresh the status of the single_threaded flag
295 toggle_single_threaded.set_active(App::single_threaded);
298 GammaPattern::GammaPattern():
302 set_size_request(tile_w*4,tile_h*3);
303 signal_expose_event().connect(sigc::mem_fun(*this, &studio::GammaPattern::redraw));
306 GammaPattern::~GammaPattern()
311 GammaPattern::refresh()
335 black[1].set_rgb(black[0].get_red(),0,0);
336 gray25[1].set_rgb(gray25[0].get_red(),0,0);
337 gray50[1].set_rgb(gray50[0].get_red(),0,0);
338 white[1].set_rgb(white[0].get_red(),0,0);
341 black[2].set_rgb(0,black[0].get_green(),0);
342 gray25[2].set_rgb(0,gray25[0].get_green(),0);
343 gray50[2].set_rgb(0,gray50[0].get_green(),0);
344 white[2].set_rgb(0,white[0].get_green(),0);
347 black[3].set_rgb(0,0,black[0].get_blue());
348 gray25[3].set_rgb(0,0,gray25[0].get_blue());
349 gray50[3].set_rgb(0,0,gray50[0].get_blue());
350 white[3].set_rgb(0,0,white[0].get_blue());
354 GammaPattern::redraw(GdkEventExpose */*bleh*/)
356 static const char hlines[] = { 3, 0 };
358 Glib::RefPtr<Gdk::GC> gc(Gdk::GC::create(get_window()));
361 Gdk::Color trueblack("#000000");
366 gc->set_rgb_fg_color(black[i]);
367 get_window()->draw_rectangle(gc, true, i*tile_w, 0, tile_w, tile_h);
369 gc->set_stipple(Gdk::Bitmap::create(hlines,2,2));
370 gc->set_fill(Gdk::STIPPLED);
371 gc->set_rgb_fg_color(white[i]);
372 get_window()->draw_rectangle(gc, true, i*tile_w, 0, tile_w, tile_h);
374 gc->set_fill(Gdk::SOLID);
375 gc->set_rgb_fg_color(gray50[i]);
377 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);
383 gc->set_rgb_fg_color(black[i]);
384 get_window()->draw_rectangle(gc, true, i*tile_w, tile_h, tile_w, tile_h);
386 gc->set_stipple(Gdk::Bitmap::create(hlines,2,2));
387 gc->set_fill(Gdk::STIPPLED);
388 gc->set_rgb_fg_color(gray50[i]);
389 get_window()->draw_rectangle(gc, true, i*tile_w, tile_h, tile_w, tile_h);
391 gc->set_fill(Gdk::SOLID);
392 gc->set_rgb_fg_color(gray25[i]);
394 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);
397 // Black-level Pattern
398 gc->set_rgb_fg_color(trueblack);
399 get_window()->draw_rectangle(gc, true, 0, tile_h*2, tile_w*4, tile_h);
400 gc->set_fill(Gdk::SOLID);
403 gc->set_rgb_fg_color(black[i]);
405 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);
412 BlackLevelSelector::BlackLevelSelector()
414 set_size_request(-1,24);
415 signal_expose_event().connect(sigc::mem_fun(*this, &studio::BlackLevelSelector::redraw));
417 add_events(Gdk::BUTTON_PRESS_MASK | Gdk::BUTTON_RELEASE_MASK);
418 add_events(Gdk::BUTTON1_MOTION_MASK);
419 add_events(Gdk::BUTTON1_MOTION_MASK);
422 BlackLevelSelector::~BlackLevelSelector()
427 BlackLevelSelector::redraw(GdkEventExpose */*bleh*/)
429 const int w(get_width()),h(get_height());
433 Glib::RefPtr<Gdk::GC> gc(Gdk::GC::create(get_window()));
440 color.set_rgb(i*65536/w,i*65536/w,i*65536/w);
442 gc->set_rgb_fg_color(color);
443 get_window()->draw_rectangle(gc, true, i, 0, 1, h);
447 gc->set_rgb_fg_color(Gdk::Color("#000000"));
448 get_window()->draw_rectangle(gc, false, 0, 0, w-1, h-1);
450 // Draw the position of the current value
451 i=(int)(level*w+0.5);
452 gc->set_rgb_fg_color(Gdk::Color("#ff0000"));
453 get_window()->draw_rectangle(gc, true, i, 1, 1, h-1);
455 // Print out the value
456 Glib::RefPtr<Pango::Layout> layout(Pango::Layout::create(get_pango_context()));
457 layout->set_text(etl::strprintf("%0.01f%%",level*100.0f));
458 layout->set_alignment(Pango::ALIGN_CENTER);
459 gc->set_rgb_fg_color(Gdk::Color("#a00000"));
460 get_window()->draw_layout(gc, w/2, 4, layout);
468 BlackLevelSelector::on_event(GdkEvent *event)
470 int x(round_to_int(event->button.x));
471 //int y(round_to_int(event->button.y));
475 case GDK_MOTION_NOTIFY:
476 level=(float)x/(float)get_width();
477 if(level<0.0f)level=0.0f;
478 if(level>1.0f)level=1.0f;
479 signal_value_changed_();
483 case GDK_BUTTON_PRESS:
484 case GDK_BUTTON_RELEASE:
485 if(event->button.button==1)
487 level=(float)x/(float)get_width();
488 if(level<0.0f)level=0.0f;
489 if(level>1.0f)level=1.0f;
490 signal_value_changed_();
504 Dialog_Setup::set_time_format(synfig::Time::Format x)
507 if(x<=Time::FORMAT_VIDEO)
508 timestamp_optionmenu.set_history(0);
511 if(x==(Time::FORMAT_NOSPACES|Time::FORMAT_FULL))
512 timestamp_optionmenu.set_history(4);
513 else if(x==(Time::FORMAT_FULL))
514 timestamp_optionmenu.set_history(3);
515 else if(x==(Time::FORMAT_NOSPACES))
516 timestamp_optionmenu.set_history(2);
518 timestamp_optionmenu.set_history(1);
537 RedBlueLevelSelector::RedBlueLevelSelector()
539 set_size_request(-1,24);
540 signal_expose_event().connect(sigc::mem_fun(*this, &studio::RedBlueLevelSelector::redraw));
542 add_events(Gdk::BUTTON_PRESS_MASK | Gdk::BUTTON_RELEASE_MASK);
543 add_events(Gdk::BUTTON1_MOTION_MASK);
544 add_events(Gdk::BUTTON1_MOTION_MASK);
547 RedBlueLevelSelector::~RedBlueLevelSelector()
552 RedBlueLevelSelector::redraw(GdkEventExpose */*bleh*/)
554 const int w(get_width()),h(get_height());
558 Glib::RefPtr<Gdk::GC> gc(Gdk::GC::create(get_window()));
565 float red_blue(((float(i)/float(w)+0.5f)-1.0f)/2.0f+1.0f);
566 float blue_red(2.0f-(red_blue));
567 if(red_blue>1.0f)red_blue=1.0f;
568 if(blue_red>1.0f)blue_red=1.0f;
571 round_to_int(min(red_blue,1.0f)*65535),
572 round_to_int(sqrt(min(red_blue,blue_red))*65535),
573 round_to_int(min(blue_red,1.0f)*65535)
576 gc->set_rgb_fg_color(color);
577 get_window()->draw_rectangle(gc, true, i, 0, 1, h);
581 gc->set_rgb_fg_color(Gdk::Color("#000000"));
582 get_window()->draw_rectangle(gc, false, 0, 0, w-1, h-1);
584 // Draw the position of the current value
585 i=(int)(((level-1.0f)*2.0f+1.0f-0.5f)*w+0.5);
586 gc->set_rgb_fg_color(Gdk::Color("#00ff00"));
587 get_window()->draw_rectangle(gc, true, i, 1, 1, h-1);
589 // Print out the value
590 Glib::RefPtr<Pango::Layout> layout(Pango::Layout::create(get_pango_context()));
591 layout->set_text(etl::strprintf("%0.02f",level));
592 layout->set_alignment(Pango::ALIGN_CENTER);
593 gc->set_rgb_fg_color(Gdk::Color("#a00000"));
594 get_window()->draw_layout(gc, w/2, 4, layout);
602 RedBlueLevelSelector::on_event(GdkEvent *event)
604 int x(round_to_int(event->button.x));
605 //int y(round_to_int(event->button.y));
609 case GDK_MOTION_NOTIFY:
610 level=(((float)(x)/(float)get_width()+0.5)-1.0f)/2.0f+1.0f;
611 if(level<0.5f)level=0.5f;
612 if(level>1.5f)level=1.5f;
613 signal_value_changed_();
617 case GDK_BUTTON_PRESS:
618 case GDK_BUTTON_RELEASE:
619 if(event->button.button==1)
621 level=(((float)(x)/(float)get_width()+0.5)-1.0f)/2.0f+1.0f;
622 if(level<0.5f)level=0.5f;
623 if(level>1.5f)level=1.5f;
624 signal_value_changed_();