1 /* === S Y N F I G ========================================================= */
2 /*! \file dialog_gradient.cpp
3 ** \brief Template File
5 ** $Id: dialog_gradient.cpp,v 1.1.1.1 2005/01/07 03:34:36 darco Exp $
8 ** Copyright (c) 2002 Robert B. Quattlebaum Jr.
10 ** This software and associated documentation
11 ** are CONFIDENTIAL and PROPRIETARY property of
12 ** the above-mentioned copyright holder.
14 ** You may not copy, print, publish, or in any
15 ** other way distribute this software without
16 ** a prior written agreement with
17 ** the copyright holder.
20 /* ========================================================================= */
22 /* === H E A D E R S ======================================================= */
31 #include "dialog_gradient.h"
32 #include "widget_gradient.h"
33 #include <gtkmm/frame.h>
34 #include <gtkmm/table.h>
35 #include <gtkmm/label.h>
36 #include <synfig/general.h>
37 #include <synfigapp/canvasinterface.h>
38 #include <synfigapp/value_desc.h>
39 #include <synfigapp/main.h>
40 #include "widget_color.h"
41 #include <gtkmm/spinbutton.h>
46 /* === U S I N G =========================================================== */
50 using namespace synfig;
51 using namespace studio;
53 /* === M A C R O S ========================================================= */
55 /* === G L O B A L S ======================================================= */
57 /* === P R O C E D U R E S ================================================= */
59 /* === M E T H O D S ======================================================= */
61 Dialog_Gradient::Dialog_Gradient():
62 Dialog(_("Gradient Editor"),false,true),
63 dialog_settings(this,"gradient"),
64 adjustment_pos(0,0.0,1.0,0.001,0.001,0.001)
66 set_type_hint(Gdk::WINDOW_TYPE_HINT_DIALOG);
68 set_keep_above(false);
70 set_role("gradient_editor");
73 Gtk::Button *grab_button(manage(new class Gtk::Button(Gtk::StockID("Grab"))));
75 add_action_widget(*grab_button,2);
76 grab_button->signal_clicked().connect(sigc::mem_fun(*this, &Dialog_Gradient::on_grab_pressed));
79 Gtk::Button *apply_button(manage(new class Gtk::Button(Gtk::StockID("gtk-apply"))));
81 add_action_widget(*apply_button,1);
82 apply_button->signal_clicked().connect(sigc::mem_fun(*this, &Dialog_Gradient::on_apply_pressed));
85 Gtk::Button *cancel_button(manage(new class Gtk::Button(Gtk::StockID("gtk-close"))));
86 cancel_button->show();
87 add_action_widget(*cancel_button,0);
88 cancel_button->signal_clicked().connect(sigc::mem_fun(*this, &Dialog_Gradient::hide));
90 Gtk::Table* table(manage(new Gtk::Table(2,2,false)));
91 get_vbox()->pack_start(*table);
93 widget_gradient=manage(new Widget_Gradient());
94 widget_gradient->set_editable();
95 widget_gradient->signal_cpoint_selected().connect(sigc::mem_fun(*this,&studio::Dialog_Gradient::on_cpoint_selected));
96 widget_gradient->signal_value_changed().connect(sigc::mem_fun(*this,&studio::Dialog_Gradient::on_changed));
97 //table->attach(*manage(new Gtk::Label(_("Not yet fully implemented"))), 0, 1, 0, 1, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
98 table->attach(*widget_gradient, 0, 1, 2, 3, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
100 widget_color=manage(new Widget_ColorEdit());
101 widget_color->signal_value_changed().connect(sigc::mem_fun(*this,&studio::Dialog_Gradient::on_values_adjusted));
102 widget_color->signal_value_changed().connect(sigc::mem_fun(*this,&studio::Dialog_Gradient::on_changed));
103 widget_color->signal_activated().connect(sigc::mem_fun(*this,&studio::Dialog_Gradient::on_values_adjusted));
104 table->attach(*widget_color, 0, 1, 0, 1, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
107 spinbutton_pos=manage(new class Gtk::SpinButton(adjustment_pos,0.0001,4));
108 spinbutton_pos->set_update_policy(Gtk::UPDATE_ALWAYS);
109 adjustment_pos.signal_value_changed().connect(sigc::mem_fun(*this,&studio::Dialog_Gradient::on_values_adjusted));
110 adjustment_pos.signal_value_changed().connect(sigc::mem_fun(*this,&studio::Dialog_Gradient::on_changed));
111 table->attach(*spinbutton_pos, 0, 1, 1, 2, Gtk::SHRINK|Gtk::FILL, Gtk::SHRINK|Gtk::FILL, 0, 0);
114 add_accel_group(App::ui_manager()->get_accel_group());
119 Dialog_Gradient::~Dialog_Gradient()
124 Dialog_Gradient::set_gradient(const synfig::Gradient& x)
126 widget_gradient->set_value(x);
130 Dialog_Gradient::reset()
132 value_changed_connection.disconnect();
133 signal_edited_.clear();
137 Dialog_Gradient::on_grab_pressed()
139 synfigapp::Main::set_gradient(get_gradient());
140 // signal_edited_(get_gradient());
146 Dialog_Gradient::on_apply_pressed()
148 signal_edited_(get_gradient());
152 Dialog_Gradient::on_changed()
154 signal_edited_(get_gradient());
158 Dialog_Gradient::on_cpoint_selected(synfig::Gradient::CPoint x)
160 widget_color->set_value(x.color);
161 adjustment_pos.set_value(x.pos);
165 Dialog_Gradient::on_values_adjusted()
167 synfig::Gradient::CPoint x(widget_gradient->get_selected_cpoint());
168 x.color=widget_color->get_value();
169 x.pos=adjustment_pos.get_value();
170 widget_gradient->update_cpoint(x);
174 dialog_gradient_value_desc_edit(synfig::Gradient g,synfigapp::ValueDesc x,handle<synfigapp::CanvasInterface> canvas_interface)
176 // canvas_interface->connect_value(x,ValueBase(g));
180 Dialog_Gradient::edit(const synfigapp::ValueDesc &x, etl::handle<synfigapp::CanvasInterface> canvas_interface, synfig::Time time)
184 set_gradient(x.get_value().get(Gradient()));
185 else if(x.is_value_node())
186 set_gradient((*x.get_value_node())(time).get(Gradient()));
188 signal_edited().connect(
191 sigc::ptr_fun(dialog_gradient_value_desc_edit),