1 /* === S Y N F I G ========================================================= */
2 /*! \file widget_defaults.cpp
3 ** \brief Template File
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 "widget_defaults.h"
33 #include "widget_color.h"
34 #include "widget_gradient.h"
35 #include "dialog_color.h"
36 #include "dialog_gradient.h"
38 #include <gtkmm/menu.h>
39 #include <gtkmm/scale.h>
40 #include <synfig/exception.h>
41 #include <synfigapp/main.h>
42 #include "canvasview.h"
43 #include "widget_distance.h"
44 #include "widget_enum.h"
48 /* === U S I N G =========================================================== */
52 using namespace synfig;
53 using namespace studio;
55 /* === M A C R O S ========================================================= */
57 #define GRADIENT_HEIGHT 16
58 #define DEFAULT_INCREMENT (0.25)
59 #define DEFAULT_WIDTH (synfig::Distance(3,synfig::Distance::SYSTEM_POINTS))
61 /* === G L O B A L S ======================================================= */
63 class studio::Widget_Brush : public Gtk::DrawingArea
68 signal_expose_event().connect(sigc::mem_fun(*this, &studio::Widget_Brush::redraw));
70 set_size_request(24,24);
71 add_events(Gdk::BUTTON_PRESS_MASK | Gdk::BUTTON_RELEASE_MASK);
72 add_events(Gdk::BUTTON1_MOTION_MASK);
74 synfigapp::Main::signal_foreground_color_changed().connect(sigc::mem_fun(*this,&studio::Widget_Brush::queue_draw));
75 synfigapp::Main::signal_background_color_changed().connect(sigc::mem_fun(*this,&studio::Widget_Brush::queue_draw));
76 synfigapp::Main::signal_bline_width_changed().connect(sigc::mem_fun(*this,&studio::Widget_Brush::queue_draw));
77 studio::App::signal_instance_selected().connect(sigc::hide(sigc::mem_fun(*this,&studio::Widget_Brush::queue_draw)));
81 redraw(GdkEventExpose*bleh)
83 Glib::RefPtr<Gdk::GC> gc(Gdk::GC::create(get_window()));
85 const int h(get_height());
86 const int w(get_width());
89 if(App::get_selected_canvas_view())
91 const RendDesc& rend_desc(App::get_selected_canvas_view()->get_canvas()->rend_desc());
92 pixelsize=synfigapp::Main::get_bline_width().get(Distance::SYSTEM_PIXELS,rend_desc);
97 pixelsize=synfigapp::Main::get_bline_width().get(Distance::SYSTEM_PIXELS,rend_desc);
99 // Fill in the background color
100 render_color_to_window(get_window(),Gdk::Rectangle(0,0,w,h),synfigapp::Main::get_background_color());
103 gc->set_rgb_fg_color(colorconv_synfig2gdk(synfigapp::Main::get_background_color()));
104 gc->set_line_attributes(1,Gdk::LINE_SOLID,Gdk::CAP_BUTT,Gdk::JOIN_MITER);
105 get_window()->draw_rectangle(
113 // Draw in the circle
114 gc->set_rgb_fg_color(colorconv_synfig2gdk(synfigapp::Main::get_foreground_color()));
115 gc->set_function(Gdk::COPY);
116 gc->set_line_attributes(1,Gdk::LINE_SOLID,Gdk::CAP_BUTT,Gdk::JOIN_MITER);
117 get_window()->draw_arc(
120 round_to_int(((float)w/2.0f)-pixelsize/2.0f),
121 round_to_int(((float)h/2.0f)-pixelsize/2.0f),
122 round_to_int(pixelsize+0.6),
123 round_to_int(pixelsize+0.6),
132 on_event(GdkEvent *event)
134 // const int x(static_cast<int>(event->button.x));
135 const int y(static_cast<int>(event->button.y));
137 const int h(get_height());
138 // const int w(get_width());
142 case GDK_MOTION_NOTIFY:
144 case GDK_BUTTON_RELEASE:
145 if(event->button.button==1) // Left click
147 Distance dist(synfigapp::Main::get_bline_width());
149 if(y<h/2) // increase BLine size
151 dist+=DEFAULT_INCREMENT;
153 else // Decrease BLine size
155 dist-=DEFAULT_INCREMENT;
157 synfigapp::Main::set_bline_width(dist);
160 if(event->button.button==3)
162 // right click on bline width
163 synfigapp::Main::set_bline_width(DEFAULT_WIDTH);
169 Distance dist(synfigapp::Main::get_bline_width());
171 if(event->scroll.direction==GDK_SCROLL_UP)
173 dist+=DEFAULT_INCREMENT;
175 else if(event->scroll.direction==GDK_SCROLL_DOWN)
177 dist-=DEFAULT_INCREMENT;
179 synfigapp::Main::set_bline_width(dist);
191 /* === P R O C E D U R E S ================================================= */
193 /* === M E T H O D S ======================================================= */
195 Widget_Defaults::Widget_Defaults()
197 //set_size_request(48,48+GRADIENT_HEIGHT+16);
198 //set_size_request(48,-1);
201 Gtk::Table* subtable(manage(new Gtk::Table()));
204 widget_fg_color=manage(new Widget_Color());
205 widget_fg_color->show();
206 widget_fg_color->set_size_request(16,16);
207 widget_fg_color->signal_clicked().connect(sigc::mem_fun(*this,&Widget_Defaults::on_fg_color_clicked));
208 subtable->attach(*widget_fg_color, 0, 2, 0, 2, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
209 tooltips_.set_tip(*widget_fg_color,_("Foreground Color"));
212 widget_bg_color=manage(new Widget_Color());
213 widget_bg_color->show();
214 widget_bg_color->set_size_request(16,16);
215 widget_bg_color->signal_clicked().connect(sigc::mem_fun(*this,&Widget_Defaults::on_bg_color_clicked));
216 subtable->attach(*widget_bg_color, 1, 3, 1, 3, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
217 tooltips_.set_tip(*widget_bg_color,_("Background Color"));
222 Gtk::Button* button_swap(manage(new Gtk::Button()));
224 button_swap->set_relief(Gtk::RELIEF_NONE);
225 button_swap->set_border_width(0);
226 icon=manage(new Gtk::Image(Gtk::StockID("synfig-swap_colors"),Gtk::IconSize(1)));
228 button_swap->add(*icon);
229 //button_swap->get_child()->set_size_request(16/3,16/3);
230 //button_swap->set_size_request(16/3,16/3);
231 dynamic_cast<Gtk::Misc*>(button_swap->get_child())->set_padding(0,0);
232 button_swap->signal_clicked().connect(sigc::mem_fun(*this,&Widget_Defaults::on_swap_color_clicked));
233 subtable->attach(*button_swap, 2, 3, 0, 1, Gtk::SHRINK|Gtk::FILL, Gtk::SHRINK|Gtk::FILL, 0, 0);
234 tooltips_.set_tip(*button_swap,_("Swap Background and\nForeground Colors"));
237 Gtk::Button* button_reset(manage(new Gtk::Button("R")));
238 button_reset->show();
239 button_reset->set_relief(Gtk::RELIEF_NONE);
240 button_reset->set_border_width(0);
241 dynamic_cast<Gtk::Misc*>(button_reset->get_child())->set_padding(0,0);
242 //button_reset->set_size_request(16/3,16/3);
243 button_reset->signal_clicked().connect(sigc::mem_fun(*this,&Widget_Defaults::on_reset_color_clicked));
244 subtable->attach(*button_reset, 0,1, 2, 3, Gtk::SHRINK|Gtk::FILL, Gtk::SHRINK|Gtk::FILL, 0, 0);
245 tooltips_.set_tip(*button_reset,_("Reset Colors to Black and White"));
248 attach(*subtable, 0, 1, 0, 2, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 1, 1);
249 subtable->set_size_request(36,36);
250 subtable->set_homogeneous(true);
253 widget_brush=manage(new Widget_Brush());
254 widget_brush->show();
255 widget_brush->set_size_request(36,36);
256 attach(*widget_brush,1, 2, 0, 1, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 1, 1);
257 tooltips_.set_tip(*widget_brush,_("Brush Preview"));
259 widget_bline_width=manage(new Widget_Distance());
260 widget_bline_width->show();
261 bline_width_refresh();
262 widget_bline_width->set_digits(2);
263 widget_bline_width->set_range(0,10000000);
264 widget_bline_width->set_size_request(24,-1);
265 widget_bline_width->signal_value_changed().connect(sigc::mem_fun(*this,&studio::Widget_Defaults::on_bline_width_changed));
266 attach(*widget_bline_width,1, 2, 1, 2, Gtk::EXPAND|Gtk::FILL, Gtk::SHRINK|Gtk::FILL, 0, 0);
267 tooltips_.set_tip(*widget_bline_width,_("Brush Size"));
270 widget_blend_method=manage(new Widget_Enum());
271 widget_blend_method->show();
272 widget_blend_method->signal_activate().connect(sigc::mem_fun(*this,&studio::Widget_Defaults::on_blend_method_changed));
273 widget_blend_method->set_param_desc(ParamDesc(Color::BLEND_COMPOSITE,"blend_method"));
274 attach(*widget_blend_method,0, 2, 2, 3, Gtk::EXPAND|Gtk::FILL, Gtk::SHRINK|Gtk::FILL, 1, 1);
275 tooltips_.set_tip(*widget_blend_method,_("Default Blend Method"));
277 widget_interpolation=manage(new Widget_Enum());
278 widget_interpolation->show();
279 widget_interpolation->signal_activate().connect(sigc::mem_fun(*this,&studio::Widget_Defaults::on_interpolation_changed));
280 widget_interpolation->set_param_desc(
281 ParamDesc("interpolation")
283 .add_enum_value(INTERPOLATION_TCB,"auto",_("TCB"))
284 .add_enum_value(INTERPOLATION_CONSTANT,"constant",_("Constant"))
285 .add_enum_value(INTERPOLATION_HALT,"ease",_("Ease in/out"))
286 .add_enum_value(INTERPOLATION_LINEAR,"linear",_("Linear"))
288 attach(*widget_interpolation,0, 2, 5, 6, Gtk::EXPAND|Gtk::FILL, Gtk::SHRINK|Gtk::FILL, 1, 1);
289 tooltips_.set_tip(*widget_interpolation,_("Default Interpolation"));
291 widget_opacity=manage(new Gtk::HScale(0.0f,1.01f,0.01f));
292 widget_opacity->show();
293 widget_opacity->set_digits(2);
294 widget_opacity->set_value_pos(Gtk::POS_LEFT);
295 widget_opacity->signal_value_changed().connect(sigc::mem_fun(*this,&studio::Widget_Defaults::on_opacity_changed));
296 attach(*widget_opacity,0, 2, 3, 4, Gtk::EXPAND|Gtk::FILL, Gtk::SHRINK|Gtk::FILL, 1, 1);
297 tooltips_.set_tip(*widget_opacity,_("Default Opacity"));
299 widget_gradient=manage(new Widget_Gradient());
300 widget_gradient->show();
301 widget_gradient->set_size_request(-1,GRADIENT_HEIGHT);
302 widget_gradient->signal_clicked().connect(sigc::mem_fun(*this,&studio::Widget_Defaults::on_gradient_clicked));
303 attach(*widget_gradient,0, 2, 4, 5, Gtk::EXPAND|Gtk::FILL, Gtk::SHRINK|Gtk::FILL, 1, 1);
304 tooltips_.set_tip(*widget_gradient,_("Default Gradient"));
308 synfigapp::Main::signal_opacity_changed().connect(sigc::mem_fun(*this,&studio::Widget_Defaults::opacity_refresh));
309 synfigapp::Main::signal_bline_width_changed().connect(sigc::mem_fun(*this,&studio::Widget_Defaults::bline_width_refresh));
310 synfigapp::Main::signal_foreground_color_changed().connect(sigc::mem_fun(*this,&studio::Widget_Defaults::fg_color_refresh));
311 synfigapp::Main::signal_background_color_changed().connect(sigc::mem_fun(*this,&studio::Widget_Defaults::bg_color_refresh));
312 synfigapp::Main::signal_gradient_changed().connect(sigc::mem_fun(*this,&studio::Widget_Defaults::gradient_refresh));
313 synfigapp::Main::signal_blend_method_changed().connect(sigc::mem_fun(*this,&studio::Widget_Defaults::blend_method_refresh));
314 synfigapp::Main::signal_interpolation_changed().connect(sigc::mem_fun(*this,&studio::Widget_Defaults::interpolation_refresh));
319 blend_method_refresh();
321 interpolation_refresh();
323 set_size_request(48,48+GRADIENT_HEIGHT);
324 signal_expose_event().connect(sigc::mem_fun(*this, &studio::Widget_Defaults::redraw));
325 add_events(Gdk::BUTTON_PRESS_MASK | Gdk::BUTTON_RELEASE_MASK);
326 add_events(Gdk::BUTTON1_MOTION_MASK);
328 synfigapp::Main::signal_foreground_color_changed().connect(sigc::mem_fun(*this,&studio::Widget_Defaults::queue_draw));
329 synfigapp::Main::signal_background_color_changed().connect(sigc::mem_fun(*this,&studio::Widget_Defaults::queue_draw));
330 synfigapp::Main::signal_gradient_changed().connect(sigc::mem_fun(*this,&studio::Widget_Defaults::queue_draw));
331 synfigapp::Main::signal_bline_width_changed().connect(sigc::mem_fun(*this,&studio::Widget_Defaults::queue_draw));
333 if(App::dialog_gradient)
335 App::dialog_gradient->set_gradient(synfigapp::Main::get_gradient());
336 App::dialog_gradient->reset();
337 App::dialog_gradient->signal_edited().connect(sigc::mem_fun(synfigapp::Main::set_gradient));
340 if(App::dialog_color)
342 App::dialog_color->set_color(synfigapp::Main::get_foreground_color());
343 App::dialog_color->reset();
344 App::dialog_color->signal_edited().connect(sigc::mem_fun(synfigapp::Main::set_foreground_color));
349 Widget_Defaults::~Widget_Defaults()
354 Widget_Defaults::fg_color_refresh()
356 widget_fg_color->set_value(synfigapp::Main::get_foreground_color());
360 Widget_Defaults::bg_color_refresh()
362 widget_bg_color->set_value(synfigapp::Main::get_background_color());
366 Widget_Defaults::gradient_refresh()
368 widget_gradient->set_value(synfigapp::Main::get_gradient());
372 Widget_Defaults::bline_width_refresh()
374 widget_bline_width->set_value(synfigapp::Main::get_bline_width());
378 Widget_Defaults::blend_method_refresh()
380 widget_blend_method->set_value(synfigapp::Main::get_blend_method());
384 Widget_Defaults::interpolation_refresh()
386 widget_interpolation->set_value(synfigapp::Main::get_interpolation());
390 Widget_Defaults::opacity_refresh()
392 widget_opacity->set_value(synfigapp::Main::get_opacity());
396 Widget_Defaults::on_opacity_changed()
398 synfigapp::Main::set_opacity(widget_opacity->get_value());
402 Widget_Defaults::on_blend_method_changed()
404 synfigapp::Main::set_blend_method(Color::BlendMethod(widget_blend_method->get_value()));
408 Widget_Defaults::on_interpolation_changed()
410 synfigapp::Main::set_interpolation(Waypoint::Interpolation(widget_interpolation->get_value()));
414 Widget_Defaults::on_bline_width_changed()
416 synfigapp::Main::set_bline_width(widget_bline_width->get_value());
420 Widget_Defaults::on_fg_color_clicked()
422 // Left click on foreground
423 App::dialog_color->set_color(synfigapp::Main::get_foreground_color());
424 App::dialog_color->reset();
425 App::dialog_color->signal_edited().connect(sigc::ptr_fun(synfigapp::Main::set_foreground_color));
426 App::dialog_color->present();
430 Widget_Defaults::on_bg_color_clicked()
432 // Left click on background
433 App::dialog_color->set_color(synfigapp::Main::get_background_color());
434 App::dialog_color->reset();
435 App::dialog_color->signal_edited().connect(sigc::ptr_fun(synfigapp::Main::set_background_color));
436 App::dialog_color->present();
440 Widget_Defaults::on_swap_color_clicked()
442 synfigapp::Main::color_swap();
446 Widget_Defaults::on_reset_color_clicked()
448 synfigapp::Main::set_background_color(Color::white());
449 synfigapp::Main::set_foreground_color(Color::black());
453 Widget_Defaults::on_gradient_clicked()
455 App::dialog_gradient->set_gradient(synfigapp::Main::get_gradient());
456 App::dialog_gradient->reset();
457 App::dialog_gradient->signal_edited().connect(sigc::ptr_fun(synfigapp::Main::set_gradient));
458 App::dialog_gradient->present();
463 Widget_Defaults::redraw(GdkEventExpose*bleh)
465 Glib::RefPtr<Gdk::GC> gc(Gdk::GC::create(get_window()));
467 const int h(get_height());
468 const int w(get_width());
469 const int size=std::min(h-GRADIENT_HEIGHT,w);
471 render_color_to_window(get_window(),Gdk::Rectangle(size/4,size/4,size/4*3-1,size/4*3-1),synfigapp::Main::get_background_color());
472 render_color_to_window(get_window(),Gdk::Rectangle(0,0,size/4*3-1,size/4*3-1),synfigapp::Main::get_foreground_color());
473 render_gradient_to_window(get_window(),Gdk::Rectangle(0,h-GRADIENT_HEIGHT,w,GRADIENT_HEIGHT-1),synfigapp::Main::get_gradient());
479 Glib::RefPtr<Pango::Layout> layout(Pango::Layout::create(get_pango_context()));
481 gc->set_rgb_fg_color(Gdk::Color("#FF0000"));
482 layout->set_text(synfigapp::Main::get_bline_width().get_string(2));
483 layout->set_alignment(Pango::ALIGN_CENTER);
484 layout->set_width(w/2);
485 get_window()->draw_layout(gc, w*3/4, (h-GRADIENT_HEIGHT)-16, layout);
491 Widget_Defaults::on_event(GdkEvent *event)
493 const int x(static_cast<int>(event->button.x));
494 const int y(static_cast<int>(event->button.y));
496 const int h(get_height());
497 const int w(get_width());
498 const int size=std::min(h-GRADIENT_HEIGHT,w);
502 case GDK_MOTION_NOTIFY:
504 case GDK_BUTTON_PRESS:
505 // if(event->button.button==1 && y>get_height()-CONTROL_HEIGHT)
507 case GDK_BUTTON_RELEASE:
508 if(event->button.button==1)
512 // Left click on gradient
513 App::dialog_gradient->set_gradient(synfigapp::Main::get_gradient());
514 App::dialog_gradient->reset();
515 App::dialog_gradient->signal_edited().connect(sigc::mem_fun(synfigapp::Main::set_gradient));
516 App::dialog_gradient->present();
521 if(x<size*3/4 && y<size*3/4)
523 // Left click on foreground
524 App::dialog_color->set_color(synfigapp::Main::get_foreground_color());
525 App::dialog_color->reset();
526 App::dialog_color->signal_edited().connect(sigc::mem_fun(synfigapp::Main::set_foreground_color));
527 App::dialog_color->present();
530 if(x>size*3/4 && y>size/4)
532 // Left click on background
533 App::dialog_color->set_color(synfigapp::Main::get_background_color());
534 App::dialog_color->reset();
535 App::dialog_color->signal_edited().connect(sigc::mem_fun(synfigapp::Main::set_background_color));
536 App::dialog_color->present();
540 if(x>size) // Left click on BLine Width
542 Distance dist(synfigapp::Main::get_bline_width());
544 if(y<size/2) // increase BLine size
546 dist+=DEFAULT_INCREMENT;
548 else // Decrease BLine size
550 dist-=DEFAULT_INCREMENT;
552 synfigapp::Main::set_bline_width(dist);
555 if(event->button.button==3)
559 // right click on gradient
560 synfigapp::Main::set_gradient_default_colors();
567 // right click on colors
568 synfigapp::Main::color_swap();
574 // right click on bline width
575 synfigapp::Main::set_bline_width(DEFAULT_WIDTH);
583 Distance dist(synfigapp::Main::get_bline_width());
585 if(event->scroll.direction==GDK_SCROLL_UP)
587 dist+=DEFAULT_INCREMENT;
589 else if(event->scroll.direction==GDK_SCROLL_DOWN)
591 dist-=DEFAULT_INCREMENT;
593 synfigapp::Main::set_bline_width(dist);