Change the default sub-parameters for the Time Loop convert so that the first second...
[synfig.git] / synfig-core / trunk / src / synfig / valuenode_add.cpp
index f9ddaf6..bf9f949 100644 (file)
@@ -1,11 +1,12 @@
 /* === S Y N F I G ========================================================= */
 /*!    \file valuenode_add.cpp
-**     \brief Template File
+**     \brief Implementation of the "Add" valuenode conversion.
 **
 **     $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
@@ -37,6 +38,7 @@
 #include "vector.h"
 #include "angle.h"
 #include "real.h"
+#include <ETL/misc>
 
 #endif
 
@@ -78,6 +80,10 @@ synfig::ValueNode_Add::ValueNode_Add(const ValueBase &value):
                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)));
@@ -168,13 +174,11 @@ synfig::ValueNode_Add::operator()(Time t)const
        case ValueBase::TYPE_COLOR:
                return ((*ref_a)(t).get(Color())+(*ref_b)(t).get(Color()))*(*scalar)(t).get(Real());
        case ValueBase::TYPE_INTEGER:
-       {
-               Real ret = ((*ref_a)(t).get(int())+(*ref_b)(t).get(int()))*(*scalar)(t).get(Real()) + 0.5f;
-               if (ret < 0) return static_cast<int>(ret-1);
-               return static_cast<int>(ret); 
-       }
+               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:
@@ -253,7 +257,6 @@ ValueNode_Add::link_name(int i)const
 int
 ValueNode_Add::get_link_index_from_name(const String &name)const
 {
-       printf("%s:%d link_index_from_name\n", __FILE__, __LINE__);
        if(name=="lhs") return 0;
        if(name=="rhs") return 1;
        if(name=="scalar") return 2;
@@ -279,5 +282,6 @@ ValueNode_Add::check_type(ValueBase::Type type)
                || type==ValueBase::TYPE_COLOR
                || type==ValueBase::TYPE_INTEGER
                || type==ValueBase::TYPE_REAL
+               || type==ValueBase::TYPE_TIME
                || type==ValueBase::TYPE_VECTOR;
 }