1 /* === S Y N F I G ========================================================= */
2 /*! \file valuenode_gradientcolor.cpp
3 ** \brief Implementation of the "Gradient Color" valuenode conversion.
8 ** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
9 ** Copyright (c) 2007, 2008 Chris Moore
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.
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.
22 /* ========================================================================= */
24 /* === H E A D E R S ======================================================= */
33 #include "valuenode_gradientcolor.h"
34 #include "valuenode_const.h"
40 /* === U S I N G =========================================================== */
44 using namespace synfig;
46 /* === M A C R O S ========================================================= */
48 /* === G L O B A L S ======================================================= */
50 /* === P R O C E D U R E S ================================================= */
52 /* === M E T H O D S ======================================================= */
54 ValueNode_GradientColor::ValueNode_GradientColor(const ValueBase &value):
55 LinkableValueNode(value.get_type())
57 switch(value.get_type())
59 case ValueBase::TYPE_COLOR:
60 set_link("gradient", ValueNode_Const::create(Gradient(value.get(Color()),value.get(Color()))));
61 set_link("index", ValueNode_Const::create(Real(0.5)));
62 set_link("loop", ValueNode_Const::create(bool(false)));
65 throw Exception::BadType(ValueBase::type_local_name(value.get_type()));
72 ValueNode_GradientColor::create_new()const
74 return new ValueNode_GradientColor(get_type());
77 ValueNode_GradientColor*
78 ValueNode_GradientColor::create(const ValueBase &x)
80 return new ValueNode_GradientColor(x);
83 ValueNode_GradientColor::~ValueNode_GradientColor()
89 ValueNode_GradientColor::operator()(Time t)const
91 if (getenv("SYNFIG_DEBUG_VALUENODE_OPERATORS"))
92 printf("%s:%d operator()\n", __FILE__, __LINE__);
94 Real index((*index_)(t).get(Real()));
95 bool loop((*loop_)(t).get(bool()));
96 if (loop) index -= floor(index);
97 return (*gradient_)(t).get(Gradient())(index);
102 ValueNode_GradientColor::set_link_vfunc(int i,ValueNode::Handle value)
104 assert(i>=0 && i<link_count());
108 case 0: CHECK_TYPE_AND_SET_VALUE(gradient_, ValueBase::TYPE_GRADIENT);
109 case 1: CHECK_TYPE_AND_SET_VALUE(index_, ValueBase::TYPE_REAL);
110 case 2: CHECK_TYPE_AND_SET_VALUE(loop_, ValueBase::TYPE_BOOL);
115 ValueNode::LooseHandle
116 ValueNode_GradientColor::get_link_vfunc(int i)const
118 assert(i>=0 && i<link_count());
122 case 0: return gradient_;
123 case 1: return index_;
124 case 2: return loop_;
131 ValueNode_GradientColor::link_count()const
137 ValueNode_GradientColor::link_local_name(int i)const
139 assert(i>=0 && i<link_count());
143 case 0: return _("Gradient");
144 case 1: return _("Index");
145 case 2: return _("Loop");
151 ValueNode_GradientColor::link_name(int i)const
153 assert(i>=0 && i<link_count());
157 case 0: return "gradient";
158 case 1: return "index";
159 case 2: return "loop";
165 ValueNode_GradientColor::get_link_index_from_name(const String &name)const
167 if (name=="gradient") return 0;
168 if (name=="index") return 1;
169 if (name=="loop") return 2;
170 throw Exception::BadLinkName(name);
174 ValueNode_GradientColor::get_name()const
176 return "gradientcolor";
180 ValueNode_GradientColor::get_local_name()const
182 return _("Gradient Color");
186 ValueNode_GradientColor::check_type(ValueBase::Type type)
188 return type==ValueBase::TYPE_COLOR;