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 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 <gtkmm/spinbutton.h>
32 #include "widget_vector.h"
33 #include "widget_distance.h"
38 /* === U S I N G =========================================================== */
41 using namespace synfig;
42 using namespace studio;
44 /* === M A C R O S ========================================================= */
48 /* === G L O B A L S ======================================================= */
50 /* === P R O C E D U R E S ================================================= */
52 /* === M E T H O D S ======================================================= */
54 Widget_Vector::Widget_Vector():
55 x_adjustment(0,-100000000,100000000,0.05,0.05,0.05),
56 y_adjustment(0,-100000000,100000000,0.05,0.05,0.05)
60 label=manage(new class Gtk::Label("x:"));
62 pack_start(*label, Gtk::PACK_SHRINK);
64 spinbutton_x=manage(new class Gtk::SpinButton(x_adjustment,0.05,DIGITS));
65 spinbutton_x->set_update_policy(Gtk::UPDATE_ALWAYS);
66 spinbutton_x->signal_value_changed().connect(sigc::mem_fun(*this,&studio::Widget_Vector::on_value_changed));
67 pack_start(*spinbutton_x, Gtk::PACK_EXPAND_WIDGET);
69 distance_x=manage(new Widget_Distance());
70 distance_x->set_digits(4);
71 distance_x->set_update_policy(Gtk::UPDATE_ALWAYS);
72 distance_x->signal_value_changed().connect(sigc::mem_fun(*this,&studio::Widget_Vector::on_value_changed));
73 pack_start(*distance_x, Gtk::PACK_EXPAND_WIDGET);
75 label=manage(new class Gtk::Label("y:"));
77 pack_start(*label, Gtk::PACK_SHRINK);
79 spinbutton_y=manage(new class Gtk::SpinButton(y_adjustment,0.05,DIGITS));
80 spinbutton_y->set_update_policy(Gtk::UPDATE_ALWAYS);
81 spinbutton_y->signal_value_changed().connect(sigc::mem_fun(*this,&studio::Widget_Vector::on_value_changed));
82 spinbutton_y->signal_activate().connect(sigc::mem_fun(*this,&studio::Widget_Vector::activate));
83 pack_start(*spinbutton_y, Gtk::PACK_EXPAND_WIDGET);
85 distance_y=manage(new Widget_Distance());
86 distance_y->set_digits(4);
87 distance_y->set_update_policy(Gtk::UPDATE_ALWAYS);
88 distance_y->signal_value_changed().connect(sigc::mem_fun(*this,&studio::Widget_Vector::on_value_changed));
89 distance_y->signal_activate().connect(sigc::mem_fun(*this,&studio::Widget_Vector::activate));
90 pack_start(*distance_y, Gtk::PACK_EXPAND_WIDGET);
95 spinbutton_x->signal_activate().connect(sigc::mem_fun(*spinbutton_y,&Gtk::SpinButton::grab_focus));
96 distance_x->signal_activate().connect(sigc::mem_fun(*distance_y,&Gtk::SpinButton::grab_focus));
99 Widget_Vector::~Widget_Vector()
104 Widget_Vector::on_grab_focus()
107 distance_x->grab_focus();
109 spinbutton_x->grab_focus();
113 Widget_Vector::set_has_frame(bool x)
117 spinbutton_x->set_has_frame(x);
118 spinbutton_y->set_has_frame(x);
119 spinbutton_x->set_size_request(48,-1);
120 spinbutton_y->set_size_request(48,-1);
123 distance_x->set_has_frame(x);
124 distance_y->set_has_frame(x);
125 distance_x->set_size_request(48,-1);
126 distance_y->set_size_request(48,-1);
130 Widget_Vector::set_digits(int x)
134 spinbutton_x->set_digits(x);
135 spinbutton_y->set_digits(x);
136 spinbutton_x->set_size_request(48,-1);
137 spinbutton_y->set_size_request(48,-1);
140 distance_x->set_digits(x);
141 distance_y->set_digits(x);
142 distance_x->set_size_request(48,-1);
143 distance_y->set_size_request(48,-1);
147 Widget_Vector::set_value(const synfig::Vector &data)
153 Distance distx(vector[0],Distance::SYSTEM_UNITS),disty(vector[1],Distance::SYSTEM_UNITS);
154 distx.convert(App::distance_system,canvas_->rend_desc());
155 disty.convert(App::distance_system,canvas_->rend_desc());
156 distance_x->set_value(distx);
157 distance_y->set_value(disty);
158 spinbutton_x->hide();
159 spinbutton_y->hide();
160 }catch(...) { synfig::error("Widget_Vector::set_value(): Caught something that was thrown"); }}
163 spinbutton_x->set_value(vector[0]);
164 spinbutton_y->set_value(vector[1]);
170 const synfig::Vector &
171 Widget_Vector::get_value()
173 if(!canvas_ && spinbutton_x)
175 vector[0]=spinbutton_x->get_value();
176 vector[1]=spinbutton_y->get_value();
182 vector[0]=distance_x->get_value().units(canvas_->rend_desc());
183 vector[1]=distance_y->get_value().units(canvas_->rend_desc());
184 spinbutton_x->hide();
185 spinbutton_y->hide();
186 }catch(...) { synfig::error("Widget_Vector::set_value(): Caught something that was thrown"); }
191 Widget_Vector::on_value_changed()
193 signal_value_changed()();
197 Widget_Vector::set_canvas(Canvas::LooseHandle x)
204 spinbutton_x->hide();
205 spinbutton_y->hide();
206 // delete spinbutton_x;
207 // delete spinbutton_y;
216 spinbutton_x->show();
217 spinbutton_y->show();
225 Widget_Vector::show_all_vfunc()
234 spinbutton_x->show();
235 spinbutton_y->show();