Fix bugs in previous commit that caused FTBFS in synfig and ETL FTBFS with older...
[synfig.git] / synfig-studio / tags / stable / src / gtkmm / duck.cpp
index b345be5..6b012a7 100644 (file)
@@ -6,6 +6,7 @@
 **
 **     \legal
 **     Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
+**     Copyright (c) 2007, 2008 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
@@ -30,6 +31,9 @@
 #endif
 
 #include "duck.h"
+#include <ETL/misc>
+
+#include "general.h"
 
 #endif
 
@@ -64,32 +68,41 @@ int _DuckCounter::counter(0);
 /* === M E T H O D S ======================================================= */
 
 Duck::Duck():
+       rotations(synfig::Angle::deg(0)),
        origin(0,0),
        scalar(1),
        editable(false),
        radius_(false),
-       tangent_(false)
+       tangent_(false),
+       hover_(false),
+       ignore_(false)
 { duck_count++; _DuckCounter::counter++; }
 
 Duck::Duck(const synfig::Point &point):
        type_(TYPE_NONE),
        point(point),
+       rotations(synfig::Angle::deg(0)),
        origin(0,0),
        scalar(1),
        guid_(0),
        editable(false),
        radius_(false),
-       tangent_(false)
+       tangent_(false),
+       hover_(false),
+       ignore_(false)
 { duck_count++; _DuckCounter::counter++;}
 
 Duck::Duck(const synfig::Point &point,const synfig::Point &origin):
        point(point),
+       rotations(synfig::Angle::deg(0)),
        origin(origin),
        scalar(1),
        guid_(0),
        editable(false),
        radius_(true),
-       tangent_(false)
+       tangent_(false),
+       hover_(false),
+       ignore_(false)
 { duck_count++; _DuckCounter::counter++;}
 
 Duck::~Duck() { duck_count--; _DuckCounter::counter--;}
@@ -99,16 +112,16 @@ Duck::get_data_guid()const
 {
        if(value_desc_.is_value_node())
                return value_desc_.get_value_node()->get_guid();
-       return GUID::hasher(get_name());
+       return synfig::GUID::hasher(get_name());
 }
 
 void
 Duck::set_name(const synfig::String &x)
 {
        name=x;
-       if(guid_==GUID::zero())
+       if(guid_==synfig::GUID::zero())
        {
-               guid_=GUID::hasher(name);
+               guid_=synfig::GUID::hasher(name);
        }
 }
 
@@ -184,7 +197,24 @@ Duck::get_sub_trans_point()const
 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);
+               int old_halves = round_to_int(Angle::deg(rotations).get()/180);
+               rotations += change;
+               int new_halves = round_to_int(Angle::deg(rotations).get()/180);
+               if (old_halves != new_halves &&
+                       (new_halves > 1 || new_halves < -1 ||
+                        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