Add my copyright to files I've modified.
[synfig.git] / synfig-core / trunk / src / synfig / valuenode_timedswap.cpp
index 0f51539..20be99f 100644 (file)
@@ -1,20 +1,22 @@
-/* === S I N F G =========================================================== */
+/* === S Y N F I G ========================================================= */
 /*!    \file valuenode_timedswap.cpp
 **     \brief Template File
 **
-**     $Id: valuenode_timedswap.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 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
 */
 /* ========================================================================= */
@@ -40,7 +42,7 @@
 
 using namespace std;
 using namespace etl;
-using namespace sinfg;
+using namespace synfig;
 
 /* === M A C R O S ========================================================= */
 
@@ -50,13 +52,41 @@ using namespace sinfg;
 
 /* === 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();
 }
@@ -64,7 +94,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);
 }
 
 
@@ -75,7 +105,7 @@ ValueNode_TimedSwap::create_new()const
 }
 
 
-sinfg::ValueNode_TimedSwap::~ValueNode_TimedSwap()
+synfig::ValueNode_TimedSwap::~ValueNode_TimedSwap()
 {
        unlink_all();
 }
@@ -120,20 +150,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;
 }
@@ -144,21 +167,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;
 }
@@ -171,35 +186,23 @@ ValueNode_TimedSwap::get_swap_length()const
 
 
 
-sinfg::ValueBase
-sinfg::ValueNode_TimedSwap::operator()(Time t)const
+synfig::ValueBase
+synfig::ValueNode_TimedSwap::operator()(Time t)const
 {
        Time swptime=(*swap_time)(t).get(Time());
        Time swplength=(*swap_length)(t).get(Time());
 
        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());
@@ -219,6 +222,24 @@ sinfg::ValueNode_TimedSwap::operator()(Time t)const
                                float b=(float)(*before)(t).get(int());
                                return static_cast<int>((b-a)*amount+a+0.5f);
                        }
+               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;
                }
@@ -239,16 +260,12 @@ ValueNode_TimedSwap::set_link_vfunc(int i,ValueNode::Handle x)
        assert(i>=0 && i<4);
        switch(i)
        {
-       case 0:
-               return set_before(x);
-       case 1:
-               return set_after(x);
-       case 2:
-               return set_swap_time(x);
-       case 3:
-               return set_swap_length(x);
+       case 0: return set_before(x);
+       case 1: return set_after(x);
+       case 2: return set_swap_time(x);
+       case 3: return set_swap_length(x);
        }
-       return 0;
+       return false;
 }
 
 ValueNode::LooseHandle
@@ -257,14 +274,10 @@ ValueNode_TimedSwap::get_link_vfunc(int i)const
        assert(i>=0 && i<4);
        switch(i)
        {
-       case 0:
-               return get_before();
-       case 1:
-               return get_after();
-       case 2:
-               return get_swap_time();
-       case 3:
-               return get_swap_length();
+       case 0: return get_before();
+       case 1: return get_after();
+       case 2: return get_swap_time();
+       case 3: return get_swap_length();
        }
        return 0;
 }
@@ -281,17 +294,13 @@ ValueNode_TimedSwap::link_local_name(int i)const
        assert(i>=0 && i<4);
        switch(i)
        {
-       case 0:
-               return _("Before");
-       case 1:
-               return _("After");
-       case 2:
-               return _("Swap Time");
-       case 3:
-               return _("Swap Duration");
+       case 0: return _("Before");
+       case 1: return _("After");
+       case 2: return _("Swap Time");
+       case 3: return _("Swap Duration");
+       default:return String();
        }
-       return 0;
-}      
+}
 
 String
 ValueNode_TimedSwap::link_name(int i)const
@@ -299,29 +308,21 @@ ValueNode_TimedSwap::link_name(int i)const
        assert(i>=0 && i<4);
        switch(i)
        {
-       case 0:
-               return "before";
-       case 1:
-               return "after";
-       case 2:
-               return "time";
-       case 3:
-               return "length";
+       case 0: return "before";
+       case 1: return "after";
+       case 2: return "time";
+       case 3: return "length";
+       default:return String();
        }
-       return 0;
-}      
+}
 
 int
 ValueNode_TimedSwap::get_link_index_from_name(const String &name)const
 {
-       if(name=="before")
-               return 0;
-       if(name=="after")
-               return 1;
-       if(name=="time")
-               return 2;
-       if(name=="length")
-               return 3;
+       if(name=="before")      return 0;
+       if(name=="after")       return 1;
+       if(name=="time")        return 2;
+       if(name=="length")      return 3;
 
        throw Exception::BadLinkName(name);
 }
@@ -341,7 +342,11 @@ ValueNode_TimedSwap::get_local_name()const
 bool
 ValueNode_TimedSwap::check_type(ValueBase::Type type)
 {
-       if(!type)
-               return false;
-       return true;
+       return
+               type==ValueBase::TYPE_ANGLE ||
+               type==ValueBase::TYPE_COLOR ||
+               type==ValueBase::TYPE_INTEGER ||
+               type==ValueBase::TYPE_REAL ||
+               type==ValueBase::TYPE_TIME ||
+               type==ValueBase::TYPE_VECTOR;
 }