1 /* === S Y N F I G ========================================================= */
2 /*! \file widget_vector.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 <gtkmm/spinbutton.h>
33 #include "widget_vector.h"
34 #include "widget_distance.h"
41 /* === U S I N G =========================================================== */
44 using namespace synfig;
45 using namespace studio;
47 /* === M A C R O S ========================================================= */
51 /* === G L O B A L S ======================================================= */
53 /* === P R O C E D U R E S ================================================= */
55 /* === M E T H O D S ======================================================= */
57 Widget_Vector::Widget_Vector():
59 x_adjustment(0,-100000000,100000000,0.05,0.05,0),
60 y_adjustment(0,-100000000,100000000,0.05,0.05,0)
64 label=manage(new class Gtk::Label("X:"));
65 label->set_alignment(0, 0.5);
67 pack_start(*label, Gtk::PACK_SHRINK);
69 spinbutton_x=manage(new class Gtk::SpinButton(x_adjustment,0.05,DIGITS));
70 spinbutton_x->set_alignment(1);
71 spinbutton_x->set_update_policy(Gtk::UPDATE_ALWAYS);
72 spinbutton_x->signal_value_changed().connect(sigc::mem_fun(*this,&studio::Widget_Vector::on_value_changed));
73 pack_start(*spinbutton_x, Gtk::PACK_EXPAND_WIDGET);
75 distance_x=manage(new Widget_Distance());
76 distance_x->set_digits(4);
77 distance_x->set_update_policy(Gtk::UPDATE_ALWAYS);
78 distance_x->signal_value_changed().connect(sigc::mem_fun(*this,&studio::Widget_Vector::on_value_changed));
79 pack_start(*distance_x, Gtk::PACK_EXPAND_WIDGET);
81 label=manage(new class Gtk::Label("Y:"));
82 label->set_alignment(0, 0.5);
84 pack_start(*label, Gtk::PACK_SHRINK);
86 spinbutton_y=manage(new class Gtk::SpinButton(y_adjustment,0.05,DIGITS));
87 spinbutton_y->set_alignment(1);
88 spinbutton_y->set_update_policy(Gtk::UPDATE_ALWAYS);
89 spinbutton_y->signal_value_changed().connect(sigc::mem_fun(*this,&studio::Widget_Vector::on_value_changed));
90 spinbutton_y->signal_activate().connect(sigc::mem_fun(*this,&studio::Widget_Vector::activate));
91 pack_start(*spinbutton_y, Gtk::PACK_EXPAND_WIDGET);
93 distance_y=manage(new Widget_Distance());
94 distance_y->set_digits(4);
95 distance_y->set_update_policy(Gtk::UPDATE_ALWAYS);
96 distance_y->signal_value_changed().connect(sigc::mem_fun(*this,&studio::Widget_Vector::on_value_changed));
97 distance_y->signal_activate().connect(sigc::mem_fun(*this,&studio::Widget_Vector::activate));
98 pack_start(*distance_y, Gtk::PACK_EXPAND_WIDGET);
100 spinbutton_x->show();
101 spinbutton_y->show();
103 spinbutton_x->signal_activate().connect(sigc::mem_fun(*spinbutton_y,&Gtk::SpinButton::grab_focus));
104 distance_x->signal_activate().connect(sigc::mem_fun(*distance_y,&Gtk::SpinButton::grab_focus));
107 Widget_Vector::~Widget_Vector()
112 Widget_Vector::on_grab_focus()
115 distance_x->grab_focus();
117 spinbutton_x->grab_focus();
121 Widget_Vector::set_has_frame(bool x)
125 spinbutton_x->set_has_frame(x);
126 spinbutton_y->set_has_frame(x);
127 spinbutton_x->set_size_request(48,-1);
128 spinbutton_y->set_size_request(48,-1);
131 distance_x->set_has_frame(x);
132 distance_y->set_has_frame(x);
133 distance_x->set_size_request(48,-1);
134 distance_y->set_size_request(48,-1);
138 Widget_Vector::set_digits(int x)
142 spinbutton_x->set_digits(x);
143 spinbutton_y->set_digits(x);
144 spinbutton_x->set_size_request(48,-1);
145 spinbutton_y->set_size_request(48,-1);
148 distance_x->set_digits(x);
149 distance_y->set_digits(x);
150 distance_x->set_size_request(48,-1);
151 distance_y->set_size_request(48,-1);
155 Widget_Vector::set_value(const synfig::Vector &data)
161 Distance distx(vector[0],Distance::SYSTEM_UNITS),disty(vector[1],Distance::SYSTEM_UNITS);
162 distx.convert(App::distance_system,canvas_->rend_desc());
163 disty.convert(App::distance_system,canvas_->rend_desc());
164 distance_x->set_value(distx);
165 distance_y->set_value(disty);
166 spinbutton_x->hide();
167 spinbutton_y->hide();
168 }catch(...) { synfig::error("Widget_Vector::set_value(): Caught something that was thrown"); }}
171 spinbutton_x->set_value(vector[0]);
172 spinbutton_y->set_value(vector[1]);
178 const synfig::Vector &
179 Widget_Vector::get_value()
181 if(!canvas_ && spinbutton_x)
183 vector[0]=spinbutton_x->get_value();
184 vector[1]=spinbutton_y->get_value();
190 vector[0]=distance_x->get_value().units(canvas_->rend_desc());
191 vector[1]=distance_y->get_value().units(canvas_->rend_desc());
192 spinbutton_x->hide();
193 spinbutton_y->hide();
194 }catch(...) { synfig::error("Widget_Vector::set_value(): Caught something that was thrown"); }
199 Widget_Vector::on_value_changed()
201 signal_value_changed()();
205 Widget_Vector::set_canvas(synfig::Canvas::LooseHandle x)
212 spinbutton_x->hide();
213 spinbutton_y->hide();
214 // delete spinbutton_x;
215 // delete spinbutton_y;
224 spinbutton_x->show();
225 spinbutton_y->show();
233 Widget_Vector::show_all_vfunc()
242 spinbutton_x->show();
243 spinbutton_y->show();