1 /* === S Y N F I G ========================================================= */
3 ** \brief Template File
8 ** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
9 ** Copyright (c) 2007, 2008 Chris Moore
11 ** This package is free software; you can redistribute it and/or
12 ** modify it under the terms of the GNU General Public License as
13 ** published by the Free Software Foundation; either version 2 of
14 ** the License, or (at your option) any later version.
16 ** This package is distributed in the hope that it will be useful,
17 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 ** General Public License for more details.
22 /* ========================================================================= */
24 /* === H E A D E R S ======================================================= */
40 /* === U S I N G =========================================================== */
44 using namespace synfig;
45 using namespace studio;
47 /* === M A C R O S ========================================================= */
49 /* === G L O B A L S ======================================================= */
51 int studio::Duck::duck_count(0);
59 synfig::error("%d ducks not yet deleted!",counter);
63 int _DuckCounter::counter(0);
66 /* === P R O C E D U R E S ================================================= */
68 /* === M E T H O D S ======================================================= */
71 rotations(synfig::Angle::deg(0)),
78 { duck_count++; _DuckCounter::counter++; }
80 Duck::Duck(const synfig::Point &point):
83 rotations(synfig::Angle::deg(0)),
90 { duck_count++; _DuckCounter::counter++;}
92 Duck::Duck(const synfig::Point &point,const synfig::Point &origin):
94 rotations(synfig::Angle::deg(0)),
101 { duck_count++; _DuckCounter::counter++;}
103 Duck::~Duck() { duck_count--; _DuckCounter::counter--;}
106 Duck::get_data_guid()const
108 if(value_desc_.is_value_node())
109 return value_desc_.get_value_node()->get_guid();
110 return GUID::hasher(get_name());
114 Duck::set_name(const synfig::String &x)
117 if(guid_==GUID::zero())
119 guid_=GUID::hasher(name);
125 Duck::operator==(const Duck &rhs)const
131 scalar==rhs.scalar &&
133 transform_stack_.size()==rhs.transform_stack_.size();
135 //(origin_duck?*origin_duck==*rhs.origin_duck:origin==rhs.origin) &&
136 //(shared_point?*shared_point==*rhs.shared_point:point==rhs.point) ;
140 Duck::get_trans_point()const
142 return transform_stack_.perform(get_sub_trans_point());
146 Duck::set_trans_point(const synfig::Point &x)
148 set_sub_trans_point(transform_stack_.unperform(x));
151 //! Sets the origin point.
153 Duck::set_origin(const synfig::Point &x)
155 origin=x; origin_duck=0;
158 //! Sets the origin point as another duck
160 Duck::set_origin(const etl::handle<Duck> &x)
165 //! Retrieves the origin location
167 Duck::get_origin()const
169 return origin_duck?origin_duck->get_point():origin;
172 //! Retrieves the origin duck
173 const etl::handle<Duck> &
174 Duck::get_origin_duck() const
179 //! Retrieves the origin location
181 Duck::get_trans_origin()const
183 return transform_stack_.perform(get_sub_trans_origin());
187 Duck::get_sub_trans_point()const
189 return get_point()*get_scalar()+get_sub_trans_origin();
193 Duck::set_sub_trans_point(const synfig::Point &x)
195 if (get_type() == Duck::TYPE_TANGENT ||
196 get_type() == Duck::TYPE_ANGLE)
198 Angle old_angle = get_point().angle();
199 set_point((x-get_sub_trans_origin())/get_scalar());
200 Angle change = get_point().angle() - old_angle;
201 while (change < Angle::deg(-180)) change += Angle::deg(360);
202 while (change > Angle::deg(180)) change -= Angle::deg(360);
203 int old_quarters = round_to_int(Angle::deg(rotations).get()/90);
205 int new_quarters = round_to_int(Angle::deg(rotations).get()/90);
206 if (old_quarters != new_quarters)
207 synfig::info("rotation: %.2f turns", new_quarters/4.0);
210 set_point((x-get_sub_trans_origin())/get_scalar());
214 Duck::get_sub_trans_origin()const
216 return origin_duck?origin_duck->get_sub_trans_point():origin;