initial version
[synfig.git] / synfig-studio / trunk / src / gtkmm / duck.cpp
1 /* === S I N F G =========================================================== */
2 /*!     \file duck.cpp
3 **      \brief Template File
4 **
5 **      $Id: duck.cpp,v 1.1.1.1 2005/01/07 03:34:36 darco Exp $
6 **
7 **      \legal
8 **      Copyright (c) 2002 Robert B. Quattlebaum Jr.
9 **
10 **      This software and associated documentation
11 **      are CONFIDENTIAL and PROPRIETARY property of
12 **      the above-mentioned copyright holder.
13 **
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.
18 **      \endlegal
19 */
20 /* ========================================================================= */
21
22 /* === H E A D E R S ======================================================= */
23
24 #ifdef USING_PCH
25 #       include "pch.h"
26 #else
27 #ifdef HAVE_CONFIG_H
28 #       include <config.h>
29 #endif
30
31 #include "duck.h"
32
33 #endif
34
35 /* === U S I N G =========================================================== */
36
37 using namespace std;
38 using namespace etl;
39 using namespace sinfg;
40 using namespace studio;
41
42 /* === M A C R O S ========================================================= */
43
44 /* === G L O B A L S ======================================================= */
45
46 int studio::Duck::duck_count(0);
47
48 struct _DuckCounter
49 {
50         static int counter;
51         ~_DuckCounter()
52         {
53                 if(counter)
54                         sinfg::error("%d ducks not yet deleted!",counter);
55         }
56 } _duck_counter;
57
58 int _DuckCounter::counter(0);
59
60
61 /* === P R O C E D U R E S ================================================= */
62
63 /* === M E T H O D S ======================================================= */
64
65 Duck::Duck():
66         origin(0,0),
67         scalar(1),
68         editable(false),
69         radius_(false),
70         tangent_(false)
71 { duck_count++; _DuckCounter::counter++; }
72
73 Duck::Duck(const sinfg::Point &point):
74         type_(TYPE_NONE),
75         point(point),
76         origin(0,0),
77         scalar(1),
78         guid_(0),
79         editable(false),
80         radius_(false),
81         tangent_(false)
82 { duck_count++; _DuckCounter::counter++;}
83
84 Duck::Duck(const sinfg::Point &point,const sinfg::Point &origin):
85         point(point),
86         origin(origin),
87         scalar(1),
88         guid_(0),
89         editable(false),
90         radius_(true),
91         tangent_(false)
92 { duck_count++; _DuckCounter::counter++;}
93
94 Duck::~Duck() { duck_count--; _DuckCounter::counter--;}
95
96 sinfg::GUID
97 Duck::get_data_guid()const
98 {
99         if(value_desc_.is_value_node())
100                 return value_desc_.get_value_node()->get_guid();
101         return GUID::hasher(get_name());
102 }
103
104 void
105 Duck::set_name(const sinfg::String &x)
106 {
107         name=x;
108         if(guid_==GUID::zero())
109         {
110                 guid_=GUID::hasher(name);
111         }
112 }
113
114
115 bool
116 Duck::operator==(const Duck &rhs)const
117 {
118         if(this==&rhs)
119                 return true;
120         return
121                 name==rhs.name &&
122                 scalar==rhs.scalar &&
123                 type_==rhs.type_ &&
124                 transform_stack_.size()==rhs.transform_stack_.size();
125                 //true;
126                 //(origin_duck?*origin_duck==*rhs.origin_duck:origin==rhs.origin) &&
127                 //(shared_point?*shared_point==*rhs.shared_point:point==rhs.point) ;
128 }
129
130 sinfg::Point
131 Duck::get_trans_point()const
132 {
133         return transform_stack_.perform(get_sub_trans_point());
134 }
135         
136 void
137 Duck::set_trans_point(const sinfg::Point &x)
138 {
139         set_sub_trans_point(transform_stack_.unperform(x));
140 }
141
142 //! Sets the origin point.
143 void
144 Duck::set_origin(const sinfg::Point &x)
145 {
146         origin=x; origin_duck=0;
147 }
148
149 //! Sets the origin point as another duck
150 void
151 Duck::set_origin(const etl::handle<Duck> &x)
152 {
153         origin_duck=x;
154 }
155
156 //! Retrieves the origin location
157 sinfg::Point
158 Duck::get_origin()const
159 {
160         return origin_duck?origin_duck->get_point():origin;
161 }
162
163 //! Retrieves the origin duck
164 const etl::handle<Duck> &
165 Duck::get_origin_duck() const
166 {
167         return origin_duck;
168 }
169
170 //! Retrieves the origin location
171 sinfg::Point
172 Duck::get_trans_origin()const
173 {
174         return transform_stack_.perform(get_sub_trans_origin());
175 }
176
177 sinfg::Point
178 Duck::get_sub_trans_point()const
179 {
180         return get_point()*get_scalar()+get_sub_trans_origin();
181 }
182
183 void
184 Duck::set_sub_trans_point(const sinfg::Point &x)
185 {
186         set_point((x-get_sub_trans_origin())/get_scalar());
187 }
188
189 sinfg::Point
190 Duck::get_sub_trans_origin()const
191 {
192         return origin_duck?origin_duck->get_sub_trans_point():origin;
193 }