1 /* === S Y N F I G ========================================================= */
2 /*! \file valuenode_subtract.cpp
3 ** \brief Implementation of the "Subtract" 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 ======================================================= */
34 #include "valuenode_subtract.h"
35 #include "valuenode_const.h"
46 /* === U S I N G =========================================================== */
50 using namespace synfig;
52 /* === M A C R O S ========================================================= */
54 /* === G L O B A L S ======================================================= */
56 /* === P R O C E D U R E S ================================================= */
58 /* === M E T H O D S ======================================================= */
60 synfig::ValueNode_Subtract::ValueNode_Subtract(const ValueBase &value):
61 LinkableValueNode(value.get_type())
63 Vocab ret(get_children_vocab());
64 set_children_vocab(ret);
65 set_link("scalar",ValueNode_Const::create(Real(1.0)));
66 ValueBase::Type id(value.get_type());
70 case ValueBase::TYPE_ANGLE:
71 set_link("lhs",ValueNode_Const::create(value.get(Angle())));
72 set_link("rhs",ValueNode_Const::create(Angle::deg(0)));
74 case ValueBase::TYPE_COLOR:
75 set_link("lhs",ValueNode_Const::create(value.get(Color())));
76 set_link("rhs",ValueNode_Const::create(Color(0,0,0,0)));
78 case ValueBase::TYPE_GRADIENT:
79 set_link("lhs",ValueNode_Const::create(value.get(Gradient())));
80 set_link("rhs",ValueNode_Const::create(Gradient()));
82 case ValueBase::TYPE_INTEGER:
83 set_link("lhs",ValueNode_Const::create(value.get(int())));
84 set_link("rhs",ValueNode_Const::create(int(0)));
86 case ValueBase::TYPE_REAL:
87 set_link("lhs",ValueNode_Const::create(value.get(Real())));
88 set_link("rhs",ValueNode_Const::create(Real(0)));
90 case ValueBase::TYPE_TIME:
91 set_link("lhs",ValueNode_Const::create(value.get(Time())));
92 set_link("rhs",ValueNode_Const::create(Time(0)));
94 case ValueBase::TYPE_VECTOR:
95 set_link("lhs",ValueNode_Const::create(value.get(Vector())));
96 set_link("rhs",ValueNode_Const::create(Vector(0,0)));
100 throw runtime_error(get_local_name()+_(":Bad type ")+ValueBase::type_local_name(id));
103 assert(ref_a->get_type()==id);
104 assert(ref_b->get_type()==id);
105 assert(get_type()==id);
109 ValueNode_Subtract::create_new()const
111 return new ValueNode_Subtract(get_type());
115 ValueNode_Subtract::create(const ValueBase& value)
117 return new ValueNode_Subtract(value);
120 synfig::ValueNode_Subtract::~ValueNode_Subtract()
126 synfig::ValueNode_Subtract::operator()(Time t)const
128 if (getenv("SYNFIG_DEBUG_VALUENODE_OPERATORS"))
129 printf("%s:%d operator()\n", __FILE__, __LINE__);
132 throw runtime_error(strprintf("ValueNode_Subtract: %s",_("One or both of my parameters aren't set!")));
135 case ValueBase::TYPE_ANGLE:
136 return ((*ref_a)(t).get(Angle())-(*ref_b)(t).get(Angle()))*(*scalar)(t).get(Real());
137 case ValueBase::TYPE_COLOR:
138 return ((*ref_a)(t).get(Color())-(*ref_b)(t).get(Color()))*(*scalar)(t).get(Real());
139 case ValueBase::TYPE_GRADIENT:
140 return ((*ref_a)(t).get(Gradient())-(*ref_b)(t).get(Gradient()))*(*scalar)(t).get(Real());
141 case ValueBase::TYPE_INTEGER:
142 return round_to_int(((*ref_a)(t).get(int())-(*ref_b)(t).get(int()))*(*scalar)(t).get(Real()));
143 case ValueBase::TYPE_REAL:
144 return ((*ref_a)(t).get(Vector::value_type())-(*ref_b)(t).get(Vector::value_type()))*(*scalar)(t).get(Real());
145 case ValueBase::TYPE_TIME:
146 return ((*ref_a)(t).get(Time())-(*ref_b)(t).get(Time()))*(*scalar)(t).get(Real());
147 case ValueBase::TYPE_VECTOR:
148 return ((*ref_a)(t).get(Vector())-(*ref_b)(t).get(Vector()))*(*scalar)(t).get(Real());
157 ValueNode_Subtract::set_link_vfunc(int i,ValueNode::Handle value)
159 assert(i>=0 && i<link_count());
163 case 0: CHECK_TYPE_AND_SET_VALUE(ref_a, get_type());
164 case 1: CHECK_TYPE_AND_SET_VALUE(ref_b, get_type());
165 case 2: CHECK_TYPE_AND_SET_VALUE(scalar, ValueBase::TYPE_REAL);
170 ValueNode::LooseHandle
171 ValueNode_Subtract::get_link_vfunc(int i)const
173 assert(i>=0 && i<link_count());
177 case 0: return ref_a;
178 case 1: return ref_b;
179 case 2: return scalar;
185 ValueNode_Subtract::get_name()const
191 ValueNode_Subtract::get_local_name()const
193 return _("Subtract");
197 ValueNode_Subtract::check_type(ValueBase::Type type)
199 return type==ValueBase::TYPE_ANGLE
200 || type==ValueBase::TYPE_COLOR
201 || type==ValueBase::TYPE_GRADIENT
202 || type==ValueBase::TYPE_INTEGER
203 || type==ValueBase::TYPE_REAL
204 || type==ValueBase::TYPE_TIME
205 || type==ValueBase::TYPE_VECTOR;
208 LinkableValueNode::Vocab
209 ValueNode_Subtract::get_children_vocab_vfunc()const
211 if(children_vocab.size())
212 return children_vocab;
214 LinkableValueNode::Vocab ret;
216 ret.push_back(ParamDesc(ValueBase(),"lhs")
217 .set_local_name(_("LHS"))
218 .set_description(_("Left Hand Side of the subtraction"))
221 ret.push_back(ParamDesc(ValueBase(),"rhs")
222 .set_local_name(_("RHS"))
223 .set_description(_("Right Hand Side of the subtraction"))
226 ret.push_back(ParamDesc(ValueBase(),"scalar")
227 .set_local_name(_("Scalar"))
228 .set_description(_("Value that multiplies the subtraction"))