moreupdates
[synfig.git] / synfig-core / trunk / src / synfig / valuenode_twotone.cpp
1 /* === S Y N F I G ========================================================= */
2 /*!     \file valuenode_subtract.cpp
3 **      \brief Template File
4 **
5 **      $Id: valuenode_twotone.cpp,v 1.1.1.1 2005/01/04 01:23:15 darco Exp $
6 **
7 **      \legal
8 **      Copyright (c) 2002 Robert B. Quattlebaum Jr.
9 **
10 **      This software and associated documentation
11 **      are CONFIDENTIAL and PROPRIETARY property of
12 **      the above-mentioned copyright holder.
13 **
14 **      You may not copy, print, publish, or in any
15 **      other way distribute this software without
16 **      a prior written agreement with
17 **      the copyright holder.
18 **      \endlegal
19 */
20 /* ========================================================================= */
21
22 /* === H E A D E R S ======================================================= */
23
24 #ifdef USING_PCH
25 #       include "pch.h"
26 #else
27 #ifdef HAVE_CONFIG_H
28 #       include <config.h>
29 #endif
30
31 #include "general.h"
32 #include "valuenode_twotone.h"
33 #include "valuenode_const.h"
34 #include <stdexcept>
35 #include "color.h"
36 #include "gradient.h"
37
38 #endif
39
40 /* === U S I N G =========================================================== */
41
42 using namespace std;
43 using namespace etl;
44 using namespace synfig;
45
46 /* === M A C R O S ========================================================= */
47
48 /* === G L O B A L S ======================================================= */
49
50 /* === P R O C E D U R E S ================================================= */
51
52 /* === M E T H O D S ======================================================= */
53
54 synfig::ValueNode_TwoTone::ValueNode_TwoTone():LinkableValueNode(synfig::ValueBase::TYPE_GRADIENT)
55 {
56         set_link("color1",ValueNode_Const::create(Color::black()));
57         set_link("color2",ValueNode_Const::create(Color::white()));
58         DCAST_HACK_ENABLE();
59 }
60
61 LinkableValueNode*
62 ValueNode_TwoTone::create_new()const
63 {
64         return new ValueNode_TwoTone();
65 }
66
67 ValueNode_TwoTone*
68 ValueNode_TwoTone::create(const ValueBase& x)
69 {
70         ValueBase::Type id(x.get_type());
71         if(id!=ValueBase::TYPE_GRADIENT)
72         {
73                 assert(0);
74                 throw runtime_error("synfig::ValueNode_TwoTone:Bad type "+ValueBase::type_name(id));                    
75         }               
76
77         ValueNode_TwoTone* value_node=new ValueNode_TwoTone();
78
79         assert(value_node->get_type()==id);
80         
81         return value_node;
82 }
83
84 synfig::ValueNode_TwoTone::~ValueNode_TwoTone()
85 {
86         unlink_all();
87 }
88
89 bool
90 synfig::ValueNode_TwoTone::set_lhs(ValueNode::Handle a)
91 {
92         if(a->get_type()!=ValueBase::TYPE_COLOR)
93                 return false;
94
95         ref_a=a;
96
97         return true;
98 }
99
100 bool
101 synfig::ValueNode_TwoTone::set_rhs(ValueNode::Handle b)
102 {
103         if(b->get_type()!=ValueBase::TYPE_COLOR)
104                 return false;
105         ref_b=b;
106         return true;
107 }
108
109 synfig::ValueBase
110 synfig::ValueNode_TwoTone::operator()(Time t)const
111 {
112         return Gradient((*ref_a)(t).get(Color()),(*ref_b)(t).get(Color()));
113 }
114
115 bool
116 ValueNode_TwoTone::set_link_vfunc(int i,ValueNode::Handle x)
117 {
118         assert(i>=0 && i<3);
119         switch(i)
120         {
121                 case 0:
122                         if(set_lhs(x)) { signal_child_changed()(i);signal_value_changed()(); return true; }
123                         else { return false; }
124                 case 1:
125                         if(set_rhs(x)) { signal_child_changed()(i);signal_value_changed()(); return true; }
126                         else { return false; }
127         }
128
129         return false;
130 }
131
132 ValueNode::LooseHandle
133 ValueNode_TwoTone::get_link_vfunc(int i)const
134 {
135         assert(i>=0 && i<3);
136         switch(i)
137         {
138                 case 0:
139                         return ref_a;
140                 case 1:
141                         return ref_b;
142         }
143         return 0;
144 }
145
146 int
147 ValueNode_TwoTone::link_count()const
148 {
149         return 2;
150 }
151
152 String
153 ValueNode_TwoTone::link_local_name(int i)const
154 {
155         assert(i>=0 && i<2);
156         switch(i)
157         {
158                 case 0:
159                         return _("Color1");
160                 case 1:
161                         return _("Color2");
162         }
163         return String();
164 }       
165
166 String
167 ValueNode_TwoTone::link_name(int i)const
168 {
169         assert(i>=0 && i<2);
170         switch(i)
171         {
172                 case 0:
173                         return "color1";
174                 case 1:
175                         return "color2";
176         }
177         return String();
178 }       
179
180 int
181 ValueNode_TwoTone::get_link_index_from_name(const String &name)const
182 {
183         if(name=="color1")
184                 return 0;
185         if(name=="color2")
186                 return 1;
187         throw Exception::BadLinkName(name);
188 }
189
190 String
191 ValueNode_TwoTone::get_name()const
192 {
193         return "twotone";
194 }
195
196 String
197 ValueNode_TwoTone::get_local_name()const
198 {
199         return _("Two-Tone");
200 }
201
202 bool
203 ValueNode_TwoTone::check_type(ValueBase::Type type)
204 {
205         return type==ValueBase::TYPE_GRADIENT;
206 }