Fix bugs in previous commit that caused FTBFS in synfig and ETL FTBFS with older...
[synfig.git] / synfig-core / tags / 0.61.09 / 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 **      Copyright (c) 2008 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 "general.h"
34 #include "valuenode_twotone.h"
35 #include "valuenode_const.h"
36 #include <stdexcept>
37 #include "color.h"
38 #include "gradient.h"
39
40 #endif
41
42 /* === U S I N G =========================================================== */
43
44 using namespace std;
45 using namespace etl;
46 using namespace synfig;
47
48 /* === M A C R O S ========================================================= */
49
50 /* === G L O B A L S ======================================================= */
51
52 /* === P R O C E D U R E S ================================================= */
53
54 /* === M E T H O D S ======================================================= */
55
56 synfig::ValueNode_TwoTone::ValueNode_TwoTone(const ValueBase &value):LinkableValueNode(synfig::ValueBase::TYPE_GRADIENT)
57 {
58         switch(value.get_type())
59         {
60         case ValueBase::TYPE_GRADIENT:
61                 set_link("color1",ValueNode_Const::create(value.get(Gradient())(0)));
62                 set_link("color2",ValueNode_Const::create(value.get(Gradient())(1)));
63                 break;
64         default:
65                 throw Exception::BadType(ValueBase::type_local_name(value.get_type()));
66         }
67
68         DCAST_HACK_ENABLE();
69 }
70
71 LinkableValueNode*
72 ValueNode_TwoTone::create_new()const
73 {
74         return new ValueNode_TwoTone(get_type());
75 }
76
77 ValueNode_TwoTone*
78 ValueNode_TwoTone::create(const ValueBase& x)
79 {
80         return new ValueNode_TwoTone(x);
81 }
82
83 synfig::ValueNode_TwoTone::~ValueNode_TwoTone()
84 {
85         unlink_all();
86 }
87
88 synfig::ValueBase
89 synfig::ValueNode_TwoTone::operator()(Time t)const
90 {
91         return Gradient((*ref_a)(t).get(Color()),(*ref_b)(t).get(Color()));
92 }
93
94 bool
95 ValueNode_TwoTone::set_link_vfunc(int i,ValueNode::Handle value)
96 {
97         assert(i>=0 && i<link_count());
98
99         switch(i)
100         {
101         case 0: CHECK_TYPE_AND_SET_VALUE(ref_a, ValueBase::TYPE_COLOR);
102         case 1: CHECK_TYPE_AND_SET_VALUE(ref_b, ValueBase::TYPE_COLOR);
103         }
104         return false;
105 }
106
107 ValueNode::LooseHandle
108 ValueNode_TwoTone::get_link_vfunc(int i)const
109 {
110         assert(i>=0 && i<link_count());
111
112         switch(i)
113         {
114                 case 0:
115                         return ref_a;
116                 case 1:
117                         return ref_b;
118         }
119         return 0;
120 }
121
122 int
123 ValueNode_TwoTone::link_count()const
124 {
125         return 2;
126 }
127
128 String
129 ValueNode_TwoTone::link_local_name(int i)const
130 {
131         assert(i>=0 && i<link_count());
132
133         switch(i)
134         {
135                 case 0:
136                         return _("Color1");
137                 case 1:
138                         return _("Color2");
139                 default:
140                         return String();
141         }
142 }
143
144 String
145 ValueNode_TwoTone::link_name(int i)const
146 {
147         assert(i>=0 && i<link_count());
148
149         switch(i)
150         {
151                 case 0:
152                         return "color1";
153                 case 1:
154                         return "color2";
155                 default:
156                         return String();
157         }
158 }
159
160 int
161 ValueNode_TwoTone::get_link_index_from_name(const String &name)const
162 {
163         if(name=="color1")
164                 return 0;
165         if(name=="color2")
166                 return 1;
167         throw Exception::BadLinkName(name);
168 }
169
170 String
171 ValueNode_TwoTone::get_name()const
172 {
173         return "twotone";
174 }
175
176 String
177 ValueNode_TwoTone::get_local_name()const
178 {
179         return _("Two-Tone");
180 }
181
182 bool
183 ValueNode_TwoTone::check_type(ValueBase::Type type)
184 {
185         return type==ValueBase::TYPE_GRADIENT;
186 }