#include "valuenode_const.h"
#include <stdexcept>
#include "color.h"
+#include "gradient.h"
#include "vector.h"
#include "angle.h"
#include "real.h"
synfig::ValueNode_Subtract::ValueNode_Subtract(const ValueBase &value):
LinkableValueNode(value.get_type())
{
- set_scalar(1.0);
+ set_link("scalar",ValueNode_Const::create(Real(1.0)));
ValueBase::Type id(value.get_type());
switch(id)
set_link("lhs",ValueNode_Const::create(value.get(Color())));
set_link("rhs",ValueNode_Const::create(Color(0,0,0,0)));
break;
+ case ValueBase::TYPE_GRADIENT:
+ set_link("lhs",ValueNode_Const::create(value.get(Gradient())));
+ set_link("rhs",ValueNode_Const::create(Gradient()));
+ break;
case ValueBase::TYPE_INTEGER:
set_link("lhs",ValueNode_Const::create(value.get(int())));
set_link("rhs",ValueNode_Const::create(int(0)));
break;
default:
assert(0);
- throw runtime_error(_("synfig::ValueNode_Subtract:Bad type ")+ValueBase::type_local_name(id));
+ throw runtime_error(get_local_name()+_(":Bad type ")+ValueBase::type_local_name(id));
}
- assert(get_lhs()->get_type()==id);
- assert(get_rhs()->get_type()==id);
+ assert(ref_a->get_type()==id);
+ assert(ref_b->get_type()==id);
assert(get_type()==id);
DCAST_HACK_ENABLE();
unlink_all();
}
-void
-ValueNode_Subtract::set_scalar(Real value)
-{
- set_link("scalar",ValueNode_Const::create(value));
-}
-
-bool
-synfig::ValueNode_Subtract::set_scalar(ValueNode::Handle value)
-{
- if(value->get_type()!=ValueBase::TYPE_REAL&& !PlaceholderValueNode::Handle::cast_dynamic(value))
- return false;
- scalar=value;
- return true;
-}
-
-bool
-synfig::ValueNode_Subtract::set_lhs(ValueNode::Handle x)
-{
- assert(get_type());
-
- if(!x ||
- (get_type()==ValueBase::TYPE_NIL && !check_type(x->get_type())) ||
- (get_type()!=ValueBase::TYPE_NIL && x->get_type()!=get_type() && !PlaceholderValueNode::Handle::cast_dynamic(x)))
- return false;
-
- ref_a=x;
-
- return true;
-}
-
-bool
-synfig::ValueNode_Subtract::set_rhs(ValueNode::Handle x)
-{
- assert(get_type());
-
- if(!x ||
- (get_type()==ValueBase::TYPE_NIL && !check_type(x->get_type())) ||
- (get_type()!=ValueBase::TYPE_NIL && x->get_type()!=get_type() && !PlaceholderValueNode::Handle::cast_dynamic(x)))
- return false;
-
- ref_b=x;
-
- return true;
-}
-
synfig::ValueBase
synfig::ValueNode_Subtract::operator()(Time t)const
{
return ((*ref_a)(t).get(Angle())-(*ref_b)(t).get(Angle()))*(*scalar)(t).get(Real());
case ValueBase::TYPE_COLOR:
return ((*ref_a)(t).get(Color())-(*ref_b)(t).get(Color()))*(*scalar)(t).get(Real());
+ case ValueBase::TYPE_GRADIENT:
+ return ((*ref_a)(t).get(Gradient())-(*ref_b)(t).get(Gradient()))*(*scalar)(t).get(Real());
case ValueBase::TYPE_INTEGER:
return round_to_int(((*ref_a)(t).get(int())-(*ref_b)(t).get(int()))*(*scalar)(t).get(Real()));
case ValueBase::TYPE_REAL:
switch(i)
{
- case 0:
- if(set_lhs(value)) { signal_child_changed()(i);signal_value_changed()(); return true; }
- return false;
- case 1:
- if(set_rhs(value)) { signal_child_changed()(i);signal_value_changed()(); return true; }
- return false;
- case 2:
- scalar=value;
- signal_child_changed()(i);signal_value_changed()();
- return true;
+ case 0: CHECK_TYPE_AND_SET_VALUE(ref_a, get_type());
+ case 1: CHECK_TYPE_AND_SET_VALUE(ref_b, get_type());
+ case 2: CHECK_TYPE_AND_SET_VALUE(scalar, ValueBase::TYPE_REAL);
}
-
return false;
}
{
return type==ValueBase::TYPE_ANGLE
|| type==ValueBase::TYPE_COLOR
+ || type==ValueBase::TYPE_GRADIENT
|| type==ValueBase::TYPE_INTEGER
|| type==ValueBase::TYPE_REAL
|| type==ValueBase::TYPE_TIME