1 /* === S I N F 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 Robert B. Quattlebaum Jr.
10 ** This software and associated documentation
11 ** are CONFIDENTIAL and PROPRIETARY property of
12 ** the above-mentioned copyright holder.
14 ** You may not copy, print, publish, or in any
15 ** other way distribute this software without
16 ** a prior written agreement with
17 ** the copyright holder.
20 /* ========================================================================= */
22 /* === S T A R T =========================================================== */
24 #ifndef __SINFG_DUCKMATIC_DUCK_H
25 #define __SINFG_DUCKMATIC_DUCK_H
27 /* === H E A D E R S ======================================================= */
31 #include <ETL/smart_ptr>
34 #include <sinfg/vector.h>
35 #include <sinfg/string.h>
36 #include <sinfg/real.h>
37 #include <sigc++/signal.h>
38 #include <sigc++/object.h>
39 #include <sinfg/time.h>
40 #include <ETL/smart_ptr>
41 #include <sinfgapp/value_desc.h>
42 #include <sinfg/transform.h>
44 /* === M A C R O S ========================================================= */
46 #define HASH_MAP_H <ext/hash_map>
47 #define HASH_SET_H <ext/hash_set>
51 #ifndef __STRING_HASH__
52 #define __STRING_HASH__
55 __gnu_cxx::hash<const char*> hasher_;
57 size_t operator()(const sinfg::String& x)const
59 return hasher_(x.c_str());
69 /* === T Y P E D E F S ===================================================== */
71 /* === C L A S S E S & S T R U C T S ======================================= */
78 class Duck : public etl::shared_object
80 friend class Duckmatic;
86 TYPE_POSITION = (1<<0),
87 TYPE_TANGENT = (1<<1),
95 TYPE_DEFAULT = 0xdefadefa
98 typedef etl::handle<Duck> Handle;
99 typedef etl::loose_handle<Duck> LooseHandle;
103 sigc::signal<bool,const sinfg::Point &> signal_edited_;
104 sigc::signal<void> signal_user_click_[5];
110 etl::smart_ptr<sinfg::Point> shared_point;
116 etl::handle<Duck> origin_duck;
118 etl::handle<Duck> connect_duck;
119 etl::handle<Duck> box_duck;
128 sinfg::TransformStack transform_stack_;
130 sinfgapp::ValueDesc value_desc_;
132 static int duck_count;
135 Duck(const sinfg::Point &point);
136 Duck(const sinfg::Point &point,const sinfg::Point &origin);
139 sigc::signal<bool,const sinfg::Point &> &signal_edited() { return signal_edited_; }
140 sigc::signal<void> &signal_user_click(int i=0) { assert(i>=0); assert(i<5); return signal_user_click_[i]; }
142 void set_guid(const sinfg::GUID& x) { guid_=x; }
143 const sinfg::GUID& get_guid()const { return guid_; }
145 sinfg::GUID get_data_guid()const;
147 //! Changes the editable flag. If set, the duck will not be able to be moved.
148 void set_editable(bool x) { editable=x; }
150 //! Retrieves the status of the editable flag
151 bool get_editable()const { return editable; }
154 void set_tangent(bool x) { tangent_=x; type_=TYPE_TANGENT; }
157 bool get_tangent()const { return tangent_; }
159 void set_connect_duck(const etl::handle<Duck>& x) { connect_duck=x; }
160 void set_box_duck(const etl::handle<Duck>& x) { box_duck=x; }
162 const etl::handle<Duck>& get_connect_duck()const { return connect_duck; }
163 const etl::handle<Duck>& get_box_duck()const { return box_duck; }
165 void set_value_desc(sinfgapp::ValueDesc x) { value_desc_=x; }
167 sinfgapp::ValueDesc& get_value_desc() { return value_desc_; }
169 void set_transform_stack(const sinfg::TransformStack& x) { transform_stack_=x; }
171 const sinfg::TransformStack& get_transform_stack()const { return transform_stack_; }
174 void set_type(Type x) { type_=x; }
177 Type get_type()const { return type_; }
179 //! Sets the scalar multiplier for the duck with respect to the origin
180 void set_scalar(sinfg::Vector::value_type n) { scalar=n; }
182 //! Retrieves the scalar value
183 sinfg::Vector::value_type get_scalar()const { return scalar; }
185 void set_shared_point(const etl::smart_ptr<sinfg::Point>&x) { shared_point=x; }
187 //! Sets the location of the duck with respect to the origin
188 void set_point(const sinfg::Point &x) { (shared_point?*shared_point:point)=x; }
190 //! Returns the location of the duck
191 sinfg::Point get_point()const { return shared_point?*shared_point:point; }
193 sinfg::Point get_trans_point()const;
195 void set_trans_point(const sinfg::Point &x);
197 sinfg::Point get_sub_trans_point()const;
198 void set_sub_trans_point(const sinfg::Point &x);
199 sinfg::Point get_sub_trans_origin()const;
201 //! Sets the origin point.
202 void set_origin(const sinfg::Point &x);
204 //! Sets the origin point as another duck
205 void set_origin(const etl::handle<Duck> &x);
207 //! Retrieves the origin location
208 sinfg::Point get_origin()const;
210 //! Retrieves the origin duck
211 const etl::handle<Duck> & get_origin_duck() const;
213 //! Retrieves the origin location
214 sinfg::Point get_trans_origin()const;
216 void set_radius(bool r) { radius_=r; }
217 bool is_radius()const { return radius_; }
219 //! Sets the name of the duck
220 void set_name(const sinfg::String &x);
222 //! Retrieves the name of the duck
223 sinfg::String get_name()const { return name; }
225 bool operator==(const Duck &rhs)const;
226 }; // END of class Duck
230 operator|(Duck::Type lhs, const Duck::Type rhs)
231 { return static_cast<Duck::Type>(int(lhs)|int(rhs)); }
235 operator-(Duck::Type lhs, const Duck::Type rhs)
236 { return static_cast<Duck::Type>(int(lhs)&~int(rhs)); }
239 operator|=(Duck::Type& lhs, const Duck::Type rhs)
240 { *reinterpret_cast<int*>(&lhs)|=int(rhs); return lhs; }
243 operator&(const Duck::Type lhs, const Duck::Type rhs)
244 { return static_cast<Duck::Type>(int(lhs)&int(rhs)); }
246 class DuckMap : public
248 __gnu_cxx::hash_map<sinfg::GUID,etl::handle<studio::Duck>,sinfg::GUIDHash>
250 typedef __gnu_cxx::hash_map<sinfg::GUID,etl::handle<studio::Duck>,sinfg::GUIDHash> PARENT_TYPE;
252 std::map<sinfg::GUID,etl::handle<studio::Duck> >
254 typedef std::map<sinfg::GUID,etl::handle<studio::Duck> > PARENT_TYPE;
257 void insert(const Duck::Handle& x) { operator[](x->get_guid())=x; }
258 }; // END of class DuckMap
260 typedef std::list<Duck::Handle> DuckList;
262 }; // END of namespace studio
264 /* === E N D =============================================================== */