Use translated versions of the type names everywhere other than in the .sif(z) files.
[synfig.git] / synfig-core / trunk / src / synfig / valuenode_linear.cpp
1 /* === S Y N F I G ========================================================= */
2 /*!     \file valuenode_linear.cpp
3 **      \brief Implementation of the "Linear" valuenode conversion.
4 **
5 **      $Id$
6 **
7 **      \legal
8 **      Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
9 **      Copyright (c) 2007 Chris Moore
10 **
11 **      This package is free software; you can redistribute it and/or
12 **      modify it under the terms of the GNU General Public License as
13 **      published by the Free Software Foundation; either version 2 of
14 **      the License, or (at your option) any later version.
15 **
16 **      This package is distributed in the hope that it will be useful,
17 **      but WITHOUT ANY WARRANTY; without even the implied warranty of
18 **      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 **      General Public License for more details.
20 **      \endlegal
21 */
22 /* ========================================================================= */
23
24 /* === H E A D E R S ======================================================= */
25
26 #ifdef USING_PCH
27 #       include "pch.h"
28 #else
29 #ifdef HAVE_CONFIG_H
30 #       include <config.h>
31 #endif
32
33 #include "valuenode_linear.h"
34 #include "valuenode_const.h"
35 #include "general.h"
36 #include "color.h"
37 #include <ETL/misc>
38
39 #endif
40
41 /* === U S I N G =========================================================== */
42
43 using namespace std;
44 using namespace etl;
45 using namespace synfig;
46
47 /* === M A C R O S ========================================================= */
48
49 /* === G L O B A L S ======================================================= */
50
51 /* === P R O C E D U R E S ================================================= */
52
53 /* === M E T H O D S ======================================================= */
54
55 ValueNode_Linear::ValueNode_Linear(const ValueBase &value):
56         LinkableValueNode(value.get_type())
57 {
58         switch(get_type())
59         {
60         case ValueBase::TYPE_ANGLE:
61                 set_link("slope",ValueNode_Const::create(Angle::deg(0)));
62                 set_link("offset",ValueNode_Const::create(value.get(Angle())));
63                 break;
64         case ValueBase::TYPE_COLOR:
65                 set_link("slope",ValueNode_Const::create(Color(0,0,0,0)));
66                 set_link("offset",ValueNode_Const::create(value.get(Color())));
67                 break;
68         case ValueBase::TYPE_INTEGER:
69                 set_link("slope",ValueNode_Const::create(int(0)));
70                 set_link("offset",ValueNode_Const::create(value.get(int())));
71                 break;
72         case ValueBase::TYPE_REAL:
73                 set_link("slope",ValueNode_Const::create(Real(0)));
74                 set_link("offset",ValueNode_Const::create(value.get(Real())));
75                 break;
76         case ValueBase::TYPE_TIME:
77                 set_link("slope",ValueNode_Const::create(Time(0)));
78                 set_link("offset",ValueNode_Const::create(value.get(Time())));
79                 break;
80         case ValueBase::TYPE_VECTOR:
81                 set_link("slope",ValueNode_Const::create(Vector(0,0)));
82                 set_link("offset",ValueNode_Const::create(value.get(Vector())));
83                 break;
84         default:
85                 throw Exception::BadType(ValueBase::type_local_name(get_type()));
86         }
87
88         DCAST_HACK_ENABLE();
89 }
90
91 LinkableValueNode*
92 ValueNode_Linear::create_new()const
93 {
94         return new ValueNode_Linear(get_type());
95 }
96
97 ValueNode_Linear*
98 ValueNode_Linear::create(const ValueBase &x)
99 {
100         return new ValueNode_Linear(x);
101 }
102
103 ValueNode_Linear::~ValueNode_Linear()
104 {
105         unlink_all();
106 }
107
108 ValueBase
109 ValueNode_Linear::operator()(Time t)const
110 {
111         switch(get_type())
112         {
113         case ValueBase::TYPE_ANGLE:
114                 return (*m_)(t).get( Angle())*t+(*b_)(t).get( Angle());
115         case ValueBase::TYPE_COLOR:
116                 return (*m_)(t).get( Color())*t+(*b_)(t).get( Color());
117         case ValueBase::TYPE_INTEGER:
118                 return round_to_int((*m_)(t).get(int())*t+(*b_)(t).get(int()));
119         case ValueBase::TYPE_REAL:
120                 return (*m_)(t).get(  Real())*t+(*b_)(t).get(  Real());
121         case ValueBase::TYPE_TIME:
122                 return (*m_)(t).get(  Time())*t+(*b_)(t).get(  Time());
123         case ValueBase::TYPE_VECTOR:
124                 return (*m_)(t).get(Vector())*t+(*b_)(t).get(Vector());
125         default:
126                 assert(0);
127                 break;
128         }
129         return ValueBase();
130 }
131
132
133 String
134 ValueNode_Linear::get_name()const
135 {
136         return "linear";
137 }
138
139 String
140 ValueNode_Linear::get_local_name()const
141 {
142         return _("Linear");
143 }
144
145 bool
146 ValueNode_Linear::check_type(ValueBase::Type type)
147 {
148         return
149                 type==ValueBase::TYPE_ANGLE             ||
150                 type==ValueBase::TYPE_COLOR             ||
151                 type==ValueBase::TYPE_INTEGER   ||
152                 type==ValueBase::TYPE_REAL              ||
153                 type==ValueBase::TYPE_TIME              ||
154                 type==ValueBase::TYPE_VECTOR    ;
155 }
156
157 bool
158 ValueNode_Linear::set_link_vfunc(int i,ValueNode::Handle x)
159 {
160         assert(i>=0 && i<link_count());
161
162         if(i==0)
163         {
164                 m_=x;
165                 signal_child_changed()(i);signal_value_changed()();
166                 return true;
167         }
168         if(i==1)
169         {
170                 b_=x;
171                 signal_child_changed()(i);signal_value_changed()();
172                 return true;
173         }
174         return false;
175 }
176
177 ValueNode::LooseHandle
178 ValueNode_Linear::get_link_vfunc(int i)const
179 {
180         assert(i>=0 && i<link_count());
181
182         if(i==0) return m_;
183         if(i==1) return b_;
184         return 0;
185 }
186
187 int
188 ValueNode_Linear::link_count()const
189 {
190         return 2;
191 }
192
193 String
194 ValueNode_Linear::link_name(int i)const
195 {
196         assert(i>=0 && i<link_count());
197
198         if(i==0) return "slope";
199         if(i==1) return "offset";
200         return String();
201 }
202
203 String
204 ValueNode_Linear::link_local_name(int i)const
205 {
206         assert(i>=0 && i<link_count());
207
208         if(i==0)
209                 switch(get_type())
210                 {
211                 case ValueBase::TYPE_ANGLE:
212                 case ValueBase::TYPE_COLOR:
213                 case ValueBase::TYPE_INTEGER:
214                 case ValueBase::TYPE_REAL:
215                 case ValueBase::TYPE_TIME:
216                         return _("Rate");
217                 case ValueBase::TYPE_VECTOR:
218                 default:
219                         return _("Slope");
220                 }
221         if(i==1)
222                 return _("Offset");
223         return String();
224 }
225
226 int
227 ValueNode_Linear::get_link_index_from_name(const String &name)const
228 {
229         if(name=="slope")  return 0;
230         if(name=="offset") return 1;
231
232         throw Exception::BadLinkName(name);
233 }