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"
39 /* === U S I N G =========================================================== */
42 using namespace synfig;
43 using namespace studio;
45 /* === M A C R O S ========================================================= */
49 /* === G L O B A L S ======================================================= */
51 /* === P R O C E D U R E S ================================================= */
53 /* === M E T H O D S ======================================================= */
55 Widget_Vector::Widget_Vector():
57 x_adjustment(0,-100000000,100000000,0.05,0.05,0.05),
58 y_adjustment(0,-100000000,100000000,0.05,0.05,0.05)
62 label=manage(new class Gtk::Label("X:"));
63 label->set_alignment(0, 0.5);
65 pack_start(*label, Gtk::PACK_SHRINK);
67 spinbutton_x=manage(new class Gtk::SpinButton(x_adjustment,0.05,DIGITS));
68 spinbutton_x->set_alignment(1);
69 spinbutton_x->set_update_policy(Gtk::UPDATE_ALWAYS);
70 spinbutton_x->signal_value_changed().connect(sigc::mem_fun(*this,&studio::Widget_Vector::on_value_changed));
71 pack_start(*spinbutton_x, Gtk::PACK_EXPAND_WIDGET);
73 distance_x=manage(new Widget_Distance());
74 distance_x->set_digits(4);
75 distance_x->set_update_policy(Gtk::UPDATE_ALWAYS);
76 distance_x->signal_value_changed().connect(sigc::mem_fun(*this,&studio::Widget_Vector::on_value_changed));
77 pack_start(*distance_x, Gtk::PACK_EXPAND_WIDGET);
79 label=manage(new class Gtk::Label("Y:"));
80 label->set_alignment(0, 0.5);
82 pack_start(*label, Gtk::PACK_SHRINK);
84 spinbutton_y=manage(new class Gtk::SpinButton(y_adjustment,0.05,DIGITS));
85 spinbutton_y->set_alignment(1);
86 spinbutton_y->set_update_policy(Gtk::UPDATE_ALWAYS);
87 spinbutton_y->signal_value_changed().connect(sigc::mem_fun(*this,&studio::Widget_Vector::on_value_changed));
88 spinbutton_y->signal_activate().connect(sigc::mem_fun(*this,&studio::Widget_Vector::activate));
89 pack_start(*spinbutton_y, Gtk::PACK_EXPAND_WIDGET);
91 distance_y=manage(new Widget_Distance());
92 distance_y->set_digits(4);
93 distance_y->set_update_policy(Gtk::UPDATE_ALWAYS);
94 distance_y->signal_value_changed().connect(sigc::mem_fun(*this,&studio::Widget_Vector::on_value_changed));
95 distance_y->signal_activate().connect(sigc::mem_fun(*this,&studio::Widget_Vector::activate));
96 pack_start(*distance_y, Gtk::PACK_EXPAND_WIDGET);
101 spinbutton_x->signal_activate().connect(sigc::mem_fun(*spinbutton_y,&Gtk::SpinButton::grab_focus));
102 distance_x->signal_activate().connect(sigc::mem_fun(*distance_y,&Gtk::SpinButton::grab_focus));
105 Widget_Vector::~Widget_Vector()
110 Widget_Vector::on_grab_focus()
113 distance_x->grab_focus();
115 spinbutton_x->grab_focus();
119 Widget_Vector::set_has_frame(bool x)
123 spinbutton_x->set_has_frame(x);
124 spinbutton_y->set_has_frame(x);
125 spinbutton_x->set_size_request(48,-1);
126 spinbutton_y->set_size_request(48,-1);
129 distance_x->set_has_frame(x);
130 distance_y->set_has_frame(x);
131 distance_x->set_size_request(48,-1);
132 distance_y->set_size_request(48,-1);
136 Widget_Vector::set_digits(int x)
140 spinbutton_x->set_digits(x);
141 spinbutton_y->set_digits(x);
142 spinbutton_x->set_size_request(48,-1);
143 spinbutton_y->set_size_request(48,-1);
146 distance_x->set_digits(x);
147 distance_y->set_digits(x);
148 distance_x->set_size_request(48,-1);
149 distance_y->set_size_request(48,-1);
153 Widget_Vector::set_value(const synfig::Vector &data)
159 Distance distx(vector[0],Distance::SYSTEM_UNITS),disty(vector[1],Distance::SYSTEM_UNITS);
160 distx.convert(App::distance_system,canvas_->rend_desc());
161 disty.convert(App::distance_system,canvas_->rend_desc());
162 distance_x->set_value(distx);
163 distance_y->set_value(disty);
164 spinbutton_x->hide();
165 spinbutton_y->hide();
166 }catch(...) { synfig::error("Widget_Vector::set_value(): Caught something that was thrown"); }}
169 spinbutton_x->set_value(vector[0]);
170 spinbutton_y->set_value(vector[1]);
176 const synfig::Vector &
177 Widget_Vector::get_value()
179 if(!canvas_ && spinbutton_x)
181 vector[0]=spinbutton_x->get_value();
182 vector[1]=spinbutton_y->get_value();
188 vector[0]=distance_x->get_value().units(canvas_->rend_desc());
189 vector[1]=distance_y->get_value().units(canvas_->rend_desc());
190 spinbutton_x->hide();
191 spinbutton_y->hide();
192 }catch(...) { synfig::error("Widget_Vector::set_value(): Caught something that was thrown"); }
197 Widget_Vector::on_value_changed()
199 signal_value_changed()();
203 Widget_Vector::set_canvas(Canvas::LooseHandle x)
210 spinbutton_x->hide();
211 spinbutton_y->hide();
212 // delete spinbutton_x;
213 // delete spinbutton_y;
222 spinbutton_x->show();
223 spinbutton_y->show();
231 Widget_Vector::show_all_vfunc()
240 spinbutton_x->show();
241 spinbutton_y->show();