Avoid the "deprecated or antiquated header" warning from g++ 4.3 by using <tr1/unorde...
[synfig.git] / synfig-studio / trunk / src / gtkmm / duck.h
1 /* === S Y N F I G ========================================================= */
2 /*!     \file duck.h
3 **      \brief Template Header
4 **
5 **      $Id$
6 **
7 **      \legal
8 **      Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
9 **
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.
14 **
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.
19 **      \endlegal
20 */
21 /* ========================================================================= */
22
23 /* === S T A R T =========================================================== */
24
25 #ifndef __SYNFIG_DUCKMATIC_DUCK_H
26 #define __SYNFIG_DUCKMATIC_DUCK_H
27
28 /* === H E A D E R S ======================================================= */
29
30 #include <list>
31
32 #include <ETL/smart_ptr>
33 #include <ETL/handle>
34
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>
44
45 /* === M A C R O S ========================================================= */
46
47 #ifdef HASH_MAP_H
48 #include HASH_MAP_H
49 #ifndef __STRING_HASH__
50 #define __STRING_HASH__
51 class StringHash
52 {
53         HASH_MAP_NAMESPACE::hash<const char*> hasher_;
54 public:
55         size_t operator()(const synfig::String& x)const
56         {
57                 return hasher_(x.c_str());
58         }
59 };
60 #endif
61 #else
62 #include <map>
63 #endif
64
65 #include <set>
66
67 /* === T Y P E D E F S ===================================================== */
68
69 /* === C L A S S E S & S T R U C T S ======================================= */
70
71 namespace studio {
72 class Duckmatic;
73
74 /*! \class Duck
75 **      \writeme */
76 class Duck : public etl::shared_object
77 {
78         friend class Duckmatic;
79
80 public:
81         enum Type
82         {
83                 TYPE_NONE               =       (0),
84                 TYPE_POSITION   =       (1<<0),
85                 TYPE_TANGENT    =       (1<<1),
86                 TYPE_RADIUS             =       (1<<2),
87                 TYPE_WIDTH              =       (1<<3),
88                 TYPE_ANGLE              =       (1<<4),
89                 TYPE_VERTEX             =       (1<<5),
90
91                 TYPE_ALL                =       (~0),
92
93                 TYPE_DEFAULT    =       0xdefadefa
94         };
95
96         typedef etl::handle<Duck> Handle;
97         typedef etl::loose_handle<Duck> LooseHandle;
98
99 private:
100
101         sigc::signal<bool,const synfig::Point &> signal_edited_;
102         sigc::signal<bool,const synfig::Angle &> signal_edited_angle_;
103         sigc::signal<void> signal_user_click_[5];
104
105         Type type_;
106
107         synfig::Point point;
108         synfig::Angle rotations;
109
110         etl::smart_ptr<synfig::Point> shared_point;
111
112         synfig::Point origin;
113         synfig::String name;
114         synfig::Real scalar;
115
116         etl::handle<Duck> origin_duck;
117
118         etl::handle<Duck> connect_duck;
119         etl::handle<Duck> box_duck;
120
121         synfig::GUID guid_;
122
123         // Flags
124         bool editable;
125         bool radius_;
126         bool tangent_;
127
128         synfig::TransformStack transform_stack_;
129
130         synfigapp::ValueDesc value_desc_;
131
132         static int duck_count;
133 public:
134         Duck();
135         Duck(const synfig::Point &point);
136         Duck(const synfig::Point &point,const synfig::Point &origin);
137         ~Duck();
138
139         sigc::signal<bool,const synfig::Point &> &signal_edited() { return signal_edited_; }
140         sigc::signal<bool,const synfig::Angle &> &signal_edited_angle() { return signal_edited_angle_; }
141         sigc::signal<void> &signal_user_click(int i=0) { assert(i>=0); assert(i<5); return signal_user_click_[i]; }
142
143         void set_guid(const synfig::GUID& x) { guid_=x; }
144         const synfig::GUID& get_guid()const { return guid_; }
145
146         synfig::GUID get_data_guid()const;
147
148         //! Changes the editable flag. If set, the duck will not be able to be moved.
149         void set_editable(bool x) { editable=x; }
150
151         //! Retrieves the status of the editable flag
152         bool get_editable()const { return editable; }
153
154         //! \writeme
155         void set_tangent(bool x) { tangent_=x; type_=TYPE_TANGENT; }
156
157         //! \writeme
158         bool get_tangent()const { return tangent_; }
159
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; }
162
163         const etl::handle<Duck>& get_connect_duck()const { return connect_duck; }
164         const etl::handle<Duck>& get_box_duck()const { return box_duck; }
165
166         void set_value_desc(synfigapp::ValueDesc x) { value_desc_=x; }
167
168         synfigapp::ValueDesc& get_value_desc() { return value_desc_; }
169
170         void set_transform_stack(const synfig::TransformStack& x) { transform_stack_=x; }
171
172         const synfig::TransformStack& get_transform_stack()const { return transform_stack_; }
173
174         //! \writeme
175         void set_type(Type x) { type_=x; }
176
177         //! \writeme
178         Type get_type()const { return type_; }
179
180         //! Sets the scalar multiplier for the duck with respect to the origin
181         void set_scalar(synfig::Vector::value_type n) { scalar=n; }
182
183         //! Retrieves the scalar value
184         synfig::Vector::value_type get_scalar()const { return scalar; }
185
186         void set_shared_point(const etl::smart_ptr<synfig::Point>&x) { shared_point=x; }
187
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; }
190
191         //! Returns the location of the duck
192         synfig::Point get_point()const { return shared_point?*shared_point:point; }
193
194         synfig::Angle get_rotations()const { return rotations; };
195
196         synfig::Point get_trans_point()const;
197
198         void set_trans_point(const synfig::Point &x);
199
200         synfig::Point get_sub_trans_point()const;
201         void set_sub_trans_point(const synfig::Point &x);
202         synfig::Point get_sub_trans_origin()const;
203
204         //! Sets the origin point.
205         void set_origin(const synfig::Point &x);
206
207         //! Sets the origin point as another duck
208         void set_origin(const etl::handle<Duck> &x);
209
210         //! Retrieves the origin location
211         synfig::Point get_origin()const;
212
213         //! Retrieves the origin duck
214         const etl::handle<Duck> & get_origin_duck() const;
215
216         //! Retrieves the origin location
217         synfig::Point get_trans_origin()const;
218
219         void set_radius(bool r) { radius_=r; }
220         bool is_radius()const { return radius_; }
221
222         //! Sets the name of the duck
223         void set_name(const synfig::String &x);
224
225         //! Retrieves the name of the duck
226         synfig::String get_name()const { return name; }
227
228         bool operator==(const Duck &rhs)const;
229 }; // END of class Duck
230
231 //! Combine Flags
232 inline Duck::Type
233 operator|(Duck::Type lhs, const Duck::Type rhs)
234 { return static_cast<Duck::Type>(int(lhs)|int(rhs)); }
235
236 //! Exclude Flags
237 inline Duck::Type
238 operator-(Duck::Type lhs, const Duck::Type rhs)
239 { return static_cast<Duck::Type>(int(lhs)&~int(rhs)); }
240
241 inline Duck::Type&
242 operator|=(Duck::Type& lhs, const Duck::Type rhs)
243 { *reinterpret_cast<int*>(&lhs)|=int(rhs); return lhs; }
244
245 inline Duck::Type
246 operator&(const Duck::Type lhs, const Duck::Type rhs)
247 { return static_cast<Duck::Type>(int(lhs)&int(rhs)); }
248
249 class DuckMap : public
250 #ifdef HASH_MAP_H
251 HASH_MAP_CLASS<synfig::GUID,etl::handle<studio::Duck>,synfig::GUIDHash>
252 {
253         typedef HASH_MAP_CLASS<synfig::GUID,etl::handle<studio::Duck>,synfig::GUIDHash> PARENT_TYPE;
254 #else
255 std::map<synfig::GUID,etl::handle<studio::Duck> >
256 {
257         typedef std::map<synfig::GUID,etl::handle<studio::Duck> > PARENT_TYPE;
258 #endif
259 public:
260         void insert(const Duck::Handle& x) { operator[](x->get_guid())=x;  }
261 }; // END of class DuckMap
262
263 typedef std::list<Duck::Handle> DuckList;
264
265 }; // END of namespace studio
266
267 /* === E N D =============================================================== */
268
269 #endif