1 /* === S Y N F I G ========================================================= */
3 ** \brief Template Header
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 /* === S T A R T =========================================================== */
26 #ifndef __SYNFIG_DUCKMATIC_DUCK_H
27 #define __SYNFIG_DUCKMATIC_DUCK_H
29 /* === H E A D E R S ======================================================= */
33 #include <ETL/smart_ptr>
36 #include <synfig/vector.h>
37 #include <synfig/string.h>
38 #include <synfig/real.h>
39 #include <sigc++/signal.h>
40 #include <sigc++/object.h>
41 #include <synfig/time.h>
42 #include <ETL/smart_ptr>
43 #include <synfigapp/value_desc.h>
44 #include <synfig/transform.h>
46 /* === M A C R O S ========================================================= */
52 #ifndef __STRING_HASH__
53 #define __STRING_HASH__
56 # ifdef FUNCTIONAL_HASH_ON_STRING
57 HASH_MAP_NAMESPACE::hash<synfig::String> hasher_;
58 # else // FUNCTIONAL_HASH_ON_STRING
59 HASH_MAP_NAMESPACE::hash<const char*> hasher_;
60 # endif // FUNCTIONAL_HASH_ON_STRING
62 size_t operator()(const synfig::String& x)const
64 # ifdef FUNCTIONAL_HASH_ON_STRING
66 # else // FUNCTIONAL_HASH_ON_STRING
67 return hasher_(x.c_str());
68 # endif // FUNCTIONAL_HASH_ON_STRING
78 /* === T Y P E D E F S ===================================================== */
80 /* === C L A S S E S & S T R U C T S ======================================= */
87 class Duck : public etl::shared_object
89 friend class Duckmatic;
95 TYPE_POSITION = (1<<0), // 1
96 TYPE_TANGENT = (1<<1), // 2
97 TYPE_RADIUS = (1<<2), // 4
98 TYPE_WIDTH = (1<<3), // 8
99 TYPE_ANGLE = (1<<4), // 16
100 TYPE_VERTEX = (1<<5), // 32
104 TYPE_DEFAULT = 0xdefadefa
107 typedef etl::handle<Duck> Handle;
108 typedef etl::loose_handle<Duck> LooseHandle;
112 sigc::signal<bool,const synfig::Point &> signal_edited_;
113 sigc::signal<bool,const synfig::Angle &> signal_edited_angle_;
114 sigc::signal<void> signal_user_click_[5];
119 synfig::Angle rotations;
121 etl::smart_ptr<synfig::Point> shared_point;
123 synfig::Point origin;
127 etl::handle<Duck> origin_duck;
129 etl::handle<Duck> connect_duck;
130 etl::handle<Duck> box_duck;
141 synfig::TransformStack transform_stack_;
143 synfigapp::ValueDesc value_desc_;
145 static int duck_count;
148 Duck(const synfig::Point &point);
149 Duck(const synfig::Point &point,const synfig::Point &origin);
152 sigc::signal<bool,const synfig::Point &> &signal_edited() { return signal_edited_; }
153 sigc::signal<bool,const synfig::Angle &> &signal_edited_angle() { return signal_edited_angle_; }
154 sigc::signal<void> &signal_user_click(int i=0) { assert(i>=0); assert(i<5); return signal_user_click_[i]; }
156 void set_guid(const synfig::GUID& x) { guid_=x; }
157 const synfig::GUID& get_guid()const { return guid_; }
159 synfig::GUID get_data_guid()const;
161 //! Changes the editable flag. If set, the duck will not be able to be moved.
162 void set_editable(bool x) { editable=x; }
164 //! Retrieves the status of the editable flag
165 bool get_editable()const { return editable; }
168 void set_tangent(bool x) { tangent_=x; type_=TYPE_TANGENT; }
171 bool get_tangent()const { return tangent_; }
173 //! Sets whether to show the duck as if it is being hovered over
174 void set_hover(bool h) { hover_=h; }
176 //! Retrieves whether to show the duck as if it is being hovered over
177 bool get_hover()const { return hover_; }
179 //! Sets whether to ignore the duck when checking for user interaction
180 void set_ignore(bool i) { ignore_=i; }
182 //! Retrieves whether to ignore the duck when checking for user interaction
183 bool get_ignore()const { return ignore_; }
185 void set_connect_duck(const etl::handle<Duck>& x) { connect_duck=x; }
186 void set_box_duck(const etl::handle<Duck>& x) { box_duck=x; }
188 const etl::handle<Duck>& get_connect_duck()const { return connect_duck; }
189 const etl::handle<Duck>& get_box_duck()const { return box_duck; }
191 void set_value_desc(synfigapp::ValueDesc x) { value_desc_=x; }
193 synfigapp::ValueDesc& get_value_desc() { return value_desc_; }
195 void set_transform_stack(const synfig::TransformStack& x) { transform_stack_=x; }
197 const synfig::TransformStack& get_transform_stack()const { return transform_stack_; }
200 void set_type(Type x) { type_=x; }
203 Type get_type()const { return type_; }
205 //! Sets the scalar multiplier for the duck with respect to the origin
206 void set_scalar(synfig::Vector::value_type n) { scalar=n; }
208 //! Retrieves the scalar value
209 synfig::Vector::value_type get_scalar()const { return scalar; }
211 void set_shared_point(const etl::smart_ptr<synfig::Point>&x) { shared_point=x; }
213 //! Sets the location of the duck with respect to the origin
214 void set_point(const synfig::Point &x) { (shared_point?*shared_point:point)=x; }
216 //! Returns the location of the duck
217 synfig::Point get_point()const { return shared_point?*shared_point:point; }
219 synfig::Angle get_rotations()const { return rotations; };
221 synfig::Point get_trans_point()const;
223 void set_trans_point(const synfig::Point &x);
225 synfig::Point get_sub_trans_point()const;
226 void set_sub_trans_point(const synfig::Point &x);
227 synfig::Point get_sub_trans_origin()const;
229 //! Sets the origin point.
230 void set_origin(const synfig::Point &x);
232 //! Sets the origin point as another duck
233 void set_origin(const etl::handle<Duck> &x);
235 //! Retrieves the origin location
236 synfig::Point get_origin()const;
238 //! Retrieves the origin duck
239 const etl::handle<Duck> & get_origin_duck() const;
241 //! Retrieves the origin location
242 synfig::Point get_trans_origin()const;
244 void set_radius(bool r) { radius_=r; }
245 bool is_radius()const { return radius_; }
247 //! Sets the name of the duck
248 void set_name(const synfig::String &x);
250 //! Retrieves the name of the duck
251 synfig::String get_name()const { return name; }
253 bool operator==(const Duck &rhs)const;
256 //! Returns a string containing the name of the given Type
257 static synfig::String type_name(Type id);
259 //! Returns a string containing the name of the type
260 synfig::String type_name()const { return type_name(get_type()); }
263 }; // END of class Duck
267 operator|(Duck::Type lhs, const Duck::Type rhs)
268 { return static_cast<Duck::Type>(int(lhs)|int(rhs)); }
272 operator-(Duck::Type lhs, const Duck::Type rhs)
273 { return static_cast<Duck::Type>(int(lhs)&~int(rhs)); }
276 operator|=(Duck::Type& lhs, const Duck::Type rhs)
277 { *reinterpret_cast<int*>(&lhs)|=int(rhs); return lhs; }
280 operator&(const Duck::Type lhs, const Duck::Type rhs)
281 { return static_cast<Duck::Type>(int(lhs)&int(rhs)); }
283 class DuckMap : public
285 HASH_MAP_CLASS<synfig::GUID,etl::handle<studio::Duck>,synfig::GUIDHash>
287 typedef HASH_MAP_CLASS<synfig::GUID,etl::handle<studio::Duck>,synfig::GUIDHash> PARENT_TYPE;
289 std::map<synfig::GUID,etl::handle<studio::Duck> >
291 typedef std::map<synfig::GUID,etl::handle<studio::Duck> > PARENT_TYPE;
294 void insert(const Duck::Handle& x) { operator[](x->get_guid())=x; }
295 }; // END of class DuckMap
297 typedef std::list<Duck::Handle> DuckList;
299 }; // END of namespace studio
301 /* === E N D =============================================================== */