1 /* === S Y N F I G ========================================================= */
2 /*! \file dialog_color.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 "dialog_color.h"
33 #include "widget_color.h"
34 #include <synfig/general.h>
35 #include <synfigapp/main.h>
36 #include <gtkmm/button.h>
43 /* === U S I N G =========================================================== */
47 using namespace synfig;
48 using namespace studio;
50 /* === M A C R O S ========================================================= */
52 /* === G L O B A L S ======================================================= */
54 /* === P R O C E D U R E S ================================================= */
56 /* === M E T H O D S ======================================================= */
58 Dialog_Color::Dialog_Color():
59 Dialog(_("Colors"), false, true),
60 dialog_settings(this, "color"),
63 set_type_hint(Gdk::WINDOW_TYPE_HINT_UTILITY);
65 create_color_edit_widget();
66 create_set_color_button("synfig-set_outline_color", _("Set as Outline"), 0,
67 sigc::mem_fun(*this, &Dialog_Color::on_set_oc_pressed));
68 create_set_color_button("synfig-set_fill_color", _("Set as Fill"), 1,
69 sigc::mem_fun(*this, &Dialog_Color::on_set_fc_pressed));
70 create_close_button();
72 add_accel_group(App::ui_manager()->get_accel_group());
76 Dialog_Color::~Dialog_Color()
81 Dialog_Color::create_color_edit_widget()
83 color_edit_widget = manage(new Gtk::ColorSelection());
84 color_edit_widget->set_has_opacity_control(true);
85 color_edit_widget->signal_color_changed().connect(sigc::mem_fun(*this,
86 &studio::Dialog_Color::on_color_changed));
88 get_vbox()->pack_start(*color_edit_widget);
92 Dialog_Color::create_set_color_button(const char *stock_id,
93 const Glib::ustring& tip_text, int index,
94 const sigc::slot0<void>& callback)
96 Gtk::Button *set_color_button = manage(new Gtk::Button());
97 Gtk::Image *set_color_icon = manage(new Gtk::Image(Gtk::StockID(stock_id),
98 Gtk::IconSize::IconSize(Gtk::ICON_SIZE_BUTTON)));
99 set_color_button->add(*set_color_icon);
100 set_color_icon->show();
101 tooltips.set_tip(*set_color_button, tip_text);
102 set_color_button->show();
103 add_action_widget(*set_color_button, index);
104 set_color_button->signal_clicked().connect(callback);
108 Dialog_Color::create_close_button()
110 Gtk::Button *close_button(manage(new Gtk::Button(Gtk::StockID("gtk-close"))));
111 close_button->show();
112 add_action_widget(*close_button, 2);
113 close_button->signal_clicked().connect(sigc::hide_return(sigc::mem_fun(*this,
114 &Dialog_Color::on_close_pressed)));
115 signal_delete_event().connect(sigc::hide(sigc::mem_fun(*this,
116 &Dialog_Color::on_close_pressed)));
120 Dialog_Color::on_color_changed()
123 signal_edited_(get_color());
128 Dialog_Color::on_set_oc_pressed()
131 synfigapp::Main::set_outline_color(get_color());
136 Dialog_Color::on_set_fc_pressed()
139 synfigapp::Main::set_fill_color(get_color());
144 Dialog_Color::on_close_pressed()
154 Dialog_Color::set_color(const synfig::Color& color)
156 color_edit_widget->set_current_color(studio::colorconv_synfig2gdk(color));
157 color_edit_widget->set_current_alpha(color.get_a());
161 Dialog_Color::get_color() const
163 return studio::colorconv_gdk2synfig(color_edit_widget->get_current_color(), color_edit_widget->get_current_alpha() / 65535.0);
167 Dialog_Color::reset()
169 signal_edited_.clear();