X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=synfig-core%2Ftrunk%2Fsrc%2Fsynfig%2Fvaluenode_subtract.cpp;h=3214d30c190d4207e454617543f6523afd84548b;hb=756c0d29ac1742f231e6615f9a577e574e35a4af;hp=e4c55c3fba2d7aea9ca9a1d69e4e69f8ea8f80e4;hpb=e3acc0b267b14fda5db3c7bbb2f218b993ef84b3;p=synfig.git diff --git a/synfig-core/trunk/src/synfig/valuenode_subtract.cpp b/synfig-core/trunk/src/synfig/valuenode_subtract.cpp index e4c55c3..3214d30 100644 --- a/synfig-core/trunk/src/synfig/valuenode_subtract.cpp +++ b/synfig-core/trunk/src/synfig/valuenode_subtract.cpp @@ -1,20 +1,22 @@ -/* === S I N F G =========================================================== */ +/* === S Y N F I G ========================================================= */ /*! \file valuenode_subtract.cpp -** \brief Template File +** \brief Implementation of the "Subtract" valuenode conversion. ** -** $Id: valuenode_subtract.cpp,v 1.1.1.1 2005/01/04 01:23:15 darco Exp $ +** $Id$ ** ** \legal -** Copyright (c) 2002 Robert B. Quattlebaum Jr. +** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley +** Copyright (c) 2007, 2008 Chris Moore ** -** This software and associated documentation -** are CONFIDENTIAL and PROPRIETARY property of -** the above-mentioned copyright holder. +** This package is free software; you can redistribute it and/or +** modify it under the terms of the GNU General Public License as +** published by the Free Software Foundation; either version 2 of +** the License, or (at your option) any later version. ** -** You may not copy, print, publish, or in any -** other way distribute this software without -** a prior written agreement with -** the copyright holder. +** This package is distributed in the hope that it will be useful, +** but WITHOUT ANY WARRANTY; without even the implied warranty of +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +** General Public License for more details. ** \endlegal */ /* ========================================================================= */ @@ -33,9 +35,11 @@ #include "valuenode_const.h" #include #include "color.h" +#include "gradient.h" #include "vector.h" #include "angle.h" #include "real.h" +#include #endif @@ -43,7 +47,7 @@ using namespace std; using namespace etl; -using namespace sinfg; +using namespace synfig; /* === M A C R O S ========================================================= */ @@ -53,193 +57,125 @@ using namespace sinfg; /* === M E T H O D S ======================================================= */ -sinfg::ValueNode_Subtract::ValueNode_Subtract():LinkableValueNode(sinfg::ValueBase::TYPE_NIL) +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()); -LinkableValueNode* -ValueNode_Subtract::create_new()const -{ - return new ValueNode_Subtract(); -} - -ValueNode_Subtract* -ValueNode_Subtract::create(const ValueBase& x) -{ - ValueBase::Type id(x.get_type()); - - ValueNode_Subtract* value_node=new ValueNode_Subtract(); switch(id) { - case ValueBase::TYPE_NIL: - return value_node; - case ValueBase::TYPE_VECTOR: - case ValueBase::TYPE_REAL: - case ValueBase::TYPE_INTEGER: case ValueBase::TYPE_ANGLE: - value_node->set_link("rhs",ValueNode_Const::create(ValueBase(id))); - value_node->set_link("lhs",ValueNode_Const::create(ValueBase(id))); - assert(value_node->get_rhs()->get_type()==id); - assert(value_node->get_lhs()->get_type()==id); + set_link("lhs",ValueNode_Const::create(value.get(Angle()))); + set_link("rhs",ValueNode_Const::create(Angle::deg(0))); + break; + case ValueBase::TYPE_COLOR: + 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; + case ValueBase::TYPE_REAL: + set_link("lhs",ValueNode_Const::create(value.get(Real()))); + set_link("rhs",ValueNode_Const::create(Real(0))); + break; + case ValueBase::TYPE_TIME: + set_link("lhs",ValueNode_Const::create(value.get(Time()))); + set_link("rhs",ValueNode_Const::create(Time(0))); + break; + case ValueBase::TYPE_VECTOR: + set_link("lhs",ValueNode_Const::create(value.get(Vector()))); + set_link("rhs",ValueNode_Const::create(Vector(0,0))); break; default: assert(0); - throw runtime_error("sinfg::ValueNode_Subtract:Bad type "+ValueBase::type_name(id)); + throw runtime_error(get_local_name()+_(":Bad type ")+ValueBase::type_local_name(id)); } - assert(value_node->get_type()==id); - - return value_node; -} -sinfg::ValueNode_Subtract::~ValueNode_Subtract() -{ - unlink_all(); -} + assert(ref_a->get_type()==id); + assert(ref_b->get_type()==id); + assert(get_type()==id); -void -ValueNode_Subtract::set_scalar(Real x) -{ - set_link("scalar",ValueNode_Const::create(x)); + DCAST_HACK_ENABLE(); } -bool -sinfg::ValueNode_Subtract::set_scalar(ValueNode::Handle x) +LinkableValueNode* +ValueNode_Subtract::create_new()const { - if(x->get_type()!=ValueBase::TYPE_REAL&& !PlaceholderValueNode::Handle::cast_dynamic(x)) - return false; - scalar=x; - return true; + return new ValueNode_Subtract(get_type()); } -bool -sinfg::ValueNode_Subtract::set_lhs(ValueNode::Handle a) +ValueNode_Subtract* +ValueNode_Subtract::create(const ValueBase& value) { - ref_a=a; - - if(PlaceholderValueNode::Handle::cast_dynamic(a)) - return true; - - if(!ref_a || !ref_b) - set_type(ValueBase::TYPE_NIL); - else - if(ref_a->get_type()==ValueBase::TYPE_VECTOR && ref_a->get_type()==ValueBase::TYPE_VECTOR) - set_type(ValueBase::TYPE_VECTOR); - else - if(ref_a->get_type()==ValueBase::TYPE_REAL && ref_a->get_type()==ValueBase::TYPE_REAL) - set_type(ValueBase::TYPE_REAL); - else - if(ref_a->get_type()==ValueBase::TYPE_INTEGER && ref_a->get_type()==ValueBase::TYPE_INTEGER) - set_type(ValueBase::TYPE_INTEGER); - else - if(ref_a->get_type()==ValueBase::TYPE_ANGLE && ref_a->get_type()==ValueBase::TYPE_ANGLE) - set_type(ValueBase::TYPE_ANGLE); - else - if(ref_a->get_type()==ValueBase::TYPE_COLOR && ref_a->get_type()==ValueBase::TYPE_COLOR) - set_type(ValueBase::TYPE_COLOR); - else - { - sinfg::warning(get_id()+":(set_a):"+strprintf(_("Types seem to be off for ValueNodes %s and %s"),ref_a->get_id().c_str(),ref_b->get_id().c_str())); - set_type(ValueBase::TYPE_NIL); - } - - return true; + return new ValueNode_Subtract(value); } -bool -sinfg::ValueNode_Subtract::set_rhs(ValueNode::Handle b) +synfig::ValueNode_Subtract::~ValueNode_Subtract() { - ref_b=b; - - if(PlaceholderValueNode::Handle::cast_dynamic(b)) - return true; - - if(!ref_a || !ref_b) - set_type(ValueBase::TYPE_NIL); - else - if(ref_a->get_type()==ValueBase::TYPE_VECTOR && ref_a->get_type()==ValueBase::TYPE_VECTOR) - set_type(ValueBase::TYPE_VECTOR); - else - if(ref_a->get_type()==ValueBase::TYPE_REAL && ref_a->get_type()==ValueBase::TYPE_REAL) - set_type(ValueBase::TYPE_REAL); - else - if(ref_a->get_type()==ValueBase::TYPE_INTEGER && ref_a->get_type()==ValueBase::TYPE_INTEGER) - set_type(ValueBase::TYPE_INTEGER); - else - if(ref_a->get_type()==ValueBase::TYPE_ANGLE && ref_a->get_type()==ValueBase::TYPE_ANGLE) - set_type(ValueBase::TYPE_ANGLE); - else - if(ref_a->get_type()==ValueBase::TYPE_COLOR && ref_a->get_type()==ValueBase::TYPE_COLOR) - set_type(ValueBase::TYPE_COLOR); - else - { - sinfg::warning(get_id()+":(set_b):"+strprintf(_("Types seem to be off for ValueNodes %s and %s"),ref_a->get_id().c_str(),ref_b->get_id().c_str())); - set_type(ValueBase::TYPE_NIL); - } - - return true; + unlink_all(); } -sinfg::ValueBase -sinfg::ValueNode_Subtract::operator()(Time t)const +synfig::ValueBase +synfig::ValueNode_Subtract::operator()(Time t)const { if(!ref_a || !ref_b) throw runtime_error(strprintf("ValueNode_Subtract: %s",_("One or both of my parameters aren't set!"))); - else - if(get_type()==ValueBase::TYPE_VECTOR) - return ((*ref_a)(t).get(Vector())-(*ref_b)(t).get(Vector()))*(*scalar)(t).get(Real()); - else - if(get_type()==ValueBase::TYPE_REAL) - return ((*ref_a)(t).get(Vector::value_type())-(*ref_b)(t).get(Vector::value_type()))*(*scalar)(t).get(Real()); - else - if(get_type()==ValueBase::TYPE_INTEGER) - return ((*ref_a)(t).get(int())-(*ref_b)(t).get(int()))*(*scalar)(t).get(Real()); - else - if(get_type()==ValueBase::TYPE_ANGLE) + switch(get_type()) + { + case ValueBase::TYPE_ANGLE: return ((*ref_a)(t).get(Angle())-(*ref_b)(t).get(Angle()))*(*scalar)(t).get(Real()); - else - if(get_type()==ValueBase::TYPE_COLOR) + case ValueBase::TYPE_COLOR: return ((*ref_a)(t).get(Color())-(*ref_b)(t).get(Color()))*(*scalar)(t).get(Real()); - - sinfg::error(get_id()+':'+strprintf(_("Cannot subtract types of %s and %s"),ValueBase::type_name(ref_a->get_type()).c_str(),ValueBase::type_name(ref_b->get_type()).c_str())); + 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: + return ((*ref_a)(t).get(Vector::value_type())-(*ref_b)(t).get(Vector::value_type()))*(*scalar)(t).get(Real()); + case ValueBase::TYPE_TIME: + return ((*ref_a)(t).get(Time())-(*ref_b)(t).get(Time()))*(*scalar)(t).get(Real()); + case ValueBase::TYPE_VECTOR: + return ((*ref_a)(t).get(Vector())-(*ref_b)(t).get(Vector()))*(*scalar)(t).get(Real()); + default: + assert(0); + break; + } return ValueBase(); } bool -ValueNode_Subtract::set_link_vfunc(int i,ValueNode::Handle x) +ValueNode_Subtract::set_link_vfunc(int i,ValueNode::Handle value) { - assert(i>=0 && i<3); + assert(i>=0 && i=0 && i<3); + assert(i>=0 && i=0 && i<3); + assert(i>=0 && i=0 && i<3); + assert(i>=0 && i