Added copyright lines for files I've edited this year.
[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 **      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():LinkableValueNode(synfig::ValueBase::TYPE_GRADIENT)
57 {
58         set_link("color1",ValueNode_Const::create(Color::black()));
59         set_link("color2",ValueNode_Const::create(Color::white()));
60         DCAST_HACK_ENABLE();
61 }
62
63 LinkableValueNode*
64 ValueNode_TwoTone::create_new()const
65 {
66         return new ValueNode_TwoTone();
67 }
68
69 ValueNode_TwoTone*
70 ValueNode_TwoTone::create(const ValueBase& x)
71 {
72         ValueBase::Type id(x.get_type());
73         if(id!=ValueBase::TYPE_GRADIENT)
74         {
75                 assert(0);
76                 throw runtime_error(String(_("Two-Tone"))+_(":Bad type ")+ValueBase::type_local_name(id));
77         }
78
79         ValueNode_TwoTone* value_node=new ValueNode_TwoTone();
80
81         assert(value_node->get_type()==id);
82
83         return value_node;
84 }
85
86 synfig::ValueNode_TwoTone::~ValueNode_TwoTone()
87 {
88         unlink_all();
89 }
90
91 synfig::ValueBase
92 synfig::ValueNode_TwoTone::operator()(Time t)const
93 {
94         return Gradient((*ref_a)(t).get(Color()),(*ref_b)(t).get(Color()));
95 }
96
97 bool
98 ValueNode_TwoTone::set_link_vfunc(int i,ValueNode::Handle value)
99 {
100         assert(i>=0 && i<link_count());
101
102         switch(i)
103         {
104         case 0: CHECK_TYPE_AND_SET_VALUE(ref_a, ValueBase::TYPE_COLOR);
105         case 1: CHECK_TYPE_AND_SET_VALUE(ref_b, ValueBase::TYPE_COLOR);
106         }
107         return false;
108 }
109
110 ValueNode::LooseHandle
111 ValueNode_TwoTone::get_link_vfunc(int i)const
112 {
113         assert(i>=0 && i<link_count());
114
115         switch(i)
116         {
117                 case 0:
118                         return ref_a;
119                 case 1:
120                         return ref_b;
121         }
122         return 0;
123 }
124
125 int
126 ValueNode_TwoTone::link_count()const
127 {
128         return 2;
129 }
130
131 String
132 ValueNode_TwoTone::link_local_name(int i)const
133 {
134         assert(i>=0 && i<link_count());
135
136         switch(i)
137         {
138                 case 0:
139                         return _("Color1");
140                 case 1:
141                         return _("Color2");
142                 default:
143                         return String();
144         }
145 }
146
147 String
148 ValueNode_TwoTone::link_name(int i)const
149 {
150         assert(i>=0 && i<link_count());
151
152         switch(i)
153         {
154                 case 0:
155                         return "color1";
156                 case 1:
157                         return "color2";
158                 default:
159                         return String();
160         }
161 }
162
163 int
164 ValueNode_TwoTone::get_link_index_from_name(const String &name)const
165 {
166         if(name=="color1")
167                 return 0;
168         if(name=="color2")
169                 return 1;
170         throw Exception::BadLinkName(name);
171 }
172
173 String
174 ValueNode_TwoTone::get_name()const
175 {
176         return "twotone";
177 }
178
179 String
180 ValueNode_TwoTone::get_local_name()const
181 {
182         return _("Two-Tone");
183 }
184
185 bool
186 ValueNode_TwoTone::check_type(ValueBase::Type type)
187 {
188         return type==ValueBase::TYPE_GRADIENT;
189 }