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 ======================================================= */
39 /* === U S I N G =========================================================== */
43 using namespace synfig;
44 using namespace studio;
46 /* === M A C R O S ========================================================= */
48 /* === G L O B A L S ======================================================= */
50 int studio::Duck::duck_count(0);
58 synfig::error("%d ducks not yet deleted!",counter);
62 int _DuckCounter::counter(0);
65 /* === P R O C E D U R E S ================================================= */
67 /* === M E T H O D S ======================================================= */
70 rotations(synfig::Angle::deg(0)),
76 { duck_count++; _DuckCounter::counter++; }
78 Duck::Duck(const synfig::Point &point):
81 rotations(synfig::Angle::deg(0)),
88 { duck_count++; _DuckCounter::counter++;}
90 Duck::Duck(const synfig::Point &point,const synfig::Point &origin):
92 rotations(synfig::Angle::deg(0)),
99 { duck_count++; _DuckCounter::counter++;}
101 Duck::~Duck() { duck_count--; _DuckCounter::counter--;}
104 Duck::get_data_guid()const
106 if(value_desc_.is_value_node())
107 return value_desc_.get_value_node()->get_guid();
108 return GUID::hasher(get_name());
112 Duck::set_name(const synfig::String &x)
115 if(guid_==GUID::zero())
117 guid_=GUID::hasher(name);
123 Duck::operator==(const Duck &rhs)const
129 scalar==rhs.scalar &&
131 transform_stack_.size()==rhs.transform_stack_.size();
133 //(origin_duck?*origin_duck==*rhs.origin_duck:origin==rhs.origin) &&
134 //(shared_point?*shared_point==*rhs.shared_point:point==rhs.point) ;
138 Duck::get_trans_point()const
140 return transform_stack_.perform(get_sub_trans_point());
144 Duck::set_trans_point(const synfig::Point &x)
146 set_sub_trans_point(transform_stack_.unperform(x));
149 //! Sets the origin point.
151 Duck::set_origin(const synfig::Point &x)
153 origin=x; origin_duck=0;
156 //! Sets the origin point as another duck
158 Duck::set_origin(const etl::handle<Duck> &x)
163 //! Retrieves the origin location
165 Duck::get_origin()const
167 return origin_duck?origin_duck->get_point():origin;
170 //! Retrieves the origin duck
171 const etl::handle<Duck> &
172 Duck::get_origin_duck() const
177 //! Retrieves the origin location
179 Duck::get_trans_origin()const
181 return transform_stack_.perform(get_sub_trans_origin());
185 Duck::get_sub_trans_point()const
187 return get_point()*get_scalar()+get_sub_trans_origin();
191 Duck::set_sub_trans_point(const synfig::Point &x)
193 if (get_type() == Duck::TYPE_TANGENT ||
194 get_type() == Duck::TYPE_ANGLE)
196 Angle old_angle = get_point().angle();
197 set_point((x-get_sub_trans_origin())/get_scalar());
198 Angle change = get_point().angle() - old_angle;
199 while (change < Angle::deg(-180)) change += Angle::deg(360);
200 while (change > Angle::deg(180)) change -= Angle::deg(360);
201 int old_quarters = round_to_int(Angle::deg(rotations).get()/90);
203 int new_quarters = round_to_int(Angle::deg(rotations).get()/90);
204 if (old_quarters != new_quarters)
205 synfig::info("rotation: %.2f turns", new_quarters/4.0);
208 set_point((x-get_sub_trans_origin())/get_scalar());
212 Duck::get_sub_trans_origin()const
214 return origin_duck?origin_duck->get_sub_trans_point():origin;