Added my "Copyright (c) 2007" notices, for files I edited in 2007.
[synfig.git] / synfig-studio / trunk / src / gtkmm / duck.cpp
index aea6b94..67e28d0 100644 (file)
@@ -2,10 +2,11 @@
 /*!    \file duck.cpp
 **     \brief Template File
 **
-**     $Id: duck.cpp,v 1.1.1.1 2005/01/07 03:34:36 darco Exp $
+**     $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
@@ -30,6 +31,9 @@
 #endif
 
 #include "duck.h"
+#include <ETL/misc>
+
+#include "general.h"
 
 #endif
 
@@ -64,16 +68,19 @@ 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)
 { 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),
@@ -84,6 +91,7 @@ Duck::Duck(const synfig::Point &point):
 
 Duck::Duck(const synfig::Point &point,const synfig::Point &origin):
        point(point),
+       rotations(synfig::Angle::deg(0)),
        origin(origin),
        scalar(1),
        guid_(0),
@@ -184,7 +192,22 @@ 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_quarters = round_to_int(Angle::deg(rotations).get()/90);
+               rotations += change;
+               int new_quarters = round_to_int(Angle::deg(rotations).get()/90);
+               if (old_quarters != new_quarters)
+                       synfig::info("rotation: %.2f turns", new_quarters/4.0);
+       }
+       else
+               set_point((x-get_sub_trans_origin())/get_scalar());
 }
 
 synfig::Point