1 /* === S Y N F I G ========================================================= */
3 ** \brief Template Header
5 ** $Id: duck.h,v 1.1.1.1 2005/01/07 03:34:36 darco Exp $
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 /* === S T A R T =========================================================== */
25 #ifndef __SYNFIG_DUCKMATIC_DUCK_H
26 #define __SYNFIG_DUCKMATIC_DUCK_H
28 /* === H E A D E R S ======================================================= */
32 #include <ETL/smart_ptr>
35 #include <synfig/vector.h>
36 #include <synfig/string.h>
37 #include <synfig/real.h>
38 #include <sigc++/signal.h>
39 #include <sigc++/object.h>
40 #include <synfig/time.h>
41 #include <ETL/smart_ptr>
42 #include <synfigapp/value_desc.h>
43 #include <synfig/transform.h>
45 /* === M A C R O S ========================================================= */
47 #define HASH_MAP_H <ext/hash_map>
48 #define HASH_SET_H <ext/hash_set>
52 #ifndef __STRING_HASH__
53 #define __STRING_HASH__
56 __gnu_cxx::hash<const char*> hasher_;
58 size_t operator()(const synfig::String& x)const
60 return hasher_(x.c_str());
70 /* === T Y P E D E F S ===================================================== */
72 /* === C L A S S E S & S T R U C T S ======================================= */
79 class Duck : public etl::shared_object
81 friend class Duckmatic;
87 TYPE_POSITION = (1<<0),
88 TYPE_TANGENT = (1<<1),
96 TYPE_DEFAULT = 0xdefadefa
99 typedef etl::handle<Duck> Handle;
100 typedef etl::loose_handle<Duck> LooseHandle;
104 sigc::signal<bool,const synfig::Point &> signal_edited_;
105 sigc::signal<void> signal_user_click_[5];
111 etl::smart_ptr<synfig::Point> shared_point;
113 synfig::Point origin;
117 etl::handle<Duck> origin_duck;
119 etl::handle<Duck> connect_duck;
120 etl::handle<Duck> box_duck;
129 synfig::TransformStack transform_stack_;
131 synfigapp::ValueDesc value_desc_;
133 static int duck_count;
136 Duck(const synfig::Point &point);
137 Duck(const synfig::Point &point,const synfig::Point &origin);
140 sigc::signal<bool,const synfig::Point &> &signal_edited() { return signal_edited_; }
141 sigc::signal<void> &signal_user_click(int i=0) { assert(i>=0); assert(i<5); return signal_user_click_[i]; }
143 void set_guid(const synfig::GUID& x) { guid_=x; }
144 const synfig::GUID& get_guid()const { return guid_; }
146 synfig::GUID get_data_guid()const;
148 //! Changes the editable flag. If set, the duck will not be able to be moved.
149 void set_editable(bool x) { editable=x; }
151 //! Retrieves the status of the editable flag
152 bool get_editable()const { return editable; }
155 void set_tangent(bool x) { tangent_=x; type_=TYPE_TANGENT; }
158 bool get_tangent()const { return tangent_; }
160 void set_connect_duck(const etl::handle<Duck>& x) { connect_duck=x; }
161 void set_box_duck(const etl::handle<Duck>& x) { box_duck=x; }
163 const etl::handle<Duck>& get_connect_duck()const { return connect_duck; }
164 const etl::handle<Duck>& get_box_duck()const { return box_duck; }
166 void set_value_desc(synfigapp::ValueDesc x) { value_desc_=x; }
168 synfigapp::ValueDesc& get_value_desc() { return value_desc_; }
170 void set_transform_stack(const synfig::TransformStack& x) { transform_stack_=x; }
172 const synfig::TransformStack& get_transform_stack()const { return transform_stack_; }
175 void set_type(Type x) { type_=x; }
178 Type get_type()const { return type_; }
180 //! Sets the scalar multiplier for the duck with respect to the origin
181 void set_scalar(synfig::Vector::value_type n) { scalar=n; }
183 //! Retrieves the scalar value
184 synfig::Vector::value_type get_scalar()const { return scalar; }
186 void set_shared_point(const etl::smart_ptr<synfig::Point>&x) { shared_point=x; }
188 //! Sets the location of the duck with respect to the origin
189 void set_point(const synfig::Point &x) { (shared_point?*shared_point:point)=x; }
191 //! Returns the location of the duck
192 synfig::Point get_point()const { return shared_point?*shared_point:point; }
194 synfig::Point get_trans_point()const;
196 void set_trans_point(const synfig::Point &x);
198 synfig::Point get_sub_trans_point()const;
199 void set_sub_trans_point(const synfig::Point &x);
200 synfig::Point get_sub_trans_origin()const;
202 //! Sets the origin point.
203 void set_origin(const synfig::Point &x);
205 //! Sets the origin point as another duck
206 void set_origin(const etl::handle<Duck> &x);
208 //! Retrieves the origin location
209 synfig::Point get_origin()const;
211 //! Retrieves the origin duck
212 const etl::handle<Duck> & get_origin_duck() const;
214 //! Retrieves the origin location
215 synfig::Point get_trans_origin()const;
217 void set_radius(bool r) { radius_=r; }
218 bool is_radius()const { return radius_; }
220 //! Sets the name of the duck
221 void set_name(const synfig::String &x);
223 //! Retrieves the name of the duck
224 synfig::String get_name()const { return name; }
226 bool operator==(const Duck &rhs)const;
227 }; // END of class Duck
231 operator|(Duck::Type lhs, const Duck::Type rhs)
232 { return static_cast<Duck::Type>(int(lhs)|int(rhs)); }
236 operator-(Duck::Type lhs, const Duck::Type rhs)
237 { return static_cast<Duck::Type>(int(lhs)&~int(rhs)); }
240 operator|=(Duck::Type& lhs, const Duck::Type rhs)
241 { *reinterpret_cast<int*>(&lhs)|=int(rhs); return lhs; }
244 operator&(const Duck::Type lhs, const Duck::Type rhs)
245 { return static_cast<Duck::Type>(int(lhs)&int(rhs)); }
247 class DuckMap : public
249 __gnu_cxx::hash_map<synfig::GUID,etl::handle<studio::Duck>,synfig::GUIDHash>
251 typedef __gnu_cxx::hash_map<synfig::GUID,etl::handle<studio::Duck>,synfig::GUIDHash> PARENT_TYPE;
253 std::map<synfig::GUID,etl::handle<studio::Duck> >
255 typedef std::map<synfig::GUID,etl::handle<studio::Duck> > PARENT_TYPE;
258 void insert(const Duck::Handle& x) { operator[](x->get_guid())=x; }
259 }; // END of class DuckMap
261 typedef std::list<Duck::Handle> DuckList;
263 }; // END of namespace studio
265 /* === E N D =============================================================== */