Remove some debugging code I left in accidentally some time ago.
[synfig.git] / synfig-core / trunk / src / synfig / valuenode_scale.cpp
index b758945..181cc29 100644 (file)
@@ -2,7 +2,7 @@
 /*!    \file valuenode_scale.cpp
 **     \brief Template File
 **
-**     $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
@@ -55,42 +55,52 @@ 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);
-}
+       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("synfig::ValueNode_Scale:Bad type "+ValueBase::type_name(value.get_type()));
        }
+
        assert(value_node);
-       assert(value_node->get_type()==x.get_type());
-       
-       return value_node;
+       assert(get_value_node()->get_type()==id);
+       assert(get_type()==id);
 }
 
 LinkableValueNode*
 ValueNode_Scale::create_new()const
 {
-       return new ValueNode_Scale();
+       return new ValueNode_Scale(get_type());
+}
+
+ValueNode_Scale*
+ValueNode_Scale::create(const ValueBase& value)
+{
+       return new ValueNode_Scale(value);
 }
 
 synfig::ValueNode_Scale::~ValueNode_Scale()
@@ -125,22 +135,19 @@ ValueNode_Scale::get_scalar()const
 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)
-       )
+       assert(get_type());
+
+       // if this isn't a proper value
+       if(!x ||
+          // or we don't have a type, and this value isn't one of the types we accept
+          (get_type()==ValueBase::TYPE_NIL && !check_type(x->get_type())) ||
+          // or we have a type and this value is a different type and (placeholder?)
+          (get_type()!=ValueBase::TYPE_NIL && x->get_type()!=get_type() && !PlaceholderValueNode::Handle::cast_dynamic(x)))
+               // then fail to set the value
                return false;
 
-       assert(!(PlaceholderValueNode::Handle::cast_dynamic(x) && !get_type()));
-
        value_node=x;
 
-       if(!get_type())
-               set_type(x->get_type());
-
        return true;
 }
 
@@ -167,7 +174,11 @@ synfig::ValueNode_Scale::operator()(Time t)const
                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());
+       {
+               Real ret = (*value_node)(t).get(int())*(*scalar)(t).get(Real()) + 0.5f;
+               if (ret < 0) return static_cast<int>(ret-1);
+               return static_cast<int>(ret);
+       }
        else
        if(get_type()==ValueBase::TYPE_ANGLE)
                return (*value_node)(t).get(Angle())*(*scalar)(t).get(Real());
@@ -177,8 +188,8 @@ synfig::ValueNode_Scale::operator()(Time t)const
                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;
        }
 
@@ -192,13 +203,13 @@ ValueNode_Scale::set_link_vfunc(int i,ValueNode::Handle x)
 {
        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;
-       
+
        signal_child_changed()(i);signal_value_changed()();
 
        return true;
@@ -230,7 +241,7 @@ ValueNode_Scale::link_local_name(int i)const
        else if(i==1)
                return _("Scalar");
        return String();
-}      
+}
 
 String
 ValueNode_Scale::link_name(int i)const
@@ -250,7 +261,7 @@ ValueNode_Scale::get_link_index_from_name(const String &name)const
                return 0;
        if(name=="scalar")
                return 1;
-       
+
        throw Exception::BadLinkName(name);
 }