Initial attempt at i18n support using gettext
[synfig.git] / synfig-studio / trunk / src / gtkmm / duck.cpp
1 /* === S Y N F I G ========================================================= */
2 /*!     \file duck.cpp
3 **      \brief Template File
4 **
5 **      $Id$
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 "duck.h"
33 #include <ETL/misc>
34
35 #include "general.h"
36
37 #endif
38
39 /* === U S I N G =========================================================== */
40
41 using namespace std;
42 using namespace etl;
43 using namespace synfig;
44 using namespace studio;
45
46 /* === M A C R O S ========================================================= */
47
48 /* === G L O B A L S ======================================================= */
49
50 int studio::Duck::duck_count(0);
51
52 struct _DuckCounter
53 {
54         static int counter;
55         ~_DuckCounter()
56         {
57                 if(counter)
58                         synfig::error("%d ducks not yet deleted!",counter);
59         }
60 } _duck_counter;
61
62 int _DuckCounter::counter(0);
63
64
65 /* === P R O C E D U R E S ================================================= */
66
67 /* === M E T H O D S ======================================================= */
68
69 Duck::Duck():
70         rotations(synfig::Angle::deg(0)),
71         origin(0,0),
72         scalar(1),
73         editable(false),
74         radius_(false),
75         tangent_(false)
76 { duck_count++; _DuckCounter::counter++; }
77
78 Duck::Duck(const synfig::Point &point):
79         type_(TYPE_NONE),
80         point(point),
81         rotations(synfig::Angle::deg(0)),
82         origin(0,0),
83         scalar(1),
84         guid_(0),
85         editable(false),
86         radius_(false),
87         tangent_(false)
88 { duck_count++; _DuckCounter::counter++;}
89
90 Duck::Duck(const synfig::Point &point,const synfig::Point &origin):
91         point(point),
92         rotations(synfig::Angle::deg(0)),
93         origin(origin),
94         scalar(1),
95         guid_(0),
96         editable(false),
97         radius_(true),
98         tangent_(false)
99 { duck_count++; _DuckCounter::counter++;}
100
101 Duck::~Duck() { duck_count--; _DuckCounter::counter--;}
102
103 synfig::GUID
104 Duck::get_data_guid()const
105 {
106         if(value_desc_.is_value_node())
107                 return value_desc_.get_value_node()->get_guid();
108         return GUID::hasher(get_name());
109 }
110
111 void
112 Duck::set_name(const synfig::String &x)
113 {
114         name=x;
115         if(guid_==GUID::zero())
116         {
117                 guid_=GUID::hasher(name);
118         }
119 }
120
121
122 bool
123 Duck::operator==(const Duck &rhs)const
124 {
125         if(this==&rhs)
126                 return true;
127         return
128                 name==rhs.name &&
129                 scalar==rhs.scalar &&
130                 type_==rhs.type_ &&
131                 transform_stack_.size()==rhs.transform_stack_.size();
132                 //true;
133                 //(origin_duck?*origin_duck==*rhs.origin_duck:origin==rhs.origin) &&
134                 //(shared_point?*shared_point==*rhs.shared_point:point==rhs.point) ;
135 }
136
137 synfig::Point
138 Duck::get_trans_point()const
139 {
140         return transform_stack_.perform(get_sub_trans_point());
141 }
142
143 void
144 Duck::set_trans_point(const synfig::Point &x)
145 {
146         set_sub_trans_point(transform_stack_.unperform(x));
147 }
148
149 //! Sets the origin point.
150 void
151 Duck::set_origin(const synfig::Point &x)
152 {
153         origin=x; origin_duck=0;
154 }
155
156 //! Sets the origin point as another duck
157 void
158 Duck::set_origin(const etl::handle<Duck> &x)
159 {
160         origin_duck=x;
161 }
162
163 //! Retrieves the origin location
164 synfig::Point
165 Duck::get_origin()const
166 {
167         return origin_duck?origin_duck->get_point():origin;
168 }
169
170 //! Retrieves the origin duck
171 const etl::handle<Duck> &
172 Duck::get_origin_duck() const
173 {
174         return origin_duck;
175 }
176
177 //! Retrieves the origin location
178 synfig::Point
179 Duck::get_trans_origin()const
180 {
181         return transform_stack_.perform(get_sub_trans_origin());
182 }
183
184 synfig::Point
185 Duck::get_sub_trans_point()const
186 {
187         return get_point()*get_scalar()+get_sub_trans_origin();
188 }
189
190 void
191 Duck::set_sub_trans_point(const synfig::Point &x)
192 {
193         if (get_type() == Duck::TYPE_TANGENT ||
194                 get_type() == Duck::TYPE_ANGLE)
195         {
196                 Angle old_angle = get_point().angle();
197                 set_point((x-get_sub_trans_origin())/get_scalar());
198                 Angle new_angle = get_point().angle();
199                 int old_quarters = round_to_int(Angle::deg(rotations).get()/90);
200                 rotations += new_angle.dist(old_angle);
201                 int new_quarters = round_to_int(Angle::deg(rotations).get()/90);
202                 if (old_quarters != new_quarters)
203                         synfig::info("rotation: %.2f turns", new_quarters/4.0);
204         }
205         else
206                 set_point((x-get_sub_trans_origin())/get_scalar());
207 }
208
209 synfig::Point
210 Duck::get_sub_trans_origin()const
211 {
212         return origin_duck?origin_duck->get_sub_trans_point():origin;
213 }