1 /* === S Y N F I G ========================================================= */
2 /*! \file widget_defaults.cpp
3 ** \brief Template File
5 ** $Id: widget_defaults.cpp,v 1.1.1.1 2005/01/07 03:34:37 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 "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 widget_bline_width->set_digits(2);
262 widget_bline_width->set_size_request(24,-1);
263 widget_bline_width->signal_value_changed().connect(sigc::mem_fun(*this,&studio::Widget_Defaults::on_bline_width_changed));
264 attach(*widget_bline_width,1, 2, 1, 2, Gtk::EXPAND|Gtk::FILL, Gtk::SHRINK|Gtk::FILL, 0, 0);
265 tooltips_.set_tip(*widget_bline_width,_("Brush Size"));
268 widget_blend_method=manage(new Widget_Enum());
269 widget_blend_method->show();
270 widget_blend_method->signal_activate().connect(sigc::mem_fun(*this,&studio::Widget_Defaults::on_blend_method_changed));
271 widget_blend_method->set_param_desc(ParamDesc(Color::BLEND_COMPOSITE,"blend_method"));
272 attach(*widget_blend_method,0, 2, 2, 3, Gtk::EXPAND|Gtk::FILL, Gtk::SHRINK|Gtk::FILL, 1, 1);
273 tooltips_.set_tip(*widget_blend_method,_("Default Blend Method"));
275 widget_interpolation=manage(new Widget_Enum());
276 widget_interpolation->show();
277 widget_interpolation->signal_activate().connect(sigc::mem_fun(*this,&studio::Widget_Defaults::on_interpolation_changed));
278 widget_interpolation->set_param_desc(
279 ParamDesc("interpolation")
281 .add_enum_value(INTERPOLATION_TCB,"auto",_("TBC"))
282 .add_enum_value(INTERPOLATION_CONSTANT,"constant",_("Constant"))
283 .add_enum_value(INTERPOLATION_HALT,"ease",_("Ease in/out"))
284 .add_enum_value(INTERPOLATION_LINEAR,"linear",_("Linear"))
286 attach(*widget_interpolation,0, 2, 5, 6, Gtk::EXPAND|Gtk::FILL, Gtk::SHRINK|Gtk::FILL, 1, 1);
287 tooltips_.set_tip(*widget_interpolation,_("Default Interpolation"));
289 widget_opacity=manage(new Gtk::HScale(0.0f,1.01f,0.01f));
290 widget_opacity->show();
291 widget_opacity->set_digits(2);
292 widget_opacity->set_value_pos(Gtk::POS_LEFT);
293 widget_opacity->signal_value_changed().connect(sigc::mem_fun(*this,&studio::Widget_Defaults::on_opacity_changed));
294 attach(*widget_opacity,0, 2, 3, 4, Gtk::EXPAND|Gtk::FILL, Gtk::SHRINK|Gtk::FILL, 1, 1);
295 tooltips_.set_tip(*widget_opacity,_("Default Opacity"));
297 widget_gradient=manage(new Widget_Gradient());
298 widget_gradient->show();
299 widget_gradient->set_size_request(-1,GRADIENT_HEIGHT);
300 widget_gradient->signal_clicked().connect(sigc::mem_fun(*this,&studio::Widget_Defaults::on_gradient_clicked));
301 attach(*widget_gradient,0, 2, 4, 5, Gtk::EXPAND|Gtk::FILL, Gtk::SHRINK|Gtk::FILL, 1, 1);
302 tooltips_.set_tip(*widget_gradient,_("Default Gradient"));
306 synfigapp::Main::signal_opacity_changed().connect(sigc::mem_fun(*this,&studio::Widget_Defaults::opacity_refresh));
307 synfigapp::Main::signal_bline_width_changed().connect(sigc::mem_fun(*this,&studio::Widget_Defaults::bline_width_refresh));
308 synfigapp::Main::signal_foreground_color_changed().connect(sigc::mem_fun(*this,&studio::Widget_Defaults::fg_color_refresh));
309 synfigapp::Main::signal_background_color_changed().connect(sigc::mem_fun(*this,&studio::Widget_Defaults::bg_color_refresh));
310 synfigapp::Main::signal_gradient_changed().connect(sigc::mem_fun(*this,&studio::Widget_Defaults::gradient_refresh));
311 synfigapp::Main::signal_blend_method_changed().connect(sigc::mem_fun(*this,&studio::Widget_Defaults::blend_method_refresh));
312 synfigapp::Main::signal_interpolation_changed().connect(sigc::mem_fun(*this,&studio::Widget_Defaults::interpolation_refresh));
317 bline_width_refresh();
318 blend_method_refresh();
320 interpolation_refresh();
322 set_size_request(48,48+GRADIENT_HEIGHT);
323 signal_expose_event().connect(sigc::mem_fun(*this, &studio::Widget_Defaults::redraw));
324 add_events(Gdk::BUTTON_PRESS_MASK | Gdk::BUTTON_RELEASE_MASK);
325 add_events(Gdk::BUTTON1_MOTION_MASK);
327 synfigapp::Main::signal_foreground_color_changed().connect(sigc::mem_fun(*this,&studio::Widget_Defaults::queue_draw));
328 synfigapp::Main::signal_background_color_changed().connect(sigc::mem_fun(*this,&studio::Widget_Defaults::queue_draw));
329 synfigapp::Main::signal_gradient_changed().connect(sigc::mem_fun(*this,&studio::Widget_Defaults::queue_draw));
330 synfigapp::Main::signal_bline_width_changed().connect(sigc::mem_fun(*this,&studio::Widget_Defaults::queue_draw));
332 if(App::dialog_gradient)
334 App::dialog_gradient->set_gradient(synfigapp::Main::get_gradient());
335 App::dialog_gradient->reset();
336 App::dialog_gradient->signal_edited().connect(sigc::mem_fun(synfigapp::Main::set_gradient));
339 if(App::dialog_color)
341 App::dialog_color->set_color(synfigapp::Main::get_foreground_color());
342 App::dialog_color->reset();
343 App::dialog_color->signal_edited().connect(sigc::mem_fun(synfigapp::Main::set_foreground_color));
348 Widget_Defaults::~Widget_Defaults()
353 Widget_Defaults::fg_color_refresh()
355 widget_fg_color->set_value(synfigapp::Main::get_foreground_color());
359 Widget_Defaults::bg_color_refresh()
361 widget_bg_color->set_value(synfigapp::Main::get_background_color());
365 Widget_Defaults::gradient_refresh()
367 widget_gradient->set_value(synfigapp::Main::get_gradient());
371 Widget_Defaults::bline_width_refresh()
373 widget_bline_width->set_value(synfigapp::Main::get_bline_width());
377 Widget_Defaults::blend_method_refresh()
379 widget_blend_method->set_value(synfigapp::Main::get_blend_method());
383 Widget_Defaults::interpolation_refresh()
385 widget_interpolation->set_value(synfigapp::Main::get_interpolation());
389 Widget_Defaults::opacity_refresh()
391 widget_opacity->set_value(synfigapp::Main::get_opacity());
395 Widget_Defaults::on_opacity_changed()
397 synfigapp::Main::set_opacity(widget_opacity->get_value());
401 Widget_Defaults::on_blend_method_changed()
403 synfigapp::Main::set_blend_method(Color::BlendMethod(widget_blend_method->get_value()));
407 Widget_Defaults::on_interpolation_changed()
409 synfigapp::Main::set_interpolation(Waypoint::Interpolation(widget_interpolation->get_value()));
413 Widget_Defaults::on_bline_width_changed()
415 synfigapp::Main::set_bline_width(widget_bline_width->get_value());
419 Widget_Defaults::on_fg_color_clicked()
421 // Left click on foreground
422 App::dialog_color->set_color(synfigapp::Main::get_foreground_color());
423 App::dialog_color->reset();
424 App::dialog_color->signal_edited().connect(sigc::ptr_fun(synfigapp::Main::set_foreground_color));
425 App::dialog_color->present();
429 Widget_Defaults::on_bg_color_clicked()
431 // Left click on background
432 App::dialog_color->set_color(synfigapp::Main::get_background_color());
433 App::dialog_color->reset();
434 App::dialog_color->signal_edited().connect(sigc::ptr_fun(synfigapp::Main::set_background_color));
435 App::dialog_color->present();
439 Widget_Defaults::on_swap_color_clicked()
441 synfigapp::Main::color_swap();
445 Widget_Defaults::on_reset_color_clicked()
447 synfigapp::Main::set_background_color(Color::white());
448 synfigapp::Main::set_foreground_color(Color::black());
452 Widget_Defaults::on_gradient_clicked()
454 App::dialog_gradient->set_gradient(synfigapp::Main::get_gradient());
455 App::dialog_gradient->reset();
456 App::dialog_gradient->signal_edited().connect(sigc::ptr_fun(synfigapp::Main::set_gradient));
457 App::dialog_gradient->present();
462 Widget_Defaults::redraw(GdkEventExpose*bleh)
464 Glib::RefPtr<Gdk::GC> gc(Gdk::GC::create(get_window()));
466 const int h(get_height());
467 const int w(get_width());
468 const int size=std::min(h-GRADIENT_HEIGHT,w);
470 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());
471 render_color_to_window(get_window(),Gdk::Rectangle(0,0,size/4*3-1,size/4*3-1),synfigapp::Main::get_foreground_color());
472 render_gradient_to_window(get_window(),Gdk::Rectangle(0,h-GRADIENT_HEIGHT,w,GRADIENT_HEIGHT-1),synfigapp::Main::get_gradient());
478 Glib::RefPtr<Pango::Layout> layout(Pango::Layout::create(get_pango_context()));
480 gc->set_rgb_fg_color(Gdk::Color("#FF0000"));
481 layout->set_text(synfigapp::Main::get_bline_width().get_string(2));
482 layout->set_alignment(Pango::ALIGN_CENTER);
483 layout->set_width(w/2);
484 get_window()->draw_layout(gc, w*3/4, (h-GRADIENT_HEIGHT)-16, layout);
490 Widget_Defaults::on_event(GdkEvent *event)
492 const int x(static_cast<int>(event->button.x));
493 const int y(static_cast<int>(event->button.y));
495 const int h(get_height());
496 const int w(get_width());
497 const int size=std::min(h-GRADIENT_HEIGHT,w);
501 case GDK_MOTION_NOTIFY:
503 case GDK_BUTTON_PRESS:
504 // if(event->button.button==1 && y>get_height()-CONTROL_HEIGHT)
506 case GDK_BUTTON_RELEASE:
507 if(event->button.button==1)
511 // Left click on gradient
512 App::dialog_gradient->set_gradient(synfigapp::Main::get_gradient());
513 App::dialog_gradient->reset();
514 App::dialog_gradient->signal_edited().connect(sigc::mem_fun(synfigapp::Main::set_gradient));
515 App::dialog_gradient->present();
520 if(x<size*3/4 && y<size*3/4)
522 // Left click on foreground
523 App::dialog_color->set_color(synfigapp::Main::get_foreground_color());
524 App::dialog_color->reset();
525 App::dialog_color->signal_edited().connect(sigc::mem_fun(synfigapp::Main::set_foreground_color));
526 App::dialog_color->present();
529 if(x>size*3/4 && y>size/4)
531 // Left click on background
532 App::dialog_color->set_color(synfigapp::Main::get_background_color());
533 App::dialog_color->reset();
534 App::dialog_color->signal_edited().connect(sigc::mem_fun(synfigapp::Main::set_background_color));
535 App::dialog_color->present();
539 if(x>size) // Left click on BLine Width
541 Distance dist(synfigapp::Main::get_bline_width());
543 if(y<size/2) // increase BLine size
545 dist+=DEFAULT_INCREMENT;
547 else // Decrease BLine size
549 dist-=DEFAULT_INCREMENT;
551 synfigapp::Main::set_bline_width(dist);
554 if(event->button.button==3)
558 // right click on gradient
559 synfigapp::Main::set_gradient_default_colors();
566 // right click on colors
567 synfigapp::Main::color_swap();
573 // right click on bline width
574 synfigapp::Main::set_bline_width(DEFAULT_WIDTH);
582 Distance dist(synfigapp::Main::get_bline_width());
584 if(event->scroll.direction==GDK_SCROLL_UP)
586 dist+=DEFAULT_INCREMENT;
588 else if(event->scroll.direction==GDK_SCROLL_DOWN)
590 dist-=DEFAULT_INCREMENT;
592 synfigapp::Main::set_bline_width(dist);