Use translated versions of the type names everywhere other than in the .sif(z) files.
[synfig.git] / synfig-core / trunk / src / synfig / valuenode_twotone.cpp
1 /* === S Y N F I G ========================================================= */
2 /*!     \file valuenode_twotone.cpp
3 **      \brief Implementation of the "Two-Tone" valuenode conversion.
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 /* === H E A D E R S ======================================================= */
24
25 #ifdef USING_PCH
26 #       include "pch.h"
27 #else
28 #ifdef HAVE_CONFIG_H
29 #       include <config.h>
30 #endif
31
32 #include "general.h"
33 #include "valuenode_twotone.h"
34 #include "valuenode_const.h"
35 #include <stdexcept>
36 #include "color.h"
37 #include "gradient.h"
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 synfig::ValueNode_TwoTone::ValueNode_TwoTone():LinkableValueNode(synfig::ValueBase::TYPE_GRADIENT)
56 {
57         set_link("color1",ValueNode_Const::create(Color::black()));
58         set_link("color2",ValueNode_Const::create(Color::white()));
59         DCAST_HACK_ENABLE();
60 }
61
62 LinkableValueNode*
63 ValueNode_TwoTone::create_new()const
64 {
65         return new ValueNode_TwoTone();
66 }
67
68 ValueNode_TwoTone*
69 ValueNode_TwoTone::create(const ValueBase& x)
70 {
71         ValueBase::Type id(x.get_type());
72         if(id!=ValueBase::TYPE_GRADIENT)
73         {
74                 assert(0);
75                 throw runtime_error(_("synfig::ValueNode_TwoTone:Bad type ")+ValueBase::type_local_name(id));
76         }
77
78         ValueNode_TwoTone* value_node=new ValueNode_TwoTone();
79
80         assert(value_node->get_type()==id);
81
82         return value_node;
83 }
84
85 synfig::ValueNode_TwoTone::~ValueNode_TwoTone()
86 {
87         unlink_all();
88 }
89
90 bool
91 synfig::ValueNode_TwoTone::set_lhs(ValueNode::Handle a)
92 {
93         if(a->get_type()!=ValueBase::TYPE_COLOR)
94                 return false;
95
96         ref_a=a;
97
98         return true;
99 }
100
101 bool
102 synfig::ValueNode_TwoTone::set_rhs(ValueNode::Handle b)
103 {
104         if(b->get_type()!=ValueBase::TYPE_COLOR)
105                 return false;
106         ref_b=b;
107         return true;
108 }
109
110 synfig::ValueBase
111 synfig::ValueNode_TwoTone::operator()(Time t)const
112 {
113         return Gradient((*ref_a)(t).get(Color()),(*ref_b)(t).get(Color()));
114 }
115
116 bool
117 ValueNode_TwoTone::set_link_vfunc(int i,ValueNode::Handle x)
118 {
119         assert(i>=0 && i<link_count());
120
121         switch(i)
122         {
123                 case 0:
124                         if(set_lhs(x)) { signal_child_changed()(i);signal_value_changed()(); return true; }
125                         else { return false; }
126                 case 1:
127                         if(set_rhs(x)) { signal_child_changed()(i);signal_value_changed()(); return true; }
128                         else { return false; }
129         }
130
131         return false;
132 }
133
134 ValueNode::LooseHandle
135 ValueNode_TwoTone::get_link_vfunc(int i)const
136 {
137         assert(i>=0 && i<link_count());
138
139         switch(i)
140         {
141                 case 0:
142                         return ref_a;
143                 case 1:
144                         return ref_b;
145         }
146         return 0;
147 }
148
149 int
150 ValueNode_TwoTone::link_count()const
151 {
152         return 2;
153 }
154
155 String
156 ValueNode_TwoTone::link_local_name(int i)const
157 {
158         assert(i>=0 && i<link_count());
159
160         switch(i)
161         {
162                 case 0:
163                         return _("Color1");
164                 case 1:
165                         return _("Color2");
166                 default:
167                         return String();
168         }
169 }
170
171 String
172 ValueNode_TwoTone::link_name(int i)const
173 {
174         assert(i>=0 && i<link_count());
175
176         switch(i)
177         {
178                 case 0:
179                         return "color1";
180                 case 1:
181                         return "color2";
182                 default:
183                         return String();
184         }
185 }
186
187 int
188 ValueNode_TwoTone::get_link_index_from_name(const String &name)const
189 {
190         if(name=="color1")
191                 return 0;
192         if(name=="color2")
193                 return 1;
194         throw Exception::BadLinkName(name);
195 }
196
197 String
198 ValueNode_TwoTone::get_name()const
199 {
200         return "twotone";
201 }
202
203 String
204 ValueNode_TwoTone::get_local_name()const
205 {
206         return _("Two-Tone");
207 }
208
209 bool
210 ValueNode_TwoTone::check_type(ValueBase::Type type)
211 {
212         return type==ValueBase::TYPE_GRADIENT;
213 }