X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=synfig-core%2Ftrunk%2Fsrc%2Fsynfig%2Fvaluenode_timedswap.cpp;h=bb564c63403a198b788a7f11f21cf4b3ed54bc37;hb=a8222ac07c79b43f492d5ca5177179d94737e7ef;hp=728c94d4dd72cca64002ec2234419cf6e2a33af9;hpb=e8a065f2385c219c511b57dac52786120bfa097d;p=synfig.git diff --git a/synfig-core/trunk/src/synfig/valuenode_timedswap.cpp b/synfig-core/trunk/src/synfig/valuenode_timedswap.cpp index 728c94d..bb564c6 100644 --- a/synfig-core/trunk/src/synfig/valuenode_timedswap.cpp +++ b/synfig-core/trunk/src/synfig/valuenode_timedswap.cpp @@ -1,11 +1,12 @@ /* === S Y N F I G ========================================================= */ /*! \file valuenode_timedswap.cpp -** \brief Template File +** \brief Implementation of the "Timed Swap" valuenode conversion. ** -** $Id: valuenode_timedswap.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 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 @@ -34,6 +35,7 @@ #include "valuenode_const.h" #include #include "color.h" +#include #endif @@ -51,13 +53,41 @@ using namespace synfig; /* === M E T H O D S ======================================================= */ -ValueNode_TimedSwap::ValueNode_TimedSwap(ValueBase::Type type): - LinkableValueNode(type) +ValueNode_TimedSwap::ValueNode_TimedSwap(const ValueBase &value): + LinkableValueNode(value.get_type()) { - set_before(ValueNode_Const::create(type)); - set_after(ValueNode_Const::create(type)); - set_swap_time_real(1.0); - set_swap_length_real(1.0); + switch(get_type()) + { + case ValueBase::TYPE_ANGLE: + set_link("before",ValueNode_Const::create(value.get(Angle()))); + set_link("after",ValueNode_Const::create(value.get(Angle()))); + break; + case ValueBase::TYPE_COLOR: + set_link("before",ValueNode_Const::create(value.get(Color()))); + set_link("after",ValueNode_Const::create(value.get(Color()))); + break; + case ValueBase::TYPE_INTEGER: + set_link("before",ValueNode_Const::create(value.get(int()))); + set_link("after",ValueNode_Const::create(value.get(int()))); + break; + case ValueBase::TYPE_REAL: + set_link("before",ValueNode_Const::create(value.get(Real()))); + set_link("after",ValueNode_Const::create(value.get(Real()))); + break; + case ValueBase::TYPE_TIME: + set_link("before",ValueNode_Const::create(value.get(Time()))); + set_link("after",ValueNode_Const::create(value.get(Time()))); + break; + case ValueBase::TYPE_VECTOR: + set_link("before",ValueNode_Const::create(value.get(Vector()))); + set_link("after",ValueNode_Const::create(value.get(Vector()))); + break; + default: + throw Exception::BadType(ValueBase::type_name(get_type())); + } + + set_link("time",ValueNode_Const::create(Time(2))); + set_link("length",ValueNode_Const::create(Time(1))); DCAST_HACK_ENABLE(); } @@ -65,7 +95,7 @@ ValueNode_TimedSwap::ValueNode_TimedSwap(ValueBase::Type type): ValueNode_TimedSwap* ValueNode_TimedSwap::create(const ValueBase& x) { - return new ValueNode_TimedSwap(x.get_type()); + return new ValueNode_TimedSwap(x); } @@ -121,20 +151,13 @@ ValueNode_TimedSwap::get_after()const } -void -ValueNode_TimedSwap::set_swap_time_real(Time x) -{ - set_swap_time(ValueNode_Const::create(x)); -} - bool ValueNode_TimedSwap::set_swap_time(const ValueNode::Handle &x) { - if(!x - || !ValueBase(ValueBase::TYPE_TIME).same_as(x->get_type()) - && !PlaceholderValueNode::Handle::cast_dynamic(x) - ) + if(!x || (!ValueBase(x->get_type()).same_type_as(ValueBase::TYPE_TIME) && + !PlaceholderValueNode::Handle::cast_dynamic(x))) return false; + swap_time=x; return true; } @@ -145,21 +168,13 @@ ValueNode_TimedSwap::get_swap_time()const return swap_time; } -void -ValueNode_TimedSwap::set_swap_length_real(Time x) -{ - set_swap_length(ValueNode_Const::create(x)); -} - bool ValueNode_TimedSwap::set_swap_length(const ValueNode::Handle &x) { - if(!x || ( - !ValueBase(ValueBase::TYPE_TIME).same_as(x->get_type()) - && !PlaceholderValueNode::Handle::cast_dynamic(x) - ) - ) + if(!x || (!ValueBase(x->get_type()).same_type_as(ValueBase::TYPE_TIME) && + !PlaceholderValueNode::Handle::cast_dynamic(x))) return false; + swap_length=x; return true; } @@ -180,27 +195,15 @@ synfig::ValueNode_TimedSwap::operator()(Time t)const if(t>swptime) return (*after)(t); - + if(t<=swptime && t>swptime-swplength) { Real amount=(swptime-t)/swplength; // if amount==0.0, then we are after // if amount==1.0, then we are before - + switch(get_type()) { - case ValueBase::TYPE_REAL: - { - Real a=(*after)(t).get(Real()); - Real b=(*before)(t).get(Real()); - return (b-a)*amount+a; - } - case ValueBase::TYPE_VECTOR: - { - Vector a=(*after)(t).get(Vector()); - Vector b=(*before)(t).get(Vector()); - return (b-a)*amount+a; - } case ValueBase::TYPE_ANGLE: { Angle a=(*after)(t).get(Angle()); @@ -218,7 +221,25 @@ synfig::ValueNode_TimedSwap::operator()(Time t)const { float a=(float)(*after)(t).get(int()); float b=(float)(*before)(t).get(int()); - return static_cast((b-a)*amount+a+0.5f); + return round_to_int((b-a)*amount+a); + } + case ValueBase::TYPE_REAL: + { + Real a=(*after)(t).get(Real()); + Real b=(*before)(t).get(Real()); + return (b-a)*amount+a; + } + case ValueBase::TYPE_TIME: + { + Time a=(*after)(t).get(Time()); + Time b=(*before)(t).get(Time()); + return (b-a)*amount+a; + } + case ValueBase::TYPE_VECTOR: + { + Vector a=(*after)(t).get(Vector()); + Vector b=(*before)(t).get(Vector()); + return (b-a)*amount+a; } default: break; @@ -237,35 +258,29 @@ synfig::ValueNode_TimedSwap::operator()(Time t)const bool ValueNode_TimedSwap::set_link_vfunc(int i,ValueNode::Handle x) { - assert(i>=0 && i<4); + assert(i>=0 && i=0 && i<4); + assert(i>=0 && i=0 && i<4); + assert(i>=0 && i=0 && i<4); + assert(i>=0 && i