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("R")));
242 button_reset->show();
243 button_reset->set_relief(Gtk::RELIEF_NONE);
244 button_reset->set_border_width(0);
245 dynamic_cast<Gtk::Misc*>(button_reset->get_child())->set_padding(0,0);
246 //button_reset->set_size_request(16/3,16/3);
247 button_reset->signal_clicked().connect(sigc::mem_fun(*this,&Widget_Defaults::on_reset_color_clicked));
248 subtable->attach(*button_reset, 0,1, 2, 3, Gtk::SHRINK|Gtk::FILL, Gtk::SHRINK|Gtk::FILL, 0, 0);
249 tooltips_.set_tip(*button_reset,_("Reset Colors to Black and White"));
252 attach(*subtable, 0, 1, 0, 2, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 1, 1);
253 subtable->set_size_request(36,36);
254 subtable->set_homogeneous(true);
257 widget_brush=manage(new Widget_Brush());
258 widget_brush->show();
259 widget_brush->set_size_request(36,36);
260 attach(*widget_brush,1, 2, 0, 1, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 1, 1);
261 tooltips_.set_tip(*widget_brush,_("Brush Preview"));
263 widget_bline_width=manage(new Widget_Distance());
264 widget_bline_width->show();
265 bline_width_refresh();
266 widget_bline_width->set_digits(2);
267 widget_bline_width->set_range(0,10000000);
268 widget_bline_width->set_size_request(24,-1);
269 widget_bline_width->signal_value_changed().connect(sigc::mem_fun(*this,&studio::Widget_Defaults::on_bline_width_changed));
270 attach(*widget_bline_width,1, 2, 1, 2, Gtk::EXPAND|Gtk::FILL, Gtk::SHRINK|Gtk::FILL, 0, 0);
271 tooltips_.set_tip(*widget_bline_width,_("Brush Size"));
274 widget_blend_method=manage(new Widget_Enum());
275 widget_blend_method->show();
276 widget_blend_method->signal_activate().connect(sigc::mem_fun(*this,&studio::Widget_Defaults::on_blend_method_changed));
277 widget_blend_method->set_param_desc(ParamDesc(Color::BLEND_COMPOSITE,"blend_method"));
278 attach(*widget_blend_method,0, 2, 2, 3, Gtk::EXPAND|Gtk::FILL, Gtk::SHRINK|Gtk::FILL, 1, 1);
279 tooltips_.set_tip(*widget_blend_method,_("Default Blend Method"));
281 widget_interpolation=manage(new Widget_Enum());
282 widget_interpolation->show();
283 widget_interpolation->signal_activate().connect(sigc::mem_fun(*this,&studio::Widget_Defaults::on_interpolation_changed));
284 widget_interpolation->set_param_desc(
285 ParamDesc("interpolation")
287 .add_enum_value(INTERPOLATION_TCB,"auto",_("TCB"))
288 .add_enum_value(INTERPOLATION_CONSTANT,"constant",_("Constant"))
289 .add_enum_value(INTERPOLATION_HALT,"ease",_("Ease in/out"))
290 .add_enum_value(INTERPOLATION_LINEAR,"linear",_("Linear"))
292 attach(*widget_interpolation,0, 2, 5, 6, Gtk::EXPAND|Gtk::FILL, Gtk::SHRINK|Gtk::FILL, 1, 1);
293 tooltips_.set_tip(*widget_interpolation,_("Default Interpolation"));
295 widget_opacity=manage(new Gtk::HScale(0.0f,1.01f,0.01f));
296 widget_opacity->show();
297 widget_opacity->set_digits(2);
298 widget_opacity->set_value_pos(Gtk::POS_LEFT);
299 widget_opacity->signal_value_changed().connect(sigc::mem_fun(*this,&studio::Widget_Defaults::on_opacity_changed));
300 attach(*widget_opacity,0, 2, 3, 4, Gtk::EXPAND|Gtk::FILL, Gtk::SHRINK|Gtk::FILL, 1, 1);
301 tooltips_.set_tip(*widget_opacity,_("Default Opacity"));
303 widget_gradient=manage(new Widget_Gradient());
304 widget_gradient->show();
305 widget_gradient->set_size_request(-1,GRADIENT_HEIGHT);
306 widget_gradient->signal_clicked().connect(sigc::mem_fun(*this,&studio::Widget_Defaults::on_gradient_clicked));
307 attach(*widget_gradient,0, 2, 4, 5, Gtk::EXPAND|Gtk::FILL, Gtk::SHRINK|Gtk::FILL, 1, 1);
308 tooltips_.set_tip(*widget_gradient,_("Default Gradient"));
312 synfigapp::Main::signal_opacity_changed().connect(sigc::mem_fun(*this,&studio::Widget_Defaults::opacity_refresh));
313 synfigapp::Main::signal_bline_width_changed().connect(sigc::mem_fun(*this,&studio::Widget_Defaults::bline_width_refresh));
314 synfigapp::Main::signal_foreground_color_changed().connect(sigc::mem_fun(*this,&studio::Widget_Defaults::fg_color_refresh));
315 synfigapp::Main::signal_background_color_changed().connect(sigc::mem_fun(*this,&studio::Widget_Defaults::bg_color_refresh));
316 synfigapp::Main::signal_gradient_changed().connect(sigc::mem_fun(*this,&studio::Widget_Defaults::gradient_refresh));
317 synfigapp::Main::signal_blend_method_changed().connect(sigc::mem_fun(*this,&studio::Widget_Defaults::blend_method_refresh));
318 synfigapp::Main::signal_interpolation_changed().connect(sigc::mem_fun(*this,&studio::Widget_Defaults::interpolation_refresh));
323 blend_method_refresh();
325 interpolation_refresh();
327 set_size_request(48,48+GRADIENT_HEIGHT);
328 signal_expose_event().connect(sigc::mem_fun(*this, &studio::Widget_Defaults::redraw));
329 add_events(Gdk::BUTTON_PRESS_MASK | Gdk::BUTTON_RELEASE_MASK);
330 add_events(Gdk::BUTTON1_MOTION_MASK);
332 synfigapp::Main::signal_foreground_color_changed().connect(sigc::mem_fun(*this,&studio::Widget_Defaults::queue_draw));
333 synfigapp::Main::signal_background_color_changed().connect(sigc::mem_fun(*this,&studio::Widget_Defaults::queue_draw));
334 synfigapp::Main::signal_gradient_changed().connect(sigc::mem_fun(*this,&studio::Widget_Defaults::queue_draw));
335 synfigapp::Main::signal_bline_width_changed().connect(sigc::mem_fun(*this,&studio::Widget_Defaults::queue_draw));
337 if(App::dialog_gradient)
339 App::dialog_gradient->set_gradient(synfigapp::Main::get_gradient());
340 App::dialog_gradient->reset();
341 App::dialog_gradient->signal_edited().connect(sigc::mem_fun(synfigapp::Main::set_gradient));
344 if(App::dialog_color)
346 App::dialog_color->set_color(synfigapp::Main::get_foreground_color());
347 App::dialog_color->reset();
348 App::dialog_color->signal_edited().connect(sigc::mem_fun(synfigapp::Main::set_foreground_color));
353 Widget_Defaults::~Widget_Defaults()
358 Widget_Defaults::fg_color_refresh()
360 widget_fg_color->set_value(synfigapp::Main::get_foreground_color());
364 Widget_Defaults::bg_color_refresh()
366 widget_bg_color->set_value(synfigapp::Main::get_background_color());
370 Widget_Defaults::gradient_refresh()
372 widget_gradient->set_value(synfigapp::Main::get_gradient());
376 Widget_Defaults::bline_width_refresh()
378 widget_bline_width->set_value(synfigapp::Main::get_bline_width());
382 Widget_Defaults::blend_method_refresh()
384 widget_blend_method->set_value(synfigapp::Main::get_blend_method());
388 Widget_Defaults::interpolation_refresh()
390 widget_interpolation->set_value(synfigapp::Main::get_interpolation());
394 Widget_Defaults::opacity_refresh()
396 widget_opacity->set_value(synfigapp::Main::get_opacity());
400 Widget_Defaults::on_opacity_changed()
402 synfigapp::Main::set_opacity(widget_opacity->get_value());
406 Widget_Defaults::on_blend_method_changed()
408 synfigapp::Main::set_blend_method(Color::BlendMethod(widget_blend_method->get_value()));
412 Widget_Defaults::on_interpolation_changed()
414 synfigapp::Main::set_interpolation(Waypoint::Interpolation(widget_interpolation->get_value()));
418 Widget_Defaults::on_bline_width_changed()
420 synfigapp::Main::set_bline_width(widget_bline_width->get_value());
424 Widget_Defaults::on_fg_color_clicked()
426 // Left click on foreground
427 App::dialog_color->set_color(synfigapp::Main::get_foreground_color());
428 App::dialog_color->reset();
429 App::dialog_color->signal_edited().connect(sigc::ptr_fun(synfigapp::Main::set_foreground_color));
430 App::dialog_color->present();
434 Widget_Defaults::on_bg_color_clicked()
436 // Left click on background
437 App::dialog_color->set_color(synfigapp::Main::get_background_color());
438 App::dialog_color->reset();
439 App::dialog_color->signal_edited().connect(sigc::ptr_fun(synfigapp::Main::set_background_color));
440 App::dialog_color->present();
444 Widget_Defaults::on_swap_color_clicked()
446 synfigapp::Main::color_swap();
450 Widget_Defaults::on_reset_color_clicked()
452 synfigapp::Main::set_background_color(Color::white());
453 synfigapp::Main::set_foreground_color(Color::black());
457 Widget_Defaults::on_gradient_clicked()
459 App::dialog_gradient->set_gradient(synfigapp::Main::get_gradient());
460 App::dialog_gradient->reset();
461 App::dialog_gradient->signal_edited().connect(sigc::ptr_fun(synfigapp::Main::set_gradient));
462 App::dialog_gradient->present();
467 Widget_Defaults::redraw(GdkEventExpose*bleh)
469 Glib::RefPtr<Gdk::GC> gc(Gdk::GC::create(get_window()));
471 const int h(get_height());
472 const int w(get_width());
473 const int size=std::min(h-GRADIENT_HEIGHT,w);
475 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());
476 render_color_to_window(get_window(),Gdk::Rectangle(0,0,size/4*3-1,size/4*3-1),synfigapp::Main::get_foreground_color());
477 render_gradient_to_window(get_window(),Gdk::Rectangle(0,h-GRADIENT_HEIGHT,w,GRADIENT_HEIGHT-1),synfigapp::Main::get_gradient());
483 Glib::RefPtr<Pango::Layout> layout(Pango::Layout::create(get_pango_context()));
485 gc->set_rgb_fg_color(Gdk::Color("#FF0000"));
486 layout->set_text(synfigapp::Main::get_bline_width().get_string(2));
487 layout->set_alignment(Pango::ALIGN_CENTER);
488 layout->set_width(w/2);
489 get_window()->draw_layout(gc, w*3/4, (h-GRADIENT_HEIGHT)-16, layout);
495 Widget_Defaults::on_event(GdkEvent *event)
497 const int x(static_cast<int>(event->button.x));
498 const int y(static_cast<int>(event->button.y));
500 const int h(get_height());
501 const int w(get_width());
502 const int size=std::min(h-GRADIENT_HEIGHT,w);
506 case GDK_MOTION_NOTIFY:
508 case GDK_BUTTON_PRESS:
509 // if(event->button.button==1 && y>get_height()-CONTROL_HEIGHT)
511 case GDK_BUTTON_RELEASE:
512 if(event->button.button==1)
516 // Left click on gradient
517 App::dialog_gradient->set_gradient(synfigapp::Main::get_gradient());
518 App::dialog_gradient->reset();
519 App::dialog_gradient->signal_edited().connect(sigc::mem_fun(synfigapp::Main::set_gradient));
520 App::dialog_gradient->present();
525 if(x<size*3/4 && y<size*3/4)
527 // Left click on foreground
528 App::dialog_color->set_color(synfigapp::Main::get_foreground_color());
529 App::dialog_color->reset();
530 App::dialog_color->signal_edited().connect(sigc::mem_fun(synfigapp::Main::set_foreground_color));
531 App::dialog_color->present();
534 if(x>size*3/4 && y>size/4)
536 // Left click on background
537 App::dialog_color->set_color(synfigapp::Main::get_background_color());
538 App::dialog_color->reset();
539 App::dialog_color->signal_edited().connect(sigc::mem_fun(synfigapp::Main::set_background_color));
540 App::dialog_color->present();
544 if(x>size) // Left click on BLine Width
546 Distance dist(synfigapp::Main::get_bline_width());
548 if(y<size/2) // increase BLine size
550 dist+=DEFAULT_INCREMENT;
552 else // Decrease BLine size
554 dist-=DEFAULT_INCREMENT;
556 synfigapp::Main::set_bline_width(dist);
559 if(event->button.button==3)
563 // right click on gradient
564 synfigapp::Main::set_gradient_default_colors();
571 // right click on colors
572 synfigapp::Main::color_swap();
578 // right click on bline width
579 synfigapp::Main::set_bline_width(DEFAULT_WIDTH);
587 Distance dist(synfigapp::Main::get_bline_width());
589 if(event->scroll.direction==GDK_SCROLL_UP)
591 dist+=DEFAULT_INCREMENT;
593 else if(event->scroll.direction==GDK_SCROLL_DOWN)
595 dist-=DEFAULT_INCREMENT;
597 synfigapp::Main::set_bline_width(dist);