X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=synfig-core%2Ftrunk%2Fsrc%2Fsynfig%2Fvaluenode_scale.cpp;h=a6f05530a6078f944a976f477f17a057340ddf6f;hb=96aa44af8c1800bcfc1308b55d40a2da419221d9;hp=8cb711b53506cdaf6f9ae152c53c55798242e772;hpb=5ddcf36f04cfbd10fabda4e3c5633cb27cdd4c0a;p=synfig.git diff --git a/synfig-core/trunk/src/synfig/valuenode_scale.cpp b/synfig-core/trunk/src/synfig/valuenode_scale.cpp index 8cb711b..a6f0553 100644 --- a/synfig-core/trunk/src/synfig/valuenode_scale.cpp +++ b/synfig-core/trunk/src/synfig/valuenode_scale.cpp @@ -1,11 +1,12 @@ /* === S Y N F I G ========================================================= */ /*! \file valuenode_scale.cpp -** \brief Template File +** \brief Implementation of the "Scale" valuenode conversion. ** -** $Id: valuenode_scale.cpp,v 1.1.1.1 2005/01/04 01:23:15 darco Exp $ +** $Id$ ** ** \legal ** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley +** Copyright (c) 2007, 2008 Chris Moore ** ** This package is free software; you can redistribute it and/or ** modify it under the terms of the GNU General Public License as @@ -33,11 +34,11 @@ #include "valuenode_scale.h" #include "valuenode_const.h" #include -#include #include "color.h" #include "vector.h" #include "time.h" #include "angle.h" +#include #endif @@ -55,132 +56,83 @@ using namespace synfig; /* === M E T H O D S ======================================================= */ -ValueNode_Scale::ValueNode_Scale():LinkableValueNode(synfig::ValueBase::TYPE_NIL) +ValueNode_Scale::ValueNode_Scale(const ValueBase &value): + LinkableValueNode(value.get_type()) { - set_scalar(1.0); -} + set_link("scalar",ValueNode::Handle(ValueNode_Const::create(Real(1.0)))); + ValueBase::Type id(value.get_type()); -ValueNode_Scale* -ValueNode_Scale::create(const ValueBase& x) -{ - ValueNode_Scale* value_node; - switch(x.get_type()) + switch(id) { - case ValueBase::TYPE_VECTOR: - case ValueBase::TYPE_REAL: - case ValueBase::TYPE_TIME: - case ValueBase::TYPE_INTEGER: case ValueBase::TYPE_ANGLE: + set_link("link",ValueNode_Const::create(value.get(Angle()))); + break; case ValueBase::TYPE_COLOR: - value_node=new ValueNode_Scale(); - if(!value_node->set_value_node(ValueNode_Const::create(x))) - return 0; - assert(value_node->get_value_node()->get_type()==x.get_type()); + set_link("link",ValueNode_Const::create(value.get(Color()))); + break; + case ValueBase::TYPE_INTEGER: + set_link("link",ValueNode_Const::create(value.get(int()))); + break; + case ValueBase::TYPE_REAL: + set_link("link",ValueNode_Const::create(value.get(Real()))); + break; + case ValueBase::TYPE_TIME: + set_link("link",ValueNode_Const::create(value.get(Time()))); + break; + case ValueBase::TYPE_VECTOR: + set_link("link",ValueNode_Const::create(value.get(Vector()))); break; default: assert(0); - throw runtime_error("synfig::ValueNode_Scale:Bad type "+ValueBase::type_name(x.get_type())); + throw runtime_error(get_local_name()+_(":Bad type ")+ValueBase::type_local_name(id)); } - assert(value_node); - assert(value_node->get_type()==x.get_type()); - return value_node; + assert(value_node); + assert(value_node->get_type()==id); + assert(get_type()==id); } LinkableValueNode* ValueNode_Scale::create_new()const { - return new ValueNode_Scale(); -} - -synfig::ValueNode_Scale::~ValueNode_Scale() -{ - unlink_all(); -} - -void -ValueNode_Scale::set_scalar(Real x) -{ - set_link("scalar",ValueNode::Handle(ValueNode_Const::create(x))); -} - -bool -ValueNode_Scale::set_scalar(const ValueNode::Handle &x) -{ - if(!x - || x->get_type()!=ValueBase::TYPE_REAL - && !PlaceholderValueNode::Handle::cast_dynamic(x) - ) - return false; - scalar=x; - return true; + return new ValueNode_Scale(get_type()); } -ValueNode::Handle -ValueNode_Scale::get_scalar()const +ValueNode_Scale* +ValueNode_Scale::create(const ValueBase& value) { - return scalar; + return new ValueNode_Scale(value); } -bool -ValueNode_Scale::set_value_node(const ValueNode::Handle &x) -{ - 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; - - assert(!(PlaceholderValueNode::Handle::cast_dynamic(x) && !get_type())); - - value_node=x; - - if(!get_type()) - set_type(x->get_type()); - - return true; -} - -ValueNode::Handle -ValueNode_Scale::get_value_node()const +synfig::ValueNode_Scale::~ValueNode_Scale() { - return value_node; + unlink_all(); } - synfig::ValueBase synfig::ValueNode_Scale::operator()(Time t)const { if(!value_node || !scalar) throw runtime_error(strprintf("ValueNode_Scale: %s",_("One or both of my parameters aren't set!"))); - else - if(get_type()==ValueBase::TYPE_VECTOR) - return (*value_node)(t).get(Vector())*(*scalar)(t).get(Real()); - else - if(get_type()==ValueBase::TYPE_REAL) - return (*value_node)(t).get(Real())*(*scalar)(t).get(Real()); - else - if(get_type()==ValueBase::TYPE_TIME) - return (*value_node)(t).get(Time())*(*scalar)(t).get(Time()); - else - if(get_type()==ValueBase::TYPE_INTEGER) - return (*value_node)(t).get(int())*(*scalar)(t).get(Real()); - else - if(get_type()==ValueBase::TYPE_ANGLE) + else if(get_type()==ValueBase::TYPE_ANGLE) return (*value_node)(t).get(Angle())*(*scalar)(t).get(Real()); - else - if(get_type()==ValueBase::TYPE_COLOR) + else if(get_type()==ValueBase::TYPE_COLOR) { Color ret((*value_node)(t).get(Color())); Real s((*scalar)(t).get(Real())); ret.set_r(ret.get_r()*s); - ret.set_g(ret.get_r()*s); - ret.set_b(ret.get_r()*s); + ret.set_g(ret.get_g()*s); + ret.set_b(ret.get_b()*s); return ret; } + else if(get_type()==ValueBase::TYPE_INTEGER) + return round_to_int((*value_node)(t).get(int())*(*scalar)(t).get(Real())); + else if(get_type()==ValueBase::TYPE_REAL) + return (*value_node)(t).get(Real())*(*scalar)(t).get(Real()); + else if(get_type()==ValueBase::TYPE_TIME) + return (*value_node)(t).get(Time())*(*scalar)(t).get(Time()); + else if(get_type()==ValueBase::TYPE_VECTOR) + return (*value_node)(t).get(Vector())*(*scalar)(t).get(Real()); assert(0); return ValueBase(); @@ -188,26 +140,23 @@ synfig::ValueNode_Scale::operator()(Time t)const bool -ValueNode_Scale::set_link_vfunc(int i,ValueNode::Handle x) +ValueNode_Scale::set_link_vfunc(int i,ValueNode::Handle value) { - if(!(i==0 || i==1)) - return false; - - if(i==0 && !set_value_node(x)) - return false; - else - if(i==1 && !set_scalar(x)) - return false; + assert(i>=0 && i=0 && i=0 && i=0 && i