Better functionality for ducks linked to BLine
[synfig.git] / synfig-studio / src / gtkmm / duck.cpp
index c142a5b..da32897 100644 (file)
@@ -7,6 +7,7 @@
 **     \legal
 **     Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
 **     Copyright (c) 2007, 2008 Chris Moore
+**     Copyright (c) 2009 Nikita Kitaev
 **
 **     This package is free software; you can redistribute it and/or
 **     modify it under the terms of the GNU General Public License as
@@ -208,11 +209,11 @@ Duck::get_sub_trans_point()const
 void
 Duck::set_sub_trans_point(const synfig::Point &x, const synfig::Time &time)
 {
-       set_point((x-get_sub_trans_origin())/get_scalar());
        if (get_type() == Duck::TYPE_TANGENT ||
                get_type() == Duck::TYPE_ANGLE)
        {
                Angle old_angle = get_point().angle();
+               set_point((x-get_sub_trans_origin())/get_scalar());
                Angle change = get_point().angle() - old_angle;
                while (change < Angle::deg(-180)) change += Angle::deg(360);
                while (change > Angle::deg(180)) change -= Angle::deg(360);
@@ -225,6 +226,7 @@ Duck::set_sub_trans_point(const synfig::Point &x, const synfig::Time &time)
                        synfig::info("rotation: %.2f turns", new_halves/2.0);
        } else if(get_type() == Duck::TYPE_VERTEX || get_type() == Duck::TYPE_POSITION)
        {
+               set_point((x-get_sub_trans_origin())/get_scalar());
 
                ValueNode_BLineCalcVertex::Handle bline_vertex;
                ValueNode_Composite::Handle composite;
@@ -246,13 +248,14 @@ Duck::set_sub_trans_point(const synfig::Point &x, const synfig::Time &time)
                        set_point(closest_point);
                }
        }
+       else set_point((x-get_sub_trans_origin())/get_scalar());
 }
 
 //! Updates width and tangent ducks that change when the origin moves
 void
 Duck::update(const synfig::Time &time)
 {
-       if((get_type() == Duck::TYPE_TANGENT || get_type() == Duck::TYPE_WIDTH) && origin_duck)
+       if((get_type() == Duck::TYPE_TANGENT || get_type() == Duck::TYPE_WIDTH || get_type() == Duck::TYPE_ANGLE) && origin_duck)
        {
                ValueNode_BLineCalcVertex::Handle bline_vertex;
                ValueNode_Composite::Handle composite;
@@ -277,6 +280,7 @@ Duck::update(const synfig::Time &time)
                                {
                                        Angle angle((*bline_tangent)(time, amount).get(Angle()));
                                        set_point(Point(Angle::cos(angle).get(), Angle::sin(angle).get()));
+                                       rotations=synfig::Angle::deg(0); //hack: rotations are a relative value
                                        break;
                                }
                                case ValueBase::TYPE_REAL:
@@ -300,11 +304,11 @@ Duck::update(const synfig::Time &time)
 void
 Duck::set_sub_trans_point(const synfig::Point &x)
 {
-       set_point((x-get_sub_trans_origin())/get_scalar());
        if (get_type() == Duck::TYPE_TANGENT ||
                get_type() == Duck::TYPE_ANGLE)
        {
                Angle old_angle = get_point().angle();
+               set_point((x-get_sub_trans_origin())/get_scalar());
                Angle change = get_point().angle() - old_angle;
                while (change < Angle::deg(-180)) change += Angle::deg(360);
                while (change > Angle::deg(180)) change -= Angle::deg(360);
@@ -316,6 +320,7 @@ Duck::set_sub_trans_point(const synfig::Point &x)
                         old_halves > 1 || old_halves < -1))
                        synfig::info("rotation: %.2f turns", new_halves/2.0);
        }
+       else set_point((x-get_sub_trans_origin())/get_scalar());
 }
 
 synfig::Point