Fix bugs in previous commit that caused FTBFS in synfig and ETL FTBFS with older...
[synfig.git] / synfig-studio / tags / synfigstudio_0_61_03 / synfig-studio / src / gtkmm / dialog_gradient.cpp
1 /* === S Y N F I G ========================================================= */
2 /*!     \file dialog_gradient.cpp
3 **      \brief Template File
4 **
5 **      $Id: dialog_gradient.cpp,v 1.1.1.1 2005/01/07 03:34:36 darco Exp $
6 **
7 **      \legal
8 **      Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
9 **
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.
14 **
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.
19 **      \endlegal
20 */
21 /* ========================================================================= */
22
23 /* === H E A D E R S ======================================================= */
24
25 #ifdef USING_PCH
26 #       include "pch.h"
27 #else
28 #ifdef HAVE_CONFIG_H
29 #       include <config.h>
30 #endif
31
32 #include "dialog_gradient.h"
33 #include "widget_gradient.h"
34 #include <gtkmm/frame.h>
35 #include <gtkmm/table.h>
36 #include <gtkmm/label.h>
37 #include <synfig/general.h>
38 #include <synfigapp/canvasinterface.h>
39 #include <synfigapp/value_desc.h>
40 #include <synfigapp/main.h>
41 #include "widget_color.h"
42 #include <gtkmm/spinbutton.h>
43 #include "app.h"
44
45 #endif
46
47 /* === U S I N G =========================================================== */
48
49 using namespace std;
50 using namespace etl;
51 using namespace synfig;
52 using namespace studio;
53
54 /* === M A C R O S ========================================================= */
55
56 /* === G L O B A L S ======================================================= */
57
58 /* === P R O C E D U R E S ================================================= */
59
60 /* === M E T H O D S ======================================================= */
61
62 Dialog_Gradient::Dialog_Gradient():
63         Dialog(_("Gradient Editor"),false,true),
64         dialog_settings(this,"gradient"),
65         adjustment_pos(0,0.0,1.0,0.001,0.001,0.001)
66 {
67         set_type_hint(Gdk::WINDOW_TYPE_HINT_DIALOG);
68         set_keep_below(true);
69         set_keep_above(false);
70
71         set_role("gradient_editor");
72         
73         // Setup the buttons
74         Gtk::Button *grab_button(manage(new class Gtk::Button(Gtk::StockID("Grab"))));
75         grab_button->show();
76         add_action_widget(*grab_button,2);
77         grab_button->signal_clicked().connect(sigc::mem_fun(*this, &Dialog_Gradient::on_grab_pressed));
78
79         /*
80         Gtk::Button *apply_button(manage(new class Gtk::Button(Gtk::StockID("gtk-apply"))));
81         apply_button->show();
82         add_action_widget(*apply_button,1);
83         apply_button->signal_clicked().connect(sigc::mem_fun(*this, &Dialog_Gradient::on_apply_pressed));
84         */
85         
86         Gtk::Button *cancel_button(manage(new class Gtk::Button(Gtk::StockID("gtk-close"))));
87         cancel_button->show();
88         add_action_widget(*cancel_button,0);
89         cancel_button->signal_clicked().connect(sigc::mem_fun(*this, &Dialog_Gradient::hide));  
90
91         Gtk::Table* table(manage(new Gtk::Table(2,2,false)));
92         get_vbox()->pack_start(*table);
93
94         widget_gradient=manage(new Widget_Gradient());
95         widget_gradient->set_editable();
96         widget_gradient->signal_cpoint_selected().connect(sigc::mem_fun(*this,&studio::Dialog_Gradient::on_cpoint_selected));   
97         widget_gradient->signal_value_changed().connect(sigc::mem_fun(*this,&studio::Dialog_Gradient::on_changed));
98         //table->attach(*manage(new Gtk::Label(_("Not yet fully implemented"))), 0, 1, 0, 1, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);       
99         table->attach(*widget_gradient, 0, 1, 2, 3, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);        
100
101         widget_color=manage(new Widget_ColorEdit());
102         widget_color->signal_value_changed().connect(sigc::mem_fun(*this,&studio::Dialog_Gradient::on_values_adjusted));
103         widget_color->signal_value_changed().connect(sigc::mem_fun(*this,&studio::Dialog_Gradient::on_changed));
104         widget_color->signal_activated().connect(sigc::mem_fun(*this,&studio::Dialog_Gradient::on_values_adjusted));
105         table->attach(*widget_color, 0, 1, 0, 1, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);   
106
107
108         spinbutton_pos=manage(new class Gtk::SpinButton(adjustment_pos,0.0001,4));
109         spinbutton_pos->set_update_policy(Gtk::UPDATE_ALWAYS);
110         adjustment_pos.signal_value_changed().connect(sigc::mem_fun(*this,&studio::Dialog_Gradient::on_values_adjusted));
111         adjustment_pos.signal_value_changed().connect(sigc::mem_fun(*this,&studio::Dialog_Gradient::on_changed));
112         table->attach(*spinbutton_pos, 0, 1, 1, 2, Gtk::SHRINK|Gtk::FILL, Gtk::SHRINK|Gtk::FILL, 0, 0); 
113
114         
115         add_accel_group(App::ui_manager()->get_accel_group());
116
117         show_all_children();
118 }
119
120 Dialog_Gradient::~Dialog_Gradient()
121 {
122 }
123
124 void
125 Dialog_Gradient::set_gradient(const synfig::Gradient& x)
126 {
127         widget_gradient->set_value(x);
128 }
129
130 void
131 Dialog_Gradient::reset()
132 {
133         value_changed_connection.disconnect();
134         signal_edited_.clear();
135 }
136
137 void
138 Dialog_Gradient::on_grab_pressed()
139 {
140         synfigapp::Main::set_gradient(get_gradient());
141 //      signal_edited_(get_gradient());
142 //      reset();
143 //      hide();
144 }
145
146 void
147 Dialog_Gradient::on_apply_pressed()
148 {
149         signal_edited_(get_gradient());
150 }
151
152 void
153 Dialog_Gradient::on_changed()
154 {
155         signal_edited_(get_gradient());
156 }
157
158 void
159 Dialog_Gradient::on_cpoint_selected(synfig::Gradient::CPoint x)
160 {
161         widget_color->set_value(x.color);
162         adjustment_pos.set_value(x.pos);
163 }
164
165 void
166 Dialog_Gradient::on_values_adjusted()
167 {
168         synfig::Gradient::CPoint x(widget_gradient->get_selected_cpoint());
169         x.color=widget_color->get_value();
170         x.pos=adjustment_pos.get_value();
171         widget_gradient->update_cpoint(x);
172 }
173
174 static void
175 dialog_gradient_value_desc_edit(synfig::Gradient g,synfigapp::ValueDesc x,handle<synfigapp::CanvasInterface> canvas_interface)
176 {
177 //      canvas_interface->connect_value(x,ValueBase(g));
178 }
179
180 void
181 Dialog_Gradient::edit(const synfigapp::ValueDesc &x, etl::handle<synfigapp::CanvasInterface> canvas_interface, synfig::Time time)
182 {
183         reset();
184         if(x.is_const())
185                 set_gradient(x.get_value().get(Gradient()));
186         else if(x.is_value_node())
187                 set_gradient((*x.get_value_node())(time).get(Gradient()));
188                 
189         signal_edited().connect(
190                 sigc::bind(
191                         sigc::bind(
192                                 sigc::ptr_fun(dialog_gradient_value_desc_edit),
193                                 canvas_interface
194                         ),
195                         x
196                 )
197         );
198                 
199         present();
200 }