1 /* === S Y N F I G ========================================================= */
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 ======================================================= */
37 /* === U S I N G =========================================================== */
41 using namespace synfig;
42 using namespace studio;
44 /* === M A C R O S ========================================================= */
46 /* === G L O B A L S ======================================================= */
48 int studio::Duck::duck_count(0);
56 synfig::error("%d ducks not yet deleted!",counter);
60 int _DuckCounter::counter(0);
63 /* === P R O C E D U R E S ================================================= */
65 /* === M E T H O D S ======================================================= */
68 rotations(synfig::Angle::deg(0)),
74 { duck_count++; _DuckCounter::counter++; }
76 Duck::Duck(const synfig::Point &point):
79 rotations(synfig::Angle::deg(0)),
86 { duck_count++; _DuckCounter::counter++;}
88 Duck::Duck(const synfig::Point &point,const synfig::Point &origin):
90 rotations(synfig::Angle::deg(0)),
97 { duck_count++; _DuckCounter::counter++;}
99 Duck::~Duck() { duck_count--; _DuckCounter::counter--;}
102 Duck::get_data_guid()const
104 if(value_desc_.is_value_node())
105 return value_desc_.get_value_node()->get_guid();
106 return GUID::hasher(get_name());
110 Duck::set_name(const synfig::String &x)
113 if(guid_==GUID::zero())
115 guid_=GUID::hasher(name);
121 Duck::operator==(const Duck &rhs)const
127 scalar==rhs.scalar &&
129 transform_stack_.size()==rhs.transform_stack_.size();
131 //(origin_duck?*origin_duck==*rhs.origin_duck:origin==rhs.origin) &&
132 //(shared_point?*shared_point==*rhs.shared_point:point==rhs.point) ;
136 Duck::get_trans_point()const
138 return transform_stack_.perform(get_sub_trans_point());
142 Duck::set_trans_point(const synfig::Point &x)
144 set_sub_trans_point(transform_stack_.unperform(x));
147 //! Sets the origin point.
149 Duck::set_origin(const synfig::Point &x)
151 origin=x; origin_duck=0;
154 //! Sets the origin point as another duck
156 Duck::set_origin(const etl::handle<Duck> &x)
161 //! Retrieves the origin location
163 Duck::get_origin()const
165 return origin_duck?origin_duck->get_point():origin;
168 //! Retrieves the origin duck
169 const etl::handle<Duck> &
170 Duck::get_origin_duck() const
175 //! Retrieves the origin location
177 Duck::get_trans_origin()const
179 return transform_stack_.perform(get_sub_trans_origin());
183 Duck::get_sub_trans_point()const
185 return get_point()*get_scalar()+get_sub_trans_origin();
189 Duck::set_sub_trans_point(const synfig::Point &x)
191 if (get_type() == Duck::TYPE_TANGENT ||
192 get_type() == Duck::TYPE_ANGLE)
194 Angle old_angle = get_point().angle();
195 set_point((x-get_sub_trans_origin())/get_scalar());
196 Angle new_angle = get_point().angle();
197 int old_quarters = round_to_int(Angle::deg(rotations).get()/90);
198 rotations += new_angle.dist(old_angle);
199 int new_quarters = round_to_int(Angle::deg(rotations).get()/90);
200 if (old_quarters != new_quarters)
201 synfig::info("rotation: %.2f turns", new_quarters/4.0);
204 set_point((x-get_sub_trans_origin())/get_scalar());
208 Duck::get_sub_trans_origin()const
210 return origin_duck?origin_duck->get_sub_trans_point():origin;