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
9 ** Copyright (c) 2008 Chris Moore
10 ** Copyright (c) 2008 Carlos López
12 ** This package is free software; you can redistribute it and/or
13 ** modify it under the terms of the GNU General Public License as
14 ** published by the Free Software Foundation; either version 2 of
15 ** the License, or (at your option) any later version.
17 ** This package is distributed in the hope that it will be useful,
18 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 ** General Public License for more details.
23 /* ========================================================================= */
25 /* === H E A D E R S ======================================================= */
34 #include "widget_defaults.h"
35 #include "widget_color.h"
36 #include "widget_gradient.h"
37 #include "dialog_color.h"
38 #include "dialog_gradient.h"
40 #include <gtkmm/menu.h>
41 #include <gtkmm/scale.h>
42 #include <synfig/exception.h>
43 #include <synfigapp/main.h>
44 #include "canvasview.h"
45 #include "widget_distance.h"
46 #include "widget_enum.h"
52 /* === U S I N G =========================================================== */
56 using namespace synfig;
57 using namespace studio;
59 /* === M A C R O S ========================================================= */
61 #define GRADIENT_HEIGHT 16
62 #define DEFAULT_INCREMENT (0.25)
63 #define DEFAULT_WIDTH (synfig::Distance(3,synfig::Distance::SYSTEM_POINTS))
65 /* === G L O B A L S ======================================================= */
67 class studio::Widget_Brush : public Gtk::DrawingArea
72 signal_expose_event().connect(sigc::mem_fun(*this, &studio::Widget_Brush::redraw));
74 set_size_request(24,24);
75 add_events(Gdk::BUTTON_PRESS_MASK | Gdk::BUTTON_RELEASE_MASK);
76 add_events(Gdk::BUTTON1_MOTION_MASK);
78 synfigapp::Main::signal_outline_color_changed().connect(sigc::mem_fun(*this,&studio::Widget_Brush::queue_draw));
79 synfigapp::Main::signal_fill_color_changed().connect(sigc::mem_fun(*this,&studio::Widget_Brush::queue_draw));
80 synfigapp::Main::signal_bline_width_changed().connect(sigc::mem_fun(*this,&studio::Widget_Brush::queue_draw));
81 studio::App::signal_instance_selected().connect(sigc::hide(sigc::mem_fun(*this,&studio::Widget_Brush::queue_draw)));
85 redraw(GdkEventExpose */*bleh*/)
87 Glib::RefPtr<Gdk::GC> gc(Gdk::GC::create(get_window()));
89 const int h(get_height());
90 const int w(get_width());
93 if(App::get_selected_canvas_view())
95 const RendDesc& rend_desc(App::get_selected_canvas_view()->get_canvas()->rend_desc());
96 pixelsize=synfigapp::Main::get_bline_width().get(Distance::SYSTEM_PIXELS,rend_desc);
101 pixelsize=synfigapp::Main::get_bline_width().get(Distance::SYSTEM_PIXELS,rend_desc);
103 // Fill in the fill color
104 render_color_to_window(get_window(),Gdk::Rectangle(0,0,w,h),synfigapp::Main::get_fill_color());
107 gc->set_rgb_fg_color(colorconv_synfig2gdk(synfigapp::Main::get_fill_color()));
108 gc->set_line_attributes(1,Gdk::LINE_SOLID,Gdk::CAP_BUTT,Gdk::JOIN_MITER);
109 get_window()->draw_rectangle(
117 // Draw in the circle
118 gc->set_rgb_fg_color(colorconv_synfig2gdk(synfigapp::Main::get_outline_color()));
119 gc->set_function(Gdk::COPY);
120 gc->set_line_attributes(1,Gdk::LINE_SOLID,Gdk::CAP_BUTT,Gdk::JOIN_MITER);
121 get_window()->draw_arc(
124 round_to_int(((float)w/2.0f)-pixelsize/2.0f),
125 round_to_int(((float)h/2.0f)-pixelsize/2.0f),
126 round_to_int(pixelsize+0.6),
127 round_to_int(pixelsize+0.6),
136 on_event(GdkEvent *event)
138 // const int x(static_cast<int>(event->button.x));
139 const int y(static_cast<int>(event->button.y));
141 const int h(get_height());
142 // const int w(get_width());
146 case GDK_MOTION_NOTIFY:
148 case GDK_BUTTON_RELEASE:
149 if(event->button.button==1) // Left click
151 Distance dist(synfigapp::Main::get_bline_width());
153 if(y<h/2) // increase BLine size
155 dist+=DEFAULT_INCREMENT;
157 else // Decrease BLine size
159 dist-=DEFAULT_INCREMENT;
161 synfigapp::Main::set_bline_width(dist);
164 if(event->button.button==3)
166 // right click on bline width
167 synfigapp::Main::set_bline_width(DEFAULT_WIDTH);
173 Distance dist(synfigapp::Main::get_bline_width());
175 switch(event->scroll.direction){
177 case GDK_SCROLL_RIGHT:
178 dist+=DEFAULT_INCREMENT;
180 case GDK_SCROLL_DOWN:
181 case GDK_SCROLL_LEFT:
182 dist-=DEFAULT_INCREMENT;
185 synfigapp::Main::set_bline_width(dist);
197 /* === P R O C E D U R E S ================================================= */
199 /* === M E T H O D S ======================================================= */
201 Widget_Defaults::Widget_Defaults()
203 //set_size_request(48,48+GRADIENT_HEIGHT+16);
204 //set_size_request(48,-1);
207 Gtk::Table* subtable(manage(new Gtk::Table()));
210 widget_otln_color=manage(new Widget_Color());
211 widget_otln_color->show();
212 widget_otln_color->set_size_request(16,16);
213 widget_otln_color->signal_clicked().connect(sigc::mem_fun(*this,&Widget_Defaults::on_otln_color_clicked));
214 subtable->attach(*widget_otln_color, 0, 4, 0, 4, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
215 tooltips_.set_tip(*widget_otln_color,_("Outline Color"));
218 widget_fill_color=manage(new Widget_Color());
219 widget_fill_color->show();
220 widget_fill_color->set_size_request(16,16);
221 widget_fill_color->signal_clicked().connect(sigc::mem_fun(*this,&Widget_Defaults::on_fill_color_clicked));
222 subtable->attach(*widget_fill_color, 3, 7, 3, 7, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
223 tooltips_.set_tip(*widget_fill_color,_("Fill Color"));
228 Gtk::Button* button_swap(manage(new Gtk::Button()));
230 button_swap->set_relief(Gtk::RELIEF_NONE);
231 button_swap->set_border_width(0);
232 icon=manage(new Gtk::Image(Gtk::StockID("synfig-swap_colors"),Gtk::IconSize(1)));
234 button_swap->add(*icon);
235 //button_swap->get_child()->set_size_request(16/3,16/3);
236 //button_swap->set_size_request(16/3,16/3);
237 dynamic_cast<Gtk::Misc*>(button_swap->get_child())->set_padding(0,0);
238 button_swap->signal_clicked().connect(sigc::mem_fun(*this,&Widget_Defaults::on_swap_color_clicked));
239 subtable->attach(*button_swap, 4, 7, 0, 3, Gtk::SHRINK|Gtk::FILL, Gtk::SHRINK|Gtk::FILL, 0, 0);
240 tooltips_.set_tip(*button_swap,_("Swap Fill and\nOutline Colors"));
243 Gtk::Button* button_reset(manage(new Gtk::Button()));
244 button_reset->show();
245 button_reset->set_relief(Gtk::RELIEF_NONE);
246 button_reset->set_border_width(0);
247 icon=manage(new Gtk::Image(Gtk::StockID("synfig-reset_colors"),Gtk::IconSize(1)));
249 button_reset->add(*icon);
250 dynamic_cast<Gtk::Misc*>(button_reset->get_child())->set_padding(0,0);
251 //button_reset->set_size_request(16/3,16/3);
252 button_reset->signal_clicked().connect(sigc::mem_fun(*this,&Widget_Defaults::on_reset_color_clicked));
253 subtable->attach(*button_reset, 0, 3, 4, 7, Gtk::SHRINK|Gtk::FILL, Gtk::SHRINK|Gtk::FILL, 0, 0);
254 tooltips_.set_tip(*button_reset,_("Reset Colors to Black and White"));
257 attach(*subtable, 0, 1, 0, 2, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 1, 1);
258 subtable->set_size_request(36,36);
259 subtable->set_homogeneous(true);
262 widget_brush=manage(new Widget_Brush());
263 widget_brush->show();
264 widget_brush->set_size_request(36,36);
265 attach(*widget_brush,1, 2, 0, 1, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 1, 1);
266 tooltips_.set_tip(*widget_brush,_("Brush Preview"));
268 widget_bline_width=manage(new Widget_Distance());
269 widget_bline_width->show();
270 bline_width_refresh();
271 widget_bline_width->set_digits(2);
272 widget_bline_width->set_range(0,10000000);
273 widget_bline_width->set_size_request(24,-1);
274 widget_bline_width->signal_value_changed().connect(sigc::mem_fun(*this,&studio::Widget_Defaults::on_bline_width_changed));
275 attach(*widget_bline_width,1, 2, 1, 2, Gtk::EXPAND|Gtk::FILL, Gtk::SHRINK|Gtk::FILL, 0, 0);
276 tooltips_.set_tip(*widget_bline_width,_("Brush Size"));
279 widget_blend_method=manage(new Widget_Enum());
280 widget_blend_method->show();
281 widget_blend_method->signal_activate().connect(sigc::mem_fun(*this,&studio::Widget_Defaults::on_blend_method_changed));
282 widget_blend_method->set_param_desc(ParamDesc(Color::BLEND_COMPOSITE,"blend_method"));
283 attach(*widget_blend_method,0, 2, 2, 3, Gtk::EXPAND|Gtk::FILL, Gtk::SHRINK|Gtk::FILL, 1, 1);
284 tooltips_.set_tip(*widget_blend_method,_("Default Blend Method"));
286 widget_interpolation=manage(new Widget_Enum());
287 widget_interpolation->show();
288 widget_interpolation->signal_activate().connect(sigc::mem_fun(*this,&studio::Widget_Defaults::on_interpolation_changed));
289 widget_interpolation->set_param_desc(
290 ParamDesc("interpolation")
292 .add_enum_value(INTERPOLATION_TCB,"auto",_("_TCB"))
293 .add_enum_value(INTERPOLATION_CONSTANT,"constant",_("_Constant"))
294 .add_enum_value(INTERPOLATION_HALT,"ease",_("_Ease In/Out"))
295 .add_enum_value(INTERPOLATION_LINEAR,"linear",_("_Linear"))
297 attach(*widget_interpolation,0, 2, 5, 6, Gtk::EXPAND|Gtk::FILL, Gtk::SHRINK|Gtk::FILL, 1, 1);
298 tooltips_.set_tip(*widget_interpolation,_("Default Interpolation"));
300 widget_opacity=manage(new Gtk::HScale(0.0f,1.01f,0.01f));
301 widget_opacity->show();
302 widget_opacity->set_digits(2);
303 widget_opacity->set_value_pos(Gtk::POS_LEFT);
304 widget_opacity->signal_value_changed().connect(sigc::mem_fun(*this,&studio::Widget_Defaults::on_opacity_changed));
305 attach(*widget_opacity,0, 2, 3, 4, Gtk::EXPAND|Gtk::FILL, Gtk::SHRINK|Gtk::FILL, 1, 1);
306 tooltips_.set_tip(*widget_opacity,_("Default Opacity"));
308 widget_gradient=manage(new Widget_Gradient());
309 widget_gradient->show();
310 widget_gradient->set_size_request(-1,GRADIENT_HEIGHT);
311 widget_gradient->signal_clicked().connect(sigc::mem_fun(*this,&studio::Widget_Defaults::on_gradient_clicked));
312 attach(*widget_gradient,0, 2, 4, 5, Gtk::EXPAND|Gtk::FILL, Gtk::SHRINK|Gtk::FILL, 1, 1);
313 tooltips_.set_tip(*widget_gradient,_("Default Gradient"));
317 synfigapp::Main::signal_opacity_changed().connect(sigc::mem_fun(*this,&studio::Widget_Defaults::opacity_refresh));
318 synfigapp::Main::signal_bline_width_changed().connect(sigc::mem_fun(*this,&studio::Widget_Defaults::bline_width_refresh));
319 synfigapp::Main::signal_outline_color_changed().connect(sigc::mem_fun(*this,&studio::Widget_Defaults::otln_color_refresh));
320 synfigapp::Main::signal_fill_color_changed().connect(sigc::mem_fun(*this,&studio::Widget_Defaults::fill_color_refresh));
321 synfigapp::Main::signal_gradient_changed().connect(sigc::mem_fun(*this,&studio::Widget_Defaults::gradient_refresh));
322 synfigapp::Main::signal_blend_method_changed().connect(sigc::mem_fun(*this,&studio::Widget_Defaults::blend_method_refresh));
323 synfigapp::Main::signal_interpolation_changed().connect(sigc::mem_fun(*this,&studio::Widget_Defaults::interpolation_refresh));
325 otln_color_refresh();
326 fill_color_refresh();
328 blend_method_refresh();
330 interpolation_refresh();
332 set_size_request(48,48+GRADIENT_HEIGHT);
333 signal_expose_event().connect(sigc::mem_fun(*this, &studio::Widget_Defaults::redraw));
334 add_events(Gdk::BUTTON_PRESS_MASK | Gdk::BUTTON_RELEASE_MASK);
335 add_events(Gdk::BUTTON1_MOTION_MASK);
337 synfigapp::Main::signal_outline_color_changed().connect(sigc::mem_fun(*this,&studio::Widget_Defaults::queue_draw));
338 synfigapp::Main::signal_fill_color_changed().connect(sigc::mem_fun(*this,&studio::Widget_Defaults::queue_draw));
339 synfigapp::Main::signal_gradient_changed().connect(sigc::mem_fun(*this,&studio::Widget_Defaults::queue_draw));
340 synfigapp::Main::signal_bline_width_changed().connect(sigc::mem_fun(*this,&studio::Widget_Defaults::queue_draw));
342 if(App::dialog_gradient)
344 App::dialog_gradient->set_gradient(synfigapp::Main::get_gradient());
345 App::dialog_gradient->reset();
346 App::dialog_gradient->signal_edited().connect(sigc::mem_fun(synfigapp::Main::set_gradient));
349 if(App::dialog_color)
351 App::dialog_color->set_color(synfigapp::Main::get_outline_color());
352 App::dialog_color->reset();
353 App::dialog_color->signal_edited().connect(sigc::mem_fun(synfigapp::Main::set_outline_color));
358 Widget_Defaults::~Widget_Defaults()
363 Widget_Defaults::otln_color_refresh()
365 widget_otln_color->set_value(synfigapp::Main::get_outline_color());
369 Widget_Defaults::fill_color_refresh()
371 widget_fill_color->set_value(synfigapp::Main::get_fill_color());
375 Widget_Defaults::gradient_refresh()
377 widget_gradient->set_value(synfigapp::Main::get_gradient());
381 Widget_Defaults::bline_width_refresh()
383 widget_bline_width->set_value(synfigapp::Main::get_bline_width());
387 Widget_Defaults::blend_method_refresh()
389 widget_blend_method->set_value(synfigapp::Main::get_blend_method());
393 Widget_Defaults::interpolation_refresh()
395 widget_interpolation->set_value(synfigapp::Main::get_interpolation());
399 Widget_Defaults::opacity_refresh()
401 widget_opacity->set_value(synfigapp::Main::get_opacity());
405 Widget_Defaults::on_opacity_changed()
407 synfigapp::Main::set_opacity(widget_opacity->get_value());
411 Widget_Defaults::on_blend_method_changed()
413 synfigapp::Main::set_blend_method(Color::BlendMethod(widget_blend_method->get_value()));
417 Widget_Defaults::on_interpolation_changed()
419 synfigapp::Main::set_interpolation(Waypoint::Interpolation(widget_interpolation->get_value()));
423 Widget_Defaults::on_bline_width_changed()
425 synfigapp::Main::set_bline_width(widget_bline_width->get_value());
429 Widget_Defaults::on_otln_color_clicked()
431 // Left click on outline color
432 App::dialog_color->set_color(synfigapp::Main::get_outline_color());
433 App::dialog_color->reset();
434 App::dialog_color->signal_edited().connect(sigc::ptr_fun(synfigapp::Main::set_outline_color));
435 App::dialog_color->present();
439 Widget_Defaults::on_fill_color_clicked()
441 // Left click on fill color
442 App::dialog_color->set_color(synfigapp::Main::get_fill_color());
443 App::dialog_color->reset();
444 App::dialog_color->signal_edited().connect(sigc::ptr_fun(synfigapp::Main::set_fill_color));
445 App::dialog_color->present();
449 Widget_Defaults::on_swap_color_clicked()
451 synfigapp::Main::color_swap();
455 Widget_Defaults::on_reset_color_clicked()
457 synfigapp::Main::set_fill_color(Color::white());
458 synfigapp::Main::set_outline_color(Color::black());
462 Widget_Defaults::on_gradient_clicked()
464 App::dialog_gradient->set_gradient(synfigapp::Main::get_gradient());
465 App::dialog_gradient->reset();
466 App::dialog_gradient->signal_edited().connect(sigc::ptr_fun(synfigapp::Main::set_gradient));
467 App::dialog_gradient->grab_button_set_sensitive(false);
468 App::dialog_gradient->present();
473 Widget_Defaults::redraw(GdkEventExpose*bleh)
475 Glib::RefPtr<Gdk::GC> gc(Gdk::GC::create(get_window()));
477 const int h(get_height());
478 const int w(get_width());
479 const int size=std::min(h-GRADIENT_HEIGHT,w);
481 render_color_to_window(get_window(),Gdk::Rectangle(size/4,size/4,size/4*3-1,size/4*3-1),synfigapp::Main::get_fill_color());
482 render_color_to_window(get_window(),Gdk::Rectangle(0,0,size/4*3-1,size/4*3-1),synfigapp::Main::get_outline_color());
483 render_gradient_to_window(get_window(),Gdk::Rectangle(0,h-GRADIENT_HEIGHT,w,GRADIENT_HEIGHT-1),synfigapp::Main::get_gradient());
489 Glib::RefPtr<Pango::Layout> layout(Pango::Layout::create(get_pango_context()));
491 gc->set_rgb_fg_color(Gdk::Color("#FF0000"));
492 layout->set_text(synfigapp::Main::get_bline_width().get_string(2));
493 layout->set_alignment(Pango::ALIGN_CENTER);
494 layout->set_width(w/2);
495 get_window()->draw_layout(gc, w*3/4, (h-GRADIENT_HEIGHT)-16, layout);
501 Widget_Defaults::on_event(GdkEvent *event)
503 const int x(static_cast<int>(event->button.x));
504 const int y(static_cast<int>(event->button.y));
506 const int h(get_height());
507 const int w(get_width());
508 const int size=std::min(h-GRADIENT_HEIGHT,w);
512 case GDK_MOTION_NOTIFY:
514 case GDK_BUTTON_PRESS:
515 // if(event->button.button==1 && y>get_height()-CONTROL_HEIGHT)
517 case GDK_BUTTON_RELEASE:
518 if(event->button.button==1)
522 // Left click on gradient
523 App::dialog_gradient->set_gradient(synfigapp::Main::get_gradient());
524 App::dialog_gradient->reset();
525 App::dialog_gradient->signal_edited().connect(sigc::mem_fun(synfigapp::Main::set_gradient));
526 App::dialog_gradient->present();
531 if(x<size*3/4 && y<size*3/4)
533 // Left click on outline coloe
534 App::dialog_color->set_color(synfigapp::Main::get_outline_color());
535 App::dialog_color->reset();
536 App::dialog_color->signal_edited().connect(sigc::mem_fun(synfigapp::Main::set_outline_color));
537 App::dialog_color->present();
540 if(x>size*3/4 && y>size/4)
542 // Left click on fill color
543 App::dialog_color->set_color(synfigapp::Main::get_fill_color());
544 App::dialog_color->reset();
545 App::dialog_color->signal_edited().connect(sigc::mem_fun(synfigapp::Main::set_fill_color));
546 App::dialog_color->present();
550 if(x>size) // Left click on BLine Width
552 Distance dist(synfigapp::Main::get_bline_width());
554 if(y<size/2) // increase BLine size
556 dist+=DEFAULT_INCREMENT;
558 else // Decrease BLine size
560 dist-=DEFAULT_INCREMENT;
562 synfigapp::Main::set_bline_width(dist);
565 if(event->button.button==3)
569 // right click on gradient
570 synfigapp::Main::set_gradient_default_colors();
577 // right click on colors
578 synfigapp::Main::color_swap();
584 // right click on bline width
585 synfigapp::Main::set_bline_width(DEFAULT_WIDTH);
593 Distance dist(synfigapp::Main::get_bline_width());
595 if(event->scroll.direction==GDK_SCROLL_UP)
597 dist+=DEFAULT_INCREMENT;
599 else if(event->scroll.direction==GDK_SCROLL_DOWN)
601 dist-=DEFAULT_INCREMENT;
603 synfigapp::Main::set_bline_width(dist);