Remove .gitignore do nothing is ignored.
[synfig.git] / synfig-studio / trunk / src / gtkmm / duck.cpp
index f540c3d..e88306e 100644 (file)
@@ -1,20 +1,22 @@
-/* === S I N F G =========================================================== */
+/* === S Y N F I G ========================================================= */
 /*!    \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 Robert B. Quattlebaum Jr.
+**     Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
+**     Copyright (c) 2007, 2008 Chris Moore
 **
-**     This software and associated documentation
-**     are CONFIDENTIAL and PROPRIETARY property of
-**     the above-mentioned copyright holder.
+**     This package is free software; you can redistribute it and/or
+**     modify it under the terms of the GNU General Public License as
+**     published by the Free Software Foundation; either version 2 of
+**     the License, or (at your option) any later version.
 **
-**     You may not copy, print, publish, or in any
-**     other way distribute this software without
-**     a prior written agreement with
-**     the copyright holder.
+**     This package is distributed in the hope that it will be useful,
+**     but WITHOUT ANY WARRANTY; without even the implied warranty of
+**     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+**     General Public License for more details.
 **     \endlegal
 */
 /* ========================================================================= */
@@ -29,6 +31,9 @@
 #endif
 
 #include "duck.h"
+#include <ETL/misc>
+
+#include "general.h"
 
 #endif
 
@@ -36,7 +41,7 @@
 
 using namespace std;
 using namespace etl;
-using namespace sinfg;
+using namespace synfig;
 using namespace studio;
 
 /* === M A C R O S ========================================================= */
@@ -51,7 +56,7 @@ struct _DuckCounter
        ~_DuckCounter()
        {
                if(counter)
-                       sinfg::error("%d ducks not yet deleted!",counter);
+                       synfig::error("%d ducks not yet deleted!",counter);
        }
 } _duck_counter;
 
@@ -63,51 +68,60 @@ 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 sinfg::Point &point):
+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 sinfg::Point &point,const sinfg::Point &origin):
+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--;}
 
-sinfg::GUID
+synfig::GUID
 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 sinfg::String &x)
+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);
        }
 }
 
@@ -127,21 +141,21 @@ Duck::operator==(const Duck &rhs)const
                //(shared_point?*shared_point==*rhs.shared_point:point==rhs.point) ;
 }
 
-sinfg::Point
+synfig::Point
 Duck::get_trans_point()const
 {
        return transform_stack_.perform(get_sub_trans_point());
 }
-       
+
 void
-Duck::set_trans_point(const sinfg::Point &x)
+Duck::set_trans_point(const synfig::Point &x)
 {
        set_sub_trans_point(transform_stack_.unperform(x));
 }
 
 //! Sets the origin point.
 void
-Duck::set_origin(const sinfg::Point &x)
+Duck::set_origin(const synfig::Point &x)
 {
        origin=x; origin_duck=0;
 }
@@ -154,7 +168,7 @@ Duck::set_origin(const etl::handle<Duck> &x)
 }
 
 //! Retrieves the origin location
-sinfg::Point
+synfig::Point
 Duck::get_origin()const
 {
        return origin_duck?origin_duck->get_point():origin;
@@ -168,26 +182,63 @@ Duck::get_origin_duck() const
 }
 
 //! Retrieves the origin location
-sinfg::Point
+synfig::Point
 Duck::get_trans_origin()const
 {
        return transform_stack_.perform(get_sub_trans_origin());
 }
 
-sinfg::Point
+synfig::Point
 Duck::get_sub_trans_point()const
 {
        return get_point()*get_scalar()+get_sub_trans_origin();
 }
 
 void
-Duck::set_sub_trans_point(const sinfg::Point &x)
+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());
 }
 
-sinfg::Point
+synfig::Point
 Duck::get_sub_trans_origin()const
 {
        return origin_duck?origin_duck->get_sub_trans_point():origin;
 }
+
+#ifdef _DEBUG
+synfig::String
+Duck::type_name(Type id)
+{
+       String ret;
+
+       if (id & TYPE_POSITION) { if (!ret.empty()) ret += ", "; ret += "position"; }
+       if (id & TYPE_TANGENT ) { if (!ret.empty()) ret += ", "; ret += "tangent" ; }
+       if (id & TYPE_RADIUS  ) { if (!ret.empty()) ret += ", "; ret += "radius"  ; }
+       if (id & TYPE_WIDTH       ) { if (!ret.empty()) ret += ", "; ret += "width"   ; }
+       if (id & TYPE_ANGLE       ) { if (!ret.empty()) ret += ", "; ret += "angle"   ; }
+       if (id & TYPE_VERTEX  ) { if (!ret.empty()) ret += ", "; ret += "vertex"  ; }
+
+       if (ret.empty())
+               ret = "none";
+
+       return ret;
+}
+#endif // _DEBUG