Fix bugs in previous commit that caused FTBFS in synfig and ETL FTBFS with older...
[synfig.git] / synfig-core / tags / synfig_0_61_07_rc2 / src / synfig / valuenode_twotone.cpp
1 /* === S Y N F I G ========================================================= */
2 /*!     \file valuenode_twotone.cpp
3 **      \brief Template File
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_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<3);
120         switch(i)
121         {
122                 case 0:
123                         if(set_lhs(x)) { signal_child_changed()(i);signal_value_changed()(); return true; }
124                         else { return false; }
125                 case 1:
126                         if(set_rhs(x)) { signal_child_changed()(i);signal_value_changed()(); return true; }
127                         else { return false; }
128         }
129
130         return false;
131 }
132
133 ValueNode::LooseHandle
134 ValueNode_TwoTone::get_link_vfunc(int i)const
135 {
136         assert(i>=0 && i<3);
137         switch(i)
138         {
139                 case 0:
140                         return ref_a;
141                 case 1:
142                         return ref_b;
143         }
144         return 0;
145 }
146
147 int
148 ValueNode_TwoTone::link_count()const
149 {
150         return 2;
151 }
152
153 String
154 ValueNode_TwoTone::link_local_name(int i)const
155 {
156         assert(i>=0 && i<2);
157         switch(i)
158         {
159                 case 0:
160                         return _("Color1");
161                 case 1:
162                         return _("Color2");
163                 default:
164                         return String();
165         }
166 }
167
168 String
169 ValueNode_TwoTone::link_name(int i)const
170 {
171         assert(i>=0 && i<2);
172         switch(i)
173         {
174                 case 0:
175                         return "color1";
176                 case 1:
177                         return "color2";
178                 default:
179                         return String();
180         }
181 }
182
183 int
184 ValueNode_TwoTone::get_link_index_from_name(const String &name)const
185 {
186         if(name=="color1")
187                 return 0;
188         if(name=="color2")
189                 return 1;
190         throw Exception::BadLinkName(name);
191 }
192
193 String
194 ValueNode_TwoTone::get_name()const
195 {
196         return "twotone";
197 }
198
199 String
200 ValueNode_TwoTone::get_local_name()const
201 {
202         return _("Two-Tone");
203 }
204
205 bool
206 ValueNode_TwoTone::check_type(ValueBase::Type type)
207 {
208         return type==ValueBase::TYPE_GRADIENT;
209 }