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"
50 /* === U S I N G =========================================================== */
54 using namespace synfig;
55 using namespace studio;
57 /* === M A C R O S ========================================================= */
59 #define GRADIENT_HEIGHT 16
60 #define DEFAULT_INCREMENT (0.25)
61 #define DEFAULT_WIDTH (synfig::Distance(3,synfig::Distance::SYSTEM_POINTS))
63 /* === G L O B A L S ======================================================= */
65 class studio::Widget_Brush : public Gtk::DrawingArea
70 signal_expose_event().connect(sigc::mem_fun(*this, &studio::Widget_Brush::redraw));
72 set_size_request(24,24);
73 add_events(Gdk::BUTTON_PRESS_MASK | Gdk::BUTTON_RELEASE_MASK);
74 add_events(Gdk::BUTTON1_MOTION_MASK);
76 synfigapp::Main::signal_foreground_color_changed().connect(sigc::mem_fun(*this,&studio::Widget_Brush::queue_draw));
77 synfigapp::Main::signal_background_color_changed().connect(sigc::mem_fun(*this,&studio::Widget_Brush::queue_draw));
78 synfigapp::Main::signal_bline_width_changed().connect(sigc::mem_fun(*this,&studio::Widget_Brush::queue_draw));
79 studio::App::signal_instance_selected().connect(sigc::hide(sigc::mem_fun(*this,&studio::Widget_Brush::queue_draw)));
83 redraw(GdkEventExpose */*bleh*/)
85 Glib::RefPtr<Gdk::GC> gc(Gdk::GC::create(get_window()));
87 const int h(get_height());
88 const int w(get_width());
91 if(App::get_selected_canvas_view())
93 const RendDesc& rend_desc(App::get_selected_canvas_view()->get_canvas()->rend_desc());
94 pixelsize=synfigapp::Main::get_bline_width().get(Distance::SYSTEM_PIXELS,rend_desc);
99 pixelsize=synfigapp::Main::get_bline_width().get(Distance::SYSTEM_PIXELS,rend_desc);
101 // Fill in the background color
102 render_color_to_window(get_window(),Gdk::Rectangle(0,0,w,h),synfigapp::Main::get_background_color());
105 gc->set_rgb_fg_color(colorconv_synfig2gdk(synfigapp::Main::get_background_color()));
106 gc->set_line_attributes(1,Gdk::LINE_SOLID,Gdk::CAP_BUTT,Gdk::JOIN_MITER);
107 get_window()->draw_rectangle(
115 // Draw in the circle
116 gc->set_rgb_fg_color(colorconv_synfig2gdk(synfigapp::Main::get_foreground_color()));
117 gc->set_function(Gdk::COPY);
118 gc->set_line_attributes(1,Gdk::LINE_SOLID,Gdk::CAP_BUTT,Gdk::JOIN_MITER);
119 get_window()->draw_arc(
122 round_to_int(((float)w/2.0f)-pixelsize/2.0f),
123 round_to_int(((float)h/2.0f)-pixelsize/2.0f),
124 round_to_int(pixelsize+0.6),
125 round_to_int(pixelsize+0.6),
134 on_event(GdkEvent *event)
136 // const int x(static_cast<int>(event->button.x));
137 const int y(static_cast<int>(event->button.y));
139 const int h(get_height());
140 // const int w(get_width());
144 case GDK_MOTION_NOTIFY:
146 case GDK_BUTTON_RELEASE:
147 if(event->button.button==1) // Left click
149 Distance dist(synfigapp::Main::get_bline_width());
151 if(y<h/2) // increase BLine size
153 dist+=DEFAULT_INCREMENT;
155 else // Decrease BLine size
157 dist-=DEFAULT_INCREMENT;
159 synfigapp::Main::set_bline_width(dist);
162 if(event->button.button==3)
164 // right click on bline width
165 synfigapp::Main::set_bline_width(DEFAULT_WIDTH);
171 Distance dist(synfigapp::Main::get_bline_width());
173 switch(event->scroll.direction){
175 case GDK_SCROLL_RIGHT:
176 dist+=DEFAULT_INCREMENT;
178 case GDK_SCROLL_DOWN:
179 case GDK_SCROLL_LEFT:
180 dist-=DEFAULT_INCREMENT;
183 synfigapp::Main::set_bline_width(dist);
195 /* === P R O C E D U R E S ================================================= */
197 /* === M E T H O D S ======================================================= */
199 Widget_Defaults::Widget_Defaults()
201 //set_size_request(48,48+GRADIENT_HEIGHT+16);
202 //set_size_request(48,-1);
205 Gtk::Table* subtable(manage(new Gtk::Table()));
208 widget_fg_color=manage(new Widget_Color());
209 widget_fg_color->show();
210 widget_fg_color->set_size_request(16,16);
211 widget_fg_color->signal_clicked().connect(sigc::mem_fun(*this,&Widget_Defaults::on_fg_color_clicked));
212 subtable->attach(*widget_fg_color, 0, 2, 0, 2, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
213 tooltips_.set_tip(*widget_fg_color,_("Foreground Color"));
216 widget_bg_color=manage(new Widget_Color());
217 widget_bg_color->show();
218 widget_bg_color->set_size_request(16,16);
219 widget_bg_color->signal_clicked().connect(sigc::mem_fun(*this,&Widget_Defaults::on_bg_color_clicked));
220 subtable->attach(*widget_bg_color, 1, 3, 1, 3, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
221 tooltips_.set_tip(*widget_bg_color,_("Background Color"));
226 Gtk::Button* button_swap(manage(new Gtk::Button()));
228 button_swap->set_relief(Gtk::RELIEF_NONE);
229 button_swap->set_border_width(0);
230 icon=manage(new Gtk::Image(Gtk::StockID("synfig-swap_colors"),Gtk::IconSize(1)));
232 button_swap->add(*icon);
233 //button_swap->get_child()->set_size_request(16/3,16/3);
234 //button_swap->set_size_request(16/3,16/3);
235 dynamic_cast<Gtk::Misc*>(button_swap->get_child())->set_padding(0,0);
236 button_swap->signal_clicked().connect(sigc::mem_fun(*this,&Widget_Defaults::on_swap_color_clicked));
237 subtable->attach(*button_swap, 2, 3, 0, 1, Gtk::SHRINK|Gtk::FILL, Gtk::SHRINK|Gtk::FILL, 0, 0);
238 tooltips_.set_tip(*button_swap,_("Swap Background and\nForeground Colors"));
241 Gtk::Button* button_reset(manage(new Gtk::Button()));
242 button_reset->show();
243 button_reset->set_relief(Gtk::RELIEF_NONE);
244 button_reset->set_border_width(0);
245 icon=manage(new Gtk::Image(Gtk::StockID("synfig-reset_colors"),Gtk::IconSize(1)));
247 button_reset->add(*icon);
248 dynamic_cast<Gtk::Misc*>(button_reset->get_child())->set_padding(0,0);
249 //button_reset->set_size_request(16/3,16/3);
250 button_reset->signal_clicked().connect(sigc::mem_fun(*this,&Widget_Defaults::on_reset_color_clicked));
251 subtable->attach(*button_reset, 0,1, 2, 3, Gtk::SHRINK|Gtk::FILL, Gtk::SHRINK|Gtk::FILL, 0, 0);
252 tooltips_.set_tip(*button_reset,_("Reset Colors to Black and White"));
255 attach(*subtable, 0, 1, 0, 2, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 1, 1);
256 subtable->set_size_request(36,36);
257 subtable->set_homogeneous(true);
260 widget_brush=manage(new Widget_Brush());
261 widget_brush->show();
262 widget_brush->set_size_request(36,36);
263 attach(*widget_brush,1, 2, 0, 1, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 1, 1);
264 tooltips_.set_tip(*widget_brush,_("Brush Preview"));
266 widget_bline_width=manage(new Widget_Distance());
267 widget_bline_width->show();
268 bline_width_refresh();
269 widget_bline_width->set_digits(2);
270 widget_bline_width->set_range(0,10000000);
271 widget_bline_width->set_size_request(24,-1);
272 widget_bline_width->signal_value_changed().connect(sigc::mem_fun(*this,&studio::Widget_Defaults::on_bline_width_changed));
273 attach(*widget_bline_width,1, 2, 1, 2, Gtk::EXPAND|Gtk::FILL, Gtk::SHRINK|Gtk::FILL, 0, 0);
274 tooltips_.set_tip(*widget_bline_width,_("Brush Size"));
277 widget_blend_method=manage(new Widget_Enum());
278 widget_blend_method->show();
279 widget_blend_method->signal_activate().connect(sigc::mem_fun(*this,&studio::Widget_Defaults::on_blend_method_changed));
280 widget_blend_method->set_param_desc(ParamDesc(Color::BLEND_COMPOSITE,"blend_method"));
281 attach(*widget_blend_method,0, 2, 2, 3, Gtk::EXPAND|Gtk::FILL, Gtk::SHRINK|Gtk::FILL, 1, 1);
282 tooltips_.set_tip(*widget_blend_method,_("Default Blend Method"));
284 widget_interpolation=manage(new Widget_Enum());
285 widget_interpolation->show();
286 widget_interpolation->signal_activate().connect(sigc::mem_fun(*this,&studio::Widget_Defaults::on_interpolation_changed));
287 widget_interpolation->set_param_desc(
288 ParamDesc("interpolation")
290 .add_enum_value(INTERPOLATION_TCB,"auto",_("_TCB"))
291 .add_enum_value(INTERPOLATION_CONSTANT,"constant",_("_Constant"))
292 .add_enum_value(INTERPOLATION_HALT,"ease",_("_Ease In/Out"))
293 .add_enum_value(INTERPOLATION_LINEAR,"linear",_("_Linear"))
295 attach(*widget_interpolation,0, 2, 5, 6, Gtk::EXPAND|Gtk::FILL, Gtk::SHRINK|Gtk::FILL, 1, 1);
296 tooltips_.set_tip(*widget_interpolation,_("Default Interpolation"));
298 widget_opacity=manage(new Gtk::HScale(0.0f,1.01f,0.01f));
299 widget_opacity->show();
300 widget_opacity->set_digits(2);
301 widget_opacity->set_value_pos(Gtk::POS_LEFT);
302 widget_opacity->signal_value_changed().connect(sigc::mem_fun(*this,&studio::Widget_Defaults::on_opacity_changed));
303 attach(*widget_opacity,0, 2, 3, 4, Gtk::EXPAND|Gtk::FILL, Gtk::SHRINK|Gtk::FILL, 1, 1);
304 tooltips_.set_tip(*widget_opacity,_("Default Opacity"));
306 widget_gradient=manage(new Widget_Gradient());
307 widget_gradient->show();
308 widget_gradient->set_size_request(-1,GRADIENT_HEIGHT);
309 widget_gradient->signal_clicked().connect(sigc::mem_fun(*this,&studio::Widget_Defaults::on_gradient_clicked));
310 attach(*widget_gradient,0, 2, 4, 5, Gtk::EXPAND|Gtk::FILL, Gtk::SHRINK|Gtk::FILL, 1, 1);
311 tooltips_.set_tip(*widget_gradient,_("Default Gradient"));
315 synfigapp::Main::signal_opacity_changed().connect(sigc::mem_fun(*this,&studio::Widget_Defaults::opacity_refresh));
316 synfigapp::Main::signal_bline_width_changed().connect(sigc::mem_fun(*this,&studio::Widget_Defaults::bline_width_refresh));
317 synfigapp::Main::signal_foreground_color_changed().connect(sigc::mem_fun(*this,&studio::Widget_Defaults::fg_color_refresh));
318 synfigapp::Main::signal_background_color_changed().connect(sigc::mem_fun(*this,&studio::Widget_Defaults::bg_color_refresh));
319 synfigapp::Main::signal_gradient_changed().connect(sigc::mem_fun(*this,&studio::Widget_Defaults::gradient_refresh));
320 synfigapp::Main::signal_blend_method_changed().connect(sigc::mem_fun(*this,&studio::Widget_Defaults::blend_method_refresh));
321 synfigapp::Main::signal_interpolation_changed().connect(sigc::mem_fun(*this,&studio::Widget_Defaults::interpolation_refresh));
326 blend_method_refresh();
328 interpolation_refresh();
330 set_size_request(48,48+GRADIENT_HEIGHT);
331 signal_expose_event().connect(sigc::mem_fun(*this, &studio::Widget_Defaults::redraw));
332 add_events(Gdk::BUTTON_PRESS_MASK | Gdk::BUTTON_RELEASE_MASK);
333 add_events(Gdk::BUTTON1_MOTION_MASK);
335 synfigapp::Main::signal_foreground_color_changed().connect(sigc::mem_fun(*this,&studio::Widget_Defaults::queue_draw));
336 synfigapp::Main::signal_background_color_changed().connect(sigc::mem_fun(*this,&studio::Widget_Defaults::queue_draw));
337 synfigapp::Main::signal_gradient_changed().connect(sigc::mem_fun(*this,&studio::Widget_Defaults::queue_draw));
338 synfigapp::Main::signal_bline_width_changed().connect(sigc::mem_fun(*this,&studio::Widget_Defaults::queue_draw));
340 if(App::dialog_gradient)
342 App::dialog_gradient->set_gradient(synfigapp::Main::get_gradient());
343 App::dialog_gradient->reset();
344 App::dialog_gradient->signal_edited().connect(sigc::mem_fun(synfigapp::Main::set_gradient));
347 if(App::dialog_color)
349 App::dialog_color->set_color(synfigapp::Main::get_foreground_color());
350 App::dialog_color->reset();
351 App::dialog_color->signal_edited().connect(sigc::mem_fun(synfigapp::Main::set_foreground_color));
356 Widget_Defaults::~Widget_Defaults()
361 Widget_Defaults::fg_color_refresh()
363 widget_fg_color->set_value(synfigapp::Main::get_foreground_color());
367 Widget_Defaults::bg_color_refresh()
369 widget_bg_color->set_value(synfigapp::Main::get_background_color());
373 Widget_Defaults::gradient_refresh()
375 widget_gradient->set_value(synfigapp::Main::get_gradient());
379 Widget_Defaults::bline_width_refresh()
381 widget_bline_width->set_value(synfigapp::Main::get_bline_width());
385 Widget_Defaults::blend_method_refresh()
387 widget_blend_method->set_value(synfigapp::Main::get_blend_method());
391 Widget_Defaults::interpolation_refresh()
393 widget_interpolation->set_value(synfigapp::Main::get_interpolation());
397 Widget_Defaults::opacity_refresh()
399 widget_opacity->set_value(synfigapp::Main::get_opacity());
403 Widget_Defaults::on_opacity_changed()
405 synfigapp::Main::set_opacity(widget_opacity->get_value());
409 Widget_Defaults::on_blend_method_changed()
411 synfigapp::Main::set_blend_method(Color::BlendMethod(widget_blend_method->get_value()));
415 Widget_Defaults::on_interpolation_changed()
417 synfigapp::Main::set_interpolation(Waypoint::Interpolation(widget_interpolation->get_value()));
421 Widget_Defaults::on_bline_width_changed()
423 synfigapp::Main::set_bline_width(widget_bline_width->get_value());
427 Widget_Defaults::on_fg_color_clicked()
429 // Left click on foreground
430 App::dialog_color->set_color(synfigapp::Main::get_foreground_color());
431 App::dialog_color->reset();
432 App::dialog_color->signal_edited().connect(sigc::ptr_fun(synfigapp::Main::set_foreground_color));
433 App::dialog_color->present();
437 Widget_Defaults::on_bg_color_clicked()
439 // Left click on background
440 App::dialog_color->set_color(synfigapp::Main::get_background_color());
441 App::dialog_color->reset();
442 App::dialog_color->signal_edited().connect(sigc::ptr_fun(synfigapp::Main::set_background_color));
443 App::dialog_color->present();
447 Widget_Defaults::on_swap_color_clicked()
449 synfigapp::Main::color_swap();
453 Widget_Defaults::on_reset_color_clicked()
455 synfigapp::Main::set_background_color(Color::white());
456 synfigapp::Main::set_foreground_color(Color::black());
460 Widget_Defaults::on_gradient_clicked()
462 App::dialog_gradient->set_gradient(synfigapp::Main::get_gradient());
463 App::dialog_gradient->reset();
464 App::dialog_gradient->signal_edited().connect(sigc::ptr_fun(synfigapp::Main::set_gradient));
465 App::dialog_gradient->present();
470 Widget_Defaults::redraw(GdkEventExpose*bleh)
472 Glib::RefPtr<Gdk::GC> gc(Gdk::GC::create(get_window()));
474 const int h(get_height());
475 const int w(get_width());
476 const int size=std::min(h-GRADIENT_HEIGHT,w);
478 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());
479 render_color_to_window(get_window(),Gdk::Rectangle(0,0,size/4*3-1,size/4*3-1),synfigapp::Main::get_foreground_color());
480 render_gradient_to_window(get_window(),Gdk::Rectangle(0,h-GRADIENT_HEIGHT,w,GRADIENT_HEIGHT-1),synfigapp::Main::get_gradient());
486 Glib::RefPtr<Pango::Layout> layout(Pango::Layout::create(get_pango_context()));
488 gc->set_rgb_fg_color(Gdk::Color("#FF0000"));
489 layout->set_text(synfigapp::Main::get_bline_width().get_string(2));
490 layout->set_alignment(Pango::ALIGN_CENTER);
491 layout->set_width(w/2);
492 get_window()->draw_layout(gc, w*3/4, (h-GRADIENT_HEIGHT)-16, layout);
498 Widget_Defaults::on_event(GdkEvent *event)
500 const int x(static_cast<int>(event->button.x));
501 const int y(static_cast<int>(event->button.y));
503 const int h(get_height());
504 const int w(get_width());
505 const int size=std::min(h-GRADIENT_HEIGHT,w);
509 case GDK_MOTION_NOTIFY:
511 case GDK_BUTTON_PRESS:
512 // if(event->button.button==1 && y>get_height()-CONTROL_HEIGHT)
514 case GDK_BUTTON_RELEASE:
515 if(event->button.button==1)
519 // Left click on gradient
520 App::dialog_gradient->set_gradient(synfigapp::Main::get_gradient());
521 App::dialog_gradient->reset();
522 App::dialog_gradient->signal_edited().connect(sigc::mem_fun(synfigapp::Main::set_gradient));
523 App::dialog_gradient->present();
528 if(x<size*3/4 && y<size*3/4)
530 // Left click on foreground
531 App::dialog_color->set_color(synfigapp::Main::get_foreground_color());
532 App::dialog_color->reset();
533 App::dialog_color->signal_edited().connect(sigc::mem_fun(synfigapp::Main::set_foreground_color));
534 App::dialog_color->present();
537 if(x>size*3/4 && y>size/4)
539 // Left click on background
540 App::dialog_color->set_color(synfigapp::Main::get_background_color());
541 App::dialog_color->reset();
542 App::dialog_color->signal_edited().connect(sigc::mem_fun(synfigapp::Main::set_background_color));
543 App::dialog_color->present();
547 if(x>size) // Left click on BLine Width
549 Distance dist(synfigapp::Main::get_bline_width());
551 if(y<size/2) // increase BLine size
553 dist+=DEFAULT_INCREMENT;
555 else // Decrease BLine size
557 dist-=DEFAULT_INCREMENT;
559 synfigapp::Main::set_bline_width(dist);
562 if(event->button.button==3)
566 // right click on gradient
567 synfigapp::Main::set_gradient_default_colors();
574 // right click on colors
575 synfigapp::Main::color_swap();
581 // right click on bline width
582 synfigapp::Main::set_bline_width(DEFAULT_WIDTH);
590 Distance dist(synfigapp::Main::get_bline_width());
592 if(event->scroll.direction==GDK_SCROLL_UP)
594 dist+=DEFAULT_INCREMENT;
596 else if(event->scroll.direction==GDK_SCROLL_DOWN)
598 dist-=DEFAULT_INCREMENT;
600 synfigapp::Main::set_bline_width(dist);