00001
00022
00023
00024
00025
00026 #ifndef __SYNFIG_DUCKMATIC_DUCK_H
00027 #define __SYNFIG_DUCKMATIC_DUCK_H
00028
00029
00030
00031 #include <list>
00032
00033 #include <ETL/smart_ptr>
00034 #include <ETL/handle>
00035
00036 #include <synfig/vector.h>
00037 #include <synfig/string.h>
00038 #include <synfig/real.h>
00039 #include <sigc++/signal.h>
00040 #include <sigc++/object.h>
00041 #include <synfig/time.h>
00042 #include <ETL/smart_ptr>
00043 #include <synfigapp/value_desc.h>
00044 #include <synfig/transform.h>
00045
00046
00047
00048 #ifdef HASH_MAP_H
00049 #include HASH_MAP_H
00050 #include FUNCTIONAL_H
00051
00052 #ifndef __STRING_HASH__
00053 #define __STRING_HASH__
00054 class StringHash
00055 {
00056 # ifdef FUNCTIONAL_HASH_ON_STRING
00057 HASH_MAP_NAMESPACE::hash<synfig::String> hasher_;
00058 # else // FUNCTIONAL_HASH_ON_STRING
00059 HASH_MAP_NAMESPACE::hash<const char*> hasher_;
00060 # endif // FUNCTIONAL_HASH_ON_STRING
00061 public:
00062 size_t operator()(const synfig::String& x)const
00063 {
00064 # ifdef FUNCTIONAL_HASH_ON_STRING
00065 return hasher_(x);
00066 # else // FUNCTIONAL_HASH_ON_STRING
00067 return hasher_(x.c_str());
00068 # endif // FUNCTIONAL_HASH_ON_STRING
00069 }
00070 };
00071 #endif
00072 #else
00073 #include <map>
00074 #endif
00075
00076 #include <set>
00077
00078
00079
00080
00081
00082 namespace studio {
00083 class Duckmatic;
00084
00087 class Duck : public etl::shared_object
00088 {
00089 friend class Duckmatic;
00090
00091 public:
00092 enum Type
00093 {
00094 TYPE_NONE = (0),
00095 TYPE_POSITION = (1<<0),
00096 TYPE_TANGENT = (1<<1),
00097 TYPE_RADIUS = (1<<2),
00098 TYPE_WIDTH = (1<<3),
00099 TYPE_ANGLE = (1<<4),
00100 TYPE_VERTEX = (1<<5),
00101
00102 TYPE_ALL = (~0),
00103
00104 TYPE_DEFAULT = 0xdefadefa
00105 };
00106
00107 typedef etl::handle<Duck> Handle;
00108 typedef etl::loose_handle<Duck> LooseHandle;
00109
00110 private:
00111
00112 sigc::signal<bool,const synfig::Point &> signal_edited_;
00113 sigc::signal<bool,const synfig::Angle &> signal_edited_angle_;
00114 sigc::signal<void> signal_user_click_[5];
00115
00116 Type type_;
00117
00118 synfig::Point point;
00119 synfig::Angle rotations;
00120
00121 etl::smart_ptr<synfig::Point> shared_point;
00122
00123 synfig::Point origin;
00124 synfig::String name;
00125 synfig::Real scalar;
00126
00127 etl::handle<Duck> origin_duck;
00128
00129 etl::handle<Duck> connect_duck;
00130 etl::handle<Duck> box_duck;
00131
00132 synfig::GUID guid_;
00133
00134
00135 bool editable;
00136 bool radius_;
00137 bool tangent_;
00138 bool hover_;
00139 bool ignore_;
00140
00141 synfig::TransformStack transform_stack_;
00142
00143 synfigapp::ValueDesc value_desc_;
00144
00145 static int duck_count;
00146 public:
00147 Duck();
00148 Duck(const synfig::Point &point);
00149 Duck(const synfig::Point &point,const synfig::Point &origin);
00150 ~Duck();
00151
00152 sigc::signal<bool,const synfig::Point &> &signal_edited() { return signal_edited_; }
00153 sigc::signal<bool,const synfig::Angle &> &signal_edited_angle() { return signal_edited_angle_; }
00154 sigc::signal<void> &signal_user_click(int i=0) { assert(i>=0); assert(i<5); return signal_user_click_[i]; }
00155
00156 void set_guid(const synfig::GUID& x) { guid_=x; }
00157 const synfig::GUID& get_guid()const { return guid_; }
00158
00159 synfig::GUID get_data_guid()const;
00160
00162 void set_editable(bool x) { editable=x; }
00163
00165 bool get_editable()const { return editable; }
00166
00168 void set_tangent(bool x) { tangent_=x; type_=TYPE_TANGENT; }
00169
00171 bool get_tangent()const { return tangent_; }
00172
00174 void set_hover(bool h) { hover_=h; }
00175
00177 bool get_hover()const { return hover_; }
00178
00180 void set_ignore(bool i) { ignore_=i; }
00181
00183 bool get_ignore()const { return ignore_; }
00184
00185 void set_connect_duck(const etl::handle<Duck>& x) { connect_duck=x; }
00186 void set_box_duck(const etl::handle<Duck>& x) { box_duck=x; }
00187
00188 const etl::handle<Duck>& get_connect_duck()const { return connect_duck; }
00189 const etl::handle<Duck>& get_box_duck()const { return box_duck; }
00190
00191 void set_value_desc(synfigapp::ValueDesc x) { value_desc_=x; }
00192
00193 synfigapp::ValueDesc& get_value_desc() { return value_desc_; }
00194
00195 void set_transform_stack(const synfig::TransformStack& x) { transform_stack_=x; }
00196
00197 const synfig::TransformStack& get_transform_stack()const { return transform_stack_; }
00198
00200 void set_type(Type x) { type_=x; }
00201
00203 Type get_type()const { return type_; }
00204
00206 void set_scalar(synfig::Vector::value_type n) { scalar=n; }
00207
00209 synfig::Vector::value_type get_scalar()const { return scalar; }
00210
00211 void set_shared_point(const etl::smart_ptr<synfig::Point>&x) { shared_point=x; }
00212
00214 void set_point(const synfig::Point &x) { (shared_point?*shared_point:point)=x; }
00215
00217 synfig::Point get_point()const { return shared_point?*shared_point:point; }
00218
00219 synfig::Angle get_rotations()const { return rotations; };
00220
00221 synfig::Point get_trans_point()const;
00222
00223 void set_trans_point(const synfig::Point &x);
00224
00225 synfig::Point get_sub_trans_point()const;
00226 void set_sub_trans_point(const synfig::Point &x);
00227 synfig::Point get_sub_trans_origin()const;
00228
00230 void set_origin(const synfig::Point &x);
00231
00233 void set_origin(const etl::handle<Duck> &x);
00234
00236 synfig::Point get_origin()const;
00237
00239 const etl::handle<Duck> & get_origin_duck() const;
00240
00242 synfig::Point get_trans_origin()const;
00243
00244 void set_radius(bool r) { radius_=r; }
00245 bool is_radius()const { return radius_; }
00246
00248 void set_name(const synfig::String &x);
00249
00251 synfig::String get_name()const { return name; }
00252
00253 bool operator==(const Duck &rhs)const;
00254
00255 #ifdef _DEBUG
00257 static synfig::String type_name(Type id);
00258
00260 synfig::String type_name()const { return type_name(get_type()); }
00261 #endif // _DEBUG
00262
00263 };
00264
00266 inline Duck::Type
00267 operator|(Duck::Type lhs, const Duck::Type rhs)
00268 { return static_cast<Duck::Type>(int(lhs)|int(rhs)); }
00269
00271 inline Duck::Type
00272 operator-(Duck::Type lhs, const Duck::Type rhs)
00273 { return static_cast<Duck::Type>(int(lhs)&~int(rhs)); }
00274
00275 inline Duck::Type&
00276 operator|=(Duck::Type& lhs, const Duck::Type rhs)
00277 { *reinterpret_cast<int*>(&lhs)|=int(rhs); return lhs; }
00278
00279 inline Duck::Type
00280 operator&(const Duck::Type lhs, const Duck::Type rhs)
00281 { return static_cast<Duck::Type>(int(lhs)&int(rhs)); }
00282
00283 class DuckMap : public
00284 #ifdef HASH_MAP_H
00285 HASH_MAP_CLASS<synfig::GUID,etl::handle<studio::Duck>,synfig::GUIDHash>
00286 {
00287 typedef HASH_MAP_CLASS<synfig::GUID,etl::handle<studio::Duck>,synfig::GUIDHash> PARENT_TYPE;
00288 #else
00289 std::map<synfig::GUID,etl::handle<studio::Duck> >
00290 {
00291 typedef std::map<synfig::GUID,etl::handle<studio::Duck> > PARENT_TYPE;
00292 #endif
00293 public:
00294 void insert(const Duck::Handle& x) { operator[](x->get_guid())=x; }
00295 };
00296
00297 typedef std::list<Duck::Handle> DuckList;
00298
00299 };
00300
00301
00302
00303 #endif