1 /* === S Y N F I G ========================================================= */
2 /*! \file dialog_setup.cpp
3 ** \brief Template File
5 ** $Id: dialog_setup.cpp,v 1.1.1.1 2005/01/07 03:34:36 darco Exp $
8 ** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
10 ** This package is free software; you can redistribute it and/or
11 ** modify it under the terms of the GNU General Public License as
12 ** published by the Free Software Foundation; either version 2 of
13 ** the License, or (at your option) any later version.
15 ** This package is distributed in the hope that it will be useful,
16 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 ** General Public License for more details.
21 /* ========================================================================= */
23 /* === H E A D E R S ======================================================= */
32 #include "dialog_setup.h"
34 #include <gtkmm/scale.h>
35 #include <gtkmm/table.h>
36 #include <gtkmm/frame.h>
37 #include <gtkmm/notebook.h>
38 #include <gtkmm/spinbutton.h>
39 #include "widget_enum.h"
41 #include <ETL/stringf>
45 /* === U S I N G =========================================================== */
49 using namespace synfig;
50 using namespace studio;
52 /* === M A C R O S ========================================================= */
54 /* === G L O B A L S ======================================================= */
56 /* === P R O C E D U R E S ================================================= */
58 /* === M E T H O D S ======================================================= */
60 Dialog_Setup::Dialog_Setup():
61 Dialog(_("SYNFIG Studio Setup"),false,true),
62 adj_gamma_r(2.2,0.1,3.0,0.025,0.025,0.025),
63 adj_gamma_g(2.2,0.1,3.0,0.025,0.025,0.025),
64 adj_gamma_b(2.2,0.1,3.0,0.025,0.025,0.025),
65 adj_recent_files(15,1,50,1,1,1),
66 adj_undo_depth(100,10,5000,1,1,1),
67 toggle_use_colorspace_gamma(_("Visually Linear Color Selection"))
71 Gtk::Button *ok_button(manage(new class Gtk::Button(Gtk::StockID("gtk-ok"))));
73 add_action_widget(*ok_button,2);
74 ok_button->signal_clicked().connect(sigc::mem_fun(*this, &Dialog_Setup::on_ok_pressed));
76 Gtk::Button *apply_button(manage(new class Gtk::Button(Gtk::StockID("gtk-apply"))));
78 add_action_widget(*apply_button,1);
79 apply_button->signal_clicked().connect(sigc::mem_fun(*this, &Dialog_Setup::on_apply_pressed));
81 Gtk::Button *cancel_button(manage(new class Gtk::Button(Gtk::StockID("gtk-close"))));
82 cancel_button->show();
83 add_action_widget(*cancel_button,0);
84 cancel_button->signal_clicked().connect(sigc::mem_fun(*this, &Dialog_Setup::hide));
88 Gtk::Notebook *notebook=manage(new class Gtk::Notebook());
89 get_vbox()->pack_start(*notebook);
93 Gtk::Table *gamma_table=manage(new Gtk::Table(2,2,false));
94 notebook->append_page(*gamma_table,_("Gamma"));
95 //gamma_frame->add(*gamma_table);
97 gamma_table->attach(gamma_pattern, 0, 2, 0, 1, Gtk::EXPAND, Gtk::SHRINK|Gtk::FILL, 0, 0);
99 Gtk::HScale* scale_gamma_r(manage(new Gtk::HScale(adj_gamma_r)));
100 gamma_table->attach(*manage(new Gtk::Label(_("Red"))), 0, 1, 1, 2, Gtk::SHRINK|Gtk::FILL, Gtk::SHRINK|Gtk::FILL, 0, 0);
101 gamma_table->attach(*scale_gamma_r, 1, 2, 1, 2, Gtk::EXPAND|Gtk::FILL, Gtk::SHRINK|Gtk::FILL, 0, 0);
102 adj_gamma_r.signal_value_changed().connect(sigc::mem_fun(*this,&studio::Dialog_Setup::on_gamma_r_change));
104 Gtk::HScale* scale_gamma_g(manage(new Gtk::HScale(adj_gamma_g)));
105 gamma_table->attach(*manage(new Gtk::Label(_("Green"))), 0, 1, 2, 3, Gtk::SHRINK|Gtk::FILL, Gtk::SHRINK|Gtk::FILL, 0, 0);
106 gamma_table->attach(*scale_gamma_g, 1, 2, 2, 3, Gtk::EXPAND|Gtk::FILL, Gtk::SHRINK|Gtk::FILL, 0, 0);
107 adj_gamma_g.signal_value_changed().connect(sigc::mem_fun(*this,&studio::Dialog_Setup::on_gamma_g_change));
109 Gtk::HScale* scale_gamma_b(manage(new Gtk::HScale(adj_gamma_b)));
110 gamma_table->attach(*manage(new Gtk::Label(_("Blue"))), 0, 1, 3, 4, Gtk::SHRINK|Gtk::FILL, Gtk::SHRINK|Gtk::FILL, 0, 0);
111 gamma_table->attach(*scale_gamma_b, 1, 2, 3, 4, Gtk::EXPAND|Gtk::FILL, Gtk::SHRINK|Gtk::FILL, 0, 0);
112 adj_gamma_b.signal_value_changed().connect(sigc::mem_fun(*this,&studio::Dialog_Setup::on_gamma_b_change));
114 gamma_table->attach(*manage(new Gtk::Label(_("Black Level"))), 0, 1, 4, 5, Gtk::SHRINK|Gtk::FILL, Gtk::SHRINK|Gtk::FILL, 0, 0);
115 gamma_table->attach(black_level_selector, 1, 2, 4, 5, Gtk::EXPAND|Gtk::FILL, Gtk::SHRINK|Gtk::FILL, 0, 0);
116 black_level_selector.signal_value_changed().connect(sigc::mem_fun(*this,&studio::Dialog_Setup::on_black_level_change));
118 //gamma_table->attach(*manage(new Gtk::Label(_("Red-Blue Level"))), 0, 1, 5, 6, Gtk::SHRINK|Gtk::FILL, Gtk::SHRINK|Gtk::FILL, 0, 0);
119 //gamma_table->attach(red_blue_level_selector, 1, 2, 5, 6, Gtk::EXPAND|Gtk::FILL, Gtk::SHRINK|Gtk::FILL, 0, 0);
120 //red_blue_level_selector.signal_value_changed().connect(sigc::mem_fun(*this,&studio::Dialog_Setup::on_red_blue_level_change));
124 Gtk::Table *misc_table=manage(new Gtk::Table(2,2,false));
125 notebook->append_page(*misc_table,_("Misc."));
128 timestamp_menu=manage(new class Gtk::Menu());
129 misc_table->attach(*manage(new Gtk::Label(_("Timestamp"))), 0, 1, 0, 1, Gtk::SHRINK|Gtk::FILL, Gtk::SHRINK|Gtk::FILL, 0, 0);
130 misc_table->attach(timestamp_optionmenu, 1, 2, 0, 1, Gtk::EXPAND|Gtk::FILL, Gtk::SHRINK|Gtk::FILL, 0, 0);
132 #define ADD_TIMESTAMP(desc,x) \
133 timestamp_menu->items().push_back( \
134 Gtk::Menu_Helpers::MenuElem( \
139 &studio::Dialog_Setup::set_time_format \
145 ADD_TIMESTAMP("HH:MM:SS.FF",Time::FORMAT_VIDEO);
146 ADD_TIMESTAMP("(HHh MMm SSs) FFf",Time::FORMAT_NORMAL);
147 ADD_TIMESTAMP("(HHhMMmSSs)FFf",Time::FORMAT_NORMAL|Time::FORMAT_NOSPACES);
148 ADD_TIMESTAMP("HHh MMm SSs FFf",Time::FORMAT_NORMAL|Time::FORMAT_FULL);
149 ADD_TIMESTAMP("HHhMMmSSsFFf",Time::FORMAT_NORMAL|Time::FORMAT_NOSPACES|Time::FORMAT_FULL);
151 timestamp_optionmenu.set_menu(*timestamp_menu);
156 ParamDesc param_desc;
159 .add_enum_value(Distance::SYSTEM_UNITS,"u",_("Units"))
160 .add_enum_value(Distance::SYSTEM_PIXELS,"px",_("Pixels"))
161 .add_enum_value(Distance::SYSTEM_POINTS,"pt",_("Points"))
162 .add_enum_value(Distance::SYSTEM_INCHES,"in",_("Inches"))
163 .add_enum_value(Distance::SYSTEM_METERS,"m",_("Meters"))
164 .add_enum_value(Distance::SYSTEM_CENTIMETERS,"cm",_("Centimeters"))
165 .add_enum_value(Distance::SYSTEM_MILLIMETERS,"mm",_("Millimeters"));
167 widget_enum=manage(new Widget_Enum());
168 widget_enum->set_param_desc(param_desc);
170 misc_table->attach(*manage(new Gtk::Label(_("Unit System"))), 0, 1, 3, 4, Gtk::SHRINK|Gtk::FILL, Gtk::SHRINK|Gtk::FILL, 0, 0);
171 misc_table->attach(*widget_enum, 1, 2, 3, 4, Gtk::EXPAND|Gtk::FILL, Gtk::SHRINK|Gtk::FILL, 0, 0);
174 // Misc - recent files
175 Gtk::SpinButton* recent_files_spinbutton(manage(new Gtk::SpinButton(adj_recent_files,1,0)));
176 misc_table->attach(*manage(new Gtk::Label(_("Recent Files"))), 0, 1, 1, 2, Gtk::SHRINK|Gtk::FILL, Gtk::SHRINK|Gtk::FILL, 0, 0);
177 misc_table->attach(*recent_files_spinbutton, 1, 2, 1, 2, Gtk::EXPAND|Gtk::FILL, Gtk::SHRINK|Gtk::FILL, 0, 0);
179 // Misc - use_colorspace_gamma
180 misc_table->attach(toggle_use_colorspace_gamma, 0, 2, 2, 3, Gtk::EXPAND|Gtk::FILL, Gtk::SHRINK|Gtk::FILL, 0, 0);
185 Dialog_Setup::~Dialog_Setup()
190 Dialog_Setup::on_ok_pressed()
197 Dialog_Setup::on_apply_pressed()
199 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());
201 App::set_max_recent_files((int)adj_recent_files.get_value());
203 // Set the time format
204 App::set_time_format(get_time_format());
206 // Set the use_colorspace_gamma flag
207 App::use_colorspace_gamma=toggle_use_colorspace_gamma.get_active();
209 App::distance_system=Distance::System(widget_enum->get_value());
211 App::save_settings();
215 Dialog_Setup::on_gamma_r_change()
217 gamma_pattern.set_gamma_r(1.0/adj_gamma_r.get_value());
218 gamma_pattern.refresh();
219 gamma_pattern.queue_draw();
223 Dialog_Setup::on_gamma_g_change()
225 gamma_pattern.set_gamma_g(1.0/adj_gamma_g.get_value());
226 gamma_pattern.refresh();
227 gamma_pattern.queue_draw();
231 Dialog_Setup::on_gamma_b_change()
233 gamma_pattern.set_gamma_b(1.0/adj_gamma_b.get_value());
234 gamma_pattern.refresh();
235 gamma_pattern.queue_draw();
239 Dialog_Setup::on_black_level_change()
241 gamma_pattern.set_black_level(black_level_selector.get_value());
242 gamma_pattern.refresh();
243 gamma_pattern.queue_draw();
247 Dialog_Setup::on_red_blue_level_change()
249 gamma_pattern.set_red_blue_level(red_blue_level_selector.get_value());
250 gamma_pattern.refresh();
251 gamma_pattern.queue_draw();
256 Dialog_Setup::refresh()
258 adj_gamma_r.set_value(1.0/App::gamma.get_gamma_r());
259 adj_gamma_g.set_value(1.0/App::gamma.get_gamma_g());
260 adj_gamma_b.set_value(1.0/App::gamma.get_gamma_b());
261 black_level_selector.set_value(App::gamma.get_black_level());
262 red_blue_level_selector.set_value(App::gamma.get_red_blue_level());
264 // Refresh the temporary gamma
265 gamma_pattern.set_gamma_r(1.0/adj_gamma_r.get_value());
266 gamma_pattern.set_gamma_g(1.0/adj_gamma_g.get_value());
267 gamma_pattern.set_gamma_b(1.0/adj_gamma_b.get_value());
268 gamma_pattern.set_black_level(black_level_selector.get_value());
269 gamma_pattern.set_red_blue_level(red_blue_level_selector.get_value());
270 gamma_pattern.refresh();
272 adj_recent_files.set_value(App::get_max_recent_files());
274 // Refresh the time format
275 set_time_format(App::get_time_format());
277 widget_enum->set_value(App::distance_system);
279 // Refresh the status of the use_colorspace_gamma flag
280 toggle_use_colorspace_gamma.set_active(App::use_colorspace_gamma);
284 GammaPattern::GammaPattern():
288 set_size_request(tile_w*4,tile_h*3);
289 signal_expose_event().connect(sigc::mem_fun(*this, &studio::GammaPattern::redraw));
292 GammaPattern::~GammaPattern()
297 GammaPattern::refresh()
321 black[1].set_rgb(black[0].get_red(),0,0);
322 gray25[1].set_rgb(gray25[0].get_red(),0,0);
323 gray50[1].set_rgb(gray50[0].get_red(),0,0);
324 white[1].set_rgb(white[0].get_red(),0,0);
327 black[2].set_rgb(0,black[0].get_green(),0);
328 gray25[2].set_rgb(0,gray25[0].get_green(),0);
329 gray50[2].set_rgb(0,gray50[0].get_green(),0);
330 white[2].set_rgb(0,white[0].get_green(),0);
333 black[3].set_rgb(0,0,black[0].get_blue());
334 gray25[3].set_rgb(0,0,gray25[0].get_blue());
335 gray50[3].set_rgb(0,0,gray50[0].get_blue());
336 white[3].set_rgb(0,0,white[0].get_blue());
340 GammaPattern::redraw(GdkEventExpose*bleh)
342 static const char hlines[] = { 3, 0 };
344 Glib::RefPtr<Gdk::GC> gc(Gdk::GC::create(get_window()));
347 Gdk::Color trueblack("#000000");
352 gc->set_rgb_fg_color(black[i]);
353 get_window()->draw_rectangle(gc, true, i*tile_w, 0, tile_w, tile_h);
355 gc->set_stipple(Gdk::Bitmap::create(hlines,2,2));
356 gc->set_fill(Gdk::STIPPLED);
357 gc->set_rgb_fg_color(white[i]);
358 get_window()->draw_rectangle(gc, true, i*tile_w, 0, tile_w, tile_h);
360 gc->set_fill(Gdk::SOLID);
361 gc->set_rgb_fg_color(gray50[i]);
363 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);
369 gc->set_rgb_fg_color(black[i]);
370 get_window()->draw_rectangle(gc, true, i*tile_w, tile_h, tile_w, tile_h);
372 gc->set_stipple(Gdk::Bitmap::create(hlines,2,2));
373 gc->set_fill(Gdk::STIPPLED);
374 gc->set_rgb_fg_color(gray50[i]);
375 get_window()->draw_rectangle(gc, true, i*tile_w, tile_h, tile_w, tile_h);
377 gc->set_fill(Gdk::SOLID);
378 gc->set_rgb_fg_color(gray25[i]);
380 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);
383 // Black-level Pattern
384 gc->set_rgb_fg_color(trueblack);
385 get_window()->draw_rectangle(gc, true, 0, tile_h*2, tile_w*4, tile_h);
386 gc->set_fill(Gdk::SOLID);
389 gc->set_rgb_fg_color(black[i]);
391 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);
398 BlackLevelSelector::BlackLevelSelector()
400 set_size_request(-1,24);
401 signal_expose_event().connect(sigc::mem_fun(*this, &studio::BlackLevelSelector::redraw));
403 add_events(Gdk::BUTTON_PRESS_MASK | Gdk::BUTTON_RELEASE_MASK);
404 add_events(Gdk::BUTTON1_MOTION_MASK);
405 add_events(Gdk::BUTTON1_MOTION_MASK);
408 BlackLevelSelector::~BlackLevelSelector()
413 BlackLevelSelector::redraw(GdkEventExpose*bleh)
415 const int w(get_width()),h(get_height());
419 Glib::RefPtr<Gdk::GC> gc(Gdk::GC::create(get_window()));
426 color.set_rgb(i*65536/w,i*65536/w,i*65536/w);
428 gc->set_rgb_fg_color(color);
429 get_window()->draw_rectangle(gc, true, i, 0, 1, h);
433 gc->set_rgb_fg_color(Gdk::Color("#000000"));
434 get_window()->draw_rectangle(gc, false, 0, 0, w-1, h-1);
436 // Draw the position of the current value
437 i=(int)(level*w+0.5);
438 gc->set_rgb_fg_color(Gdk::Color("#ff0000"));
439 get_window()->draw_rectangle(gc, true, i, 1, 1, h-1);
441 // Print out the value
442 Glib::RefPtr<Pango::Layout> layout(Pango::Layout::create(get_pango_context()));
443 layout->set_text(etl::strprintf("%0.01f%%",level*100.0f));
444 layout->set_alignment(Pango::ALIGN_CENTER);
445 gc->set_rgb_fg_color(Gdk::Color("#a00000"));
446 get_window()->draw_layout(gc, w/2, 4, layout);
454 BlackLevelSelector::on_event(GdkEvent *event)
456 int x(round_to_int(event->button.x));
457 //int y(round_to_int(event->button.y));
461 case GDK_MOTION_NOTIFY:
462 level=(float)x/(float)get_width();
463 if(level<0.0f)level=0.0f;
464 if(level>1.0f)level=1.0f;
465 signal_value_changed_();
469 case GDK_BUTTON_PRESS:
470 case GDK_BUTTON_RELEASE:
471 if(event->button.button==1)
473 level=(float)x/(float)get_width();
474 if(level<0.0f)level=0.0f;
475 if(level>1.0f)level=1.0f;
476 signal_value_changed_();
490 Dialog_Setup::set_time_format(Time::Format x)
493 if(x<=Time::FORMAT_VIDEO)
494 timestamp_optionmenu.set_history(0);
497 if(x==(Time::FORMAT_NOSPACES|Time::FORMAT_FULL))
498 timestamp_optionmenu.set_history(4);
499 else if(x==(Time::FORMAT_FULL))
500 timestamp_optionmenu.set_history(3);
501 else if(x==(Time::FORMAT_NOSPACES))
502 timestamp_optionmenu.set_history(2);
504 timestamp_optionmenu.set_history(1);
523 RedBlueLevelSelector::RedBlueLevelSelector()
525 set_size_request(-1,24);
526 signal_expose_event().connect(sigc::mem_fun(*this, &studio::RedBlueLevelSelector::redraw));
528 add_events(Gdk::BUTTON_PRESS_MASK | Gdk::BUTTON_RELEASE_MASK);
529 add_events(Gdk::BUTTON1_MOTION_MASK);
530 add_events(Gdk::BUTTON1_MOTION_MASK);
533 RedBlueLevelSelector::~RedBlueLevelSelector()
538 RedBlueLevelSelector::redraw(GdkEventExpose*bleh)
540 const int w(get_width()),h(get_height());
544 Glib::RefPtr<Gdk::GC> gc(Gdk::GC::create(get_window()));
551 float red_blue(((float(i)/float(w)+0.5f)-1.0f)/2.0f+1.0f);
552 float blue_red(2.0f-(red_blue));
553 if(red_blue>1.0f)red_blue=1.0f;
554 if(blue_red>1.0f)blue_red=1.0f;
557 round_to_int(min(red_blue,1.0f)*65535),
558 round_to_int(sqrt(min(red_blue,blue_red))*65535),
559 round_to_int(min(blue_red,1.0f)*65535)
562 gc->set_rgb_fg_color(color);
563 get_window()->draw_rectangle(gc, true, i, 0, 1, h);
567 gc->set_rgb_fg_color(Gdk::Color("#000000"));
568 get_window()->draw_rectangle(gc, false, 0, 0, w-1, h-1);
570 // Draw the position of the current value
571 i=(int)(((level-1.0f)*2.0f+1.0f-0.5f)*w+0.5);
572 gc->set_rgb_fg_color(Gdk::Color("#00ff00"));
573 get_window()->draw_rectangle(gc, true, i, 1, 1, h-1);
575 // Print out the value
576 Glib::RefPtr<Pango::Layout> layout(Pango::Layout::create(get_pango_context()));
577 layout->set_text(etl::strprintf("%0.02f",level));
578 layout->set_alignment(Pango::ALIGN_CENTER);
579 gc->set_rgb_fg_color(Gdk::Color("#a00000"));
580 get_window()->draw_layout(gc, w/2, 4, layout);
588 RedBlueLevelSelector::on_event(GdkEvent *event)
590 int x(round_to_int(event->button.x));
591 //int y(round_to_int(event->button.y));
595 case GDK_MOTION_NOTIFY:
596 level=(((float)(x)/(float)get_width()+0.5)-1.0f)/2.0f+1.0f;
597 if(level<0.5f)level=0.5f;
598 if(level>1.5f)level=1.5f;
599 signal_value_changed_();
603 case GDK_BUTTON_PRESS:
604 case GDK_BUTTON_RELEASE:
605 if(event->button.button==1)
607 level=(((float)(x)/(float)get_width()+0.5)-1.0f)/2.0f+1.0f;
608 if(level<0.5f)level=0.5f;
609 if(level>1.5f)level=1.5f;
610 signal_value_changed_();