1 /* === S Y N F I G ========================================================= */
2 /*! \file widget_vector.cpp
3 ** \brief Template File
5 ** $Id: widget_vector.cpp,v 1.1.1.1 2005/01/07 03:34:37 darco Exp $
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():
56 x_adjustment(0,-100000000,100000000,0.05,0.05,0.05),
57 y_adjustment(0,-100000000,100000000,0.05,0.05,0.05)
61 label=manage(new class Gtk::Label("x:"));
63 pack_start(*label, Gtk::PACK_SHRINK);
65 spinbutton_x=manage(new class Gtk::SpinButton(x_adjustment,0.05,DIGITS));
66 spinbutton_x->set_update_policy(Gtk::UPDATE_ALWAYS);
67 spinbutton_x->signal_value_changed().connect(sigc::mem_fun(*this,&studio::Widget_Vector::on_value_changed));
68 pack_start(*spinbutton_x, Gtk::PACK_EXPAND_WIDGET);
70 distance_x=manage(new Widget_Distance());
71 distance_x->set_digits(4);
72 distance_x->set_update_policy(Gtk::UPDATE_ALWAYS);
73 distance_x->signal_value_changed().connect(sigc::mem_fun(*this,&studio::Widget_Vector::on_value_changed));
74 pack_start(*distance_x, Gtk::PACK_EXPAND_WIDGET);
76 label=manage(new class Gtk::Label("y:"));
78 pack_start(*label, Gtk::PACK_SHRINK);
80 spinbutton_y=manage(new class Gtk::SpinButton(y_adjustment,0.05,DIGITS));
81 spinbutton_y->set_update_policy(Gtk::UPDATE_ALWAYS);
82 spinbutton_y->signal_value_changed().connect(sigc::mem_fun(*this,&studio::Widget_Vector::on_value_changed));
83 spinbutton_y->signal_activate().connect(sigc::mem_fun(*this,&studio::Widget_Vector::activate));
84 pack_start(*spinbutton_y, Gtk::PACK_EXPAND_WIDGET);
86 distance_y=manage(new Widget_Distance());
87 distance_y->set_digits(4);
88 distance_y->set_update_policy(Gtk::UPDATE_ALWAYS);
89 distance_y->signal_value_changed().connect(sigc::mem_fun(*this,&studio::Widget_Vector::on_value_changed));
90 distance_y->signal_activate().connect(sigc::mem_fun(*this,&studio::Widget_Vector::activate));
91 pack_start(*distance_y, Gtk::PACK_EXPAND_WIDGET);
96 spinbutton_x->signal_activate().connect(sigc::mem_fun(*spinbutton_y,&Gtk::SpinButton::grab_focus));
97 distance_x->signal_activate().connect(sigc::mem_fun(*distance_y,&Gtk::SpinButton::grab_focus));
100 Widget_Vector::~Widget_Vector()
105 Widget_Vector::on_grab_focus()
108 distance_x->grab_focus();
110 spinbutton_x->grab_focus();
114 Widget_Vector::set_has_frame(bool x)
118 spinbutton_x->set_has_frame(x);
119 spinbutton_y->set_has_frame(x);
120 spinbutton_x->set_size_request(48,-1);
121 spinbutton_y->set_size_request(48,-1);
124 distance_x->set_has_frame(x);
125 distance_y->set_has_frame(x);
126 distance_x->set_size_request(48,-1);
127 distance_y->set_size_request(48,-1);
131 Widget_Vector::set_digits(int x)
135 spinbutton_x->set_digits(x);
136 spinbutton_y->set_digits(x);
137 spinbutton_x->set_size_request(48,-1);
138 spinbutton_y->set_size_request(48,-1);
141 distance_x->set_digits(x);
142 distance_y->set_digits(x);
143 distance_x->set_size_request(48,-1);
144 distance_y->set_size_request(48,-1);
148 Widget_Vector::set_value(const synfig::Vector &data)
154 Distance distx(vector[0],Distance::SYSTEM_UNITS),disty(vector[1],Distance::SYSTEM_UNITS);
155 distx.convert(App::distance_system,canvas_->rend_desc());
156 disty.convert(App::distance_system,canvas_->rend_desc());
157 distance_x->set_value(distx);
158 distance_y->set_value(disty);
159 spinbutton_x->hide();
160 spinbutton_y->hide();
161 }catch(...) { synfig::error("Widget_Vector::set_value(): Caught something that was thrown"); }}
164 spinbutton_x->set_value(vector[0]);
165 spinbutton_y->set_value(vector[1]);
171 const synfig::Vector &
172 Widget_Vector::get_value()
174 if(!canvas_ && spinbutton_x)
176 vector[0]=spinbutton_x->get_value();
177 vector[1]=spinbutton_y->get_value();
183 vector[0]=distance_x->get_value().units(canvas_->rend_desc());
184 vector[1]=distance_y->get_value().units(canvas_->rend_desc());
185 spinbutton_x->hide();
186 spinbutton_y->hide();
187 }catch(...) { synfig::error("Widget_Vector::set_value(): Caught something that was thrown"); }
192 Widget_Vector::on_value_changed()
194 signal_value_changed()();
198 Widget_Vector::set_canvas(Canvas::LooseHandle x)
205 spinbutton_x->hide();
206 spinbutton_y->hide();
207 // delete spinbutton_x;
208 // delete spinbutton_y;
217 spinbutton_x->show();
218 spinbutton_y->show();
226 Widget_Vector::show_all_vfunc()
235 spinbutton_x->show();
236 spinbutton_y->show();