Change transform tool to read key states rather than events
[synfig.git] / synfig-studio / src / gtkmm / state_normal.cpp
index 2810db2..7eea702 100644 (file)
@@ -6,7 +6,8 @@
 **
 **     \legal
 **     Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
-**  Copyright (c) 2008 Chris Moore
+**     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
@@ -34,6 +35,7 @@
 #include <gtkmm/entry.h>
 
 #include <synfig/valuenode_animated.h>
+#include <synfig/valuenode_blinecalcvertex.h>
 #include <synfig/valuenode_composite.h>
 #include <synfig/valuenode_const.h>
 #include <synfig/valuenode_dynamiclist.h>
@@ -94,10 +96,10 @@ class DuckDrag_Combo : public DuckDrag_Base
        bool move_only;
 
 public:
-       etl::handle<CanvasView> canvas_view_;
+       CanvasView* canvas_view_;
        bool scale;
        bool rotate;
-       bool constrain;  
+       bool constrain;
        DuckDrag_Combo();
        void begin_duck_drag(Duckmatic* duckmatic, const synfig::Vector& begin);
        bool end_duck_drag(Duckmatic* duckmatic);
@@ -109,52 +111,32 @@ public:
 
 class studio::StateNormal_Context : public sigc::trackable
 {
-       etl::handle<CanvasView> canvas_view_;
+       CanvasView* canvas_view_;
 
        synfigapp::Settings& settings;
 
-       sigc::connection keypress_connect;
-       sigc::connection keyrelease_connect;
-
        etl::handle<DuckDrag_Combo> duck_dragger_;
 
        Gtk::Table options_table;
 
-       Gtk::CheckButton checkbutton_rotate;
-       Gtk::CheckButton checkbutton_scale;
-       Gtk::CheckButton checkbutton_constrain;
-
 public:
 
-       bool get_rotate_flag()const { return checkbutton_rotate.get_active(); }
-       void set_rotate_flag(bool x) { checkbutton_rotate.set_active(x); refresh_rotate_flag(); }
-       void refresh_rotate_flag() { if(duck_dragger_)duck_dragger_->rotate=get_rotate_flag(); }
+       bool get_rotate_flag()const { if(duck_dragger_) return duck_dragger_->rotate; else return false; }
+       void set_rotate_flag(bool x) { if(duck_dragger_ && x!=duck_dragger_->rotate) duck_dragger_->rotate=x; }
 
-       bool get_scale_flag()const { return checkbutton_scale.get_active(); }
-       void set_scale_flag(bool x) { checkbutton_scale.set_active(x); refresh_scale_flag(); }
-       void refresh_scale_flag() { if(duck_dragger_)duck_dragger_->scale=get_scale_flag(); }
+       bool get_scale_flag()const { if(duck_dragger_) return duck_dragger_->scale; else return false; }
+       void set_scale_flag(bool x) { if(duck_dragger_ && x!=duck_dragger_->scale) duck_dragger_->scale=x; }
 
-       bool get_constrain_flag()const { return checkbutton_constrain.get_active(); }
-       void set_constrain_flag(bool x) { checkbutton_constrain.set_active(x); refresh_constrain_flag(); }
-       void refresh_constrain_flag() { if(duck_dragger_)duck_dragger_->constrain=get_constrain_flag(); }
+       bool get_constrain_flag()const { if(duck_dragger_) return duck_dragger_->constrain; else return false; }
+       void set_constrain_flag(bool x) { if(duck_dragger_ && x!=duck_dragger_->constrain) duck_dragger_->constrain=x; }
 
-       Smach::event_result event_stop_handler(const Smach::event& x);
-       Smach::event_result event_refresh_handler(const Smach::event& x);
-       Smach::event_result event_refresh_ducks_handler(const Smach::event& x);
-       Smach::event_result event_undo_handler(const Smach::event& x);
-       Smach::event_result event_redo_handler(const Smach::event& x);
-       Smach::event_result event_mouse_button_down_handler(const Smach::event& x);
-       Smach::event_result event_multiple_ducks_clicked_handler(const Smach::event& x);
-       Smach::event_result event_refresh_tool_options(const Smach::event& x);
-       Smach::event_result event_layer_click(const Smach::event& x);
-
-       void refresh_tool_options();
+       void refresh_cursor();
 
        StateNormal_Context(CanvasView* canvas_view);
 
        ~StateNormal_Context();
 
-       const etl::handle<CanvasView>& get_canvas_view()const{return canvas_view_;}
+       CanvasView* get_canvas_view()const{return canvas_view_;}
        etl::handle<synfigapp::CanvasInterface> get_canvas_interface()const{return canvas_view_->canvas_interface();}
        synfig::Canvas::Handle get_canvas()const{return canvas_view_->get_canvas();}
        WorkArea * get_work_area()const{return canvas_view_->get_work_area();}
@@ -162,8 +144,18 @@ public:
        void load_settings();
        void save_settings();
 
-       bool key_pressed(GdkEventKey *event);
-       bool key_released(GdkEventKey *event);
+       Smach::event_result event_stop_handler(const Smach::event& x);
+       Smach::event_result event_refresh_handler(const Smach::event& x);
+       Smach::event_result event_refresh_ducks_handler(const Smach::event& x);
+       Smach::event_result event_undo_handler(const Smach::event& x);
+       Smach::event_result event_redo_handler(const Smach::event& x);
+       Smach::event_result event_mouse_button_down_handler(const Smach::event& x);
+       Smach::event_result event_multiple_ducks_clicked_handler(const Smach::event& x);
+       Smach::event_result event_mouse_motion_handler(const Smach::event& x);
+       Smach::event_result event_refresh_tool_options(const Smach::event& x);
+       void refresh_tool_options();
+       Smach::event_result event_layer_click(const Smach::event& x);
+
 
 };     // END of class StateNormal_Context
 
@@ -180,13 +172,56 @@ StateNormal::StateNormal():
        insert(event_def(EVENT_WORKAREA_MOUSE_BUTTON_DOWN,&StateNormal_Context::event_mouse_button_down_handler));
        insert(event_def(EVENT_WORKAREA_MULTIPLE_DUCKS_CLICKED,&StateNormal_Context::event_multiple_ducks_clicked_handler));
        insert(event_def(EVENT_REFRESH_TOOL_OPTIONS,&StateNormal_Context::event_refresh_tool_options));
+       insert(event_def(EVENT_WORKAREA_MOUSE_MOTION,           &StateNormal_Context::event_mouse_motion_handler));
+       insert(event_def(EVENT_WORKAREA_MOUSE_BUTTON_DRAG,      &StateNormal_Context::event_mouse_motion_handler));
        insert(event_def(EVENT_WORKAREA_LAYER_CLICKED,&StateNormal_Context::event_layer_click));
+
 }
 
 StateNormal::~StateNormal()
 {
 }
 
+void StateNormal_Context::refresh_cursor()
+{
+       // Check the current state and return when applicable
+       synfig::String sname;
+       sname=get_canvas_view()->get_smach().get_state_name();
+       if (sname=="smooth_move"||sname=="zoom"||sname=="width" ||
+               sname=="text"||sname=="stroke"||sname=="star"||sname=="sketch"||
+               sname=="scale"||sname=="zoom"||sname=="rotate"||sname=="rectangle"||
+               sname=="polygon"||sname=="gradient"||sname=="fill"||sname=="draw"||
+               sname=="circle")
+                       return;
+
+       // Change the cursor based on key flags
+       if(get_rotate_flag() && !get_scale_flag())
+       {
+               get_work_area()->set_cursor(Gdk::EXCHANGE);
+               return;
+       }
+       if(!get_rotate_flag() && get_scale_flag())
+       {
+               get_work_area()->set_cursor(Gdk::SIZING);
+               return;
+       }
+       if(get_rotate_flag() && get_scale_flag())
+       {
+               get_work_area()->set_cursor(Gdk::CROSSHAIR);
+               return;
+       }
+       // If we are in BLine state and there is not key pressed return to
+       // the bline cursor.
+       if (sname=="bline")
+       {
+               get_work_area()->set_cursor(Gdk::CROSSHAIR);
+               return;
+       }
+       // Default cursor for Transform tool
+       get_work_area()->set_cursor(Gdk::ARROW);
+
+}
+
 void
 StateNormal_Context::load_settings()
 {
@@ -220,88 +255,31 @@ StateNormal_Context::save_settings()
 StateNormal_Context::StateNormal_Context(CanvasView* canvas_view):
        canvas_view_(canvas_view),
        settings(synfigapp::Main::get_selected_input_device()->settings()),
-       duck_dragger_(new DuckDrag_Combo()),
-       checkbutton_rotate(_("Rotate (Ctrl)")),
-       checkbutton_scale(_("Scale (Alt)")),
-       checkbutton_constrain(_("Constrain (Shift)"))
+       duck_dragger_(new DuckDrag_Combo())
 {
        duck_dragger_->canvas_view_=get_canvas_view();
 
        // Set up the tool options dialog
-       options_table.attach(*manage(new Gtk::Label(_("Normal Tool"))), 0, 2, 0, 1, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
-       options_table.attach(checkbutton_rotate,                                                        0, 2, 1, 2, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
-       options_table.attach(checkbutton_scale,                                                 0, 2, 2, 3, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
-       options_table.attach(checkbutton_constrain,                                                     0, 2, 3, 4, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
-
-       checkbutton_rotate.signal_toggled().connect(sigc::mem_fun(*this,&StateNormal_Context::refresh_rotate_flag));
-       checkbutton_scale.signal_toggled().connect(sigc::mem_fun(*this,&StateNormal_Context::refresh_scale_flag));
-       checkbutton_constrain.signal_toggled().connect(sigc::mem_fun(*this,&StateNormal_Context::refresh_constrain_flag));
-
+       options_table.attach(*manage(new Gtk::Label(_("Transform Tool"))),      0, 2, 0, 1, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
+       options_table.attach(*manage(new Gtk::Label(_("Ctrl to rotate"), Gtk::ALIGN_LEFT)),     0, 2, 1, 2, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
+       options_table.attach(*manage(new Gtk::Label(_("Alt to scale"), Gtk::ALIGN_LEFT)),       0, 2, 2, 3, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
+       options_table.attach(*manage(new Gtk::Label(_("Shift to constrain"), Gtk::ALIGN_LEFT)), 0, 2, 3, 4, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
 
        options_table.show_all();
        refresh_tool_options();
        //App::dialog_tool_options->set_widget(options_table);
-       App::dialog_tool_options->present();
+       //App::dialog_tool_options->present();
 
        get_work_area()->set_allow_layer_clicks(true);
        get_work_area()->set_duck_dragger(duck_dragger_);
 
-       keypress_connect=get_work_area()->signal_key_press_event().connect(sigc::mem_fun(*this,&StateNormal_Context::key_pressed),false);
-       keyrelease_connect=get_work_area()->signal_key_release_event().connect(sigc::mem_fun(*this,&StateNormal_Context::key_released),false);
-
-//     get_canvas_view()->work_area->set_cursor(Gdk::CROSSHAIR);
-       get_canvas_view()->work_area->reset_cursor();
+       //these will segfault
+//     get_work_area()->set_cursor(Gdk::CROSSHAIR);
+//     get_work_area()->reset_cursor();
 
        App::toolbox->refresh();
 
        load_settings();
-       refresh_scale_flag();
-}
-
-bool
-StateNormal_Context::key_pressed(GdkEventKey *event)
-{
-       switch(event->keyval)
-       {
-               case GDK_Control_L:
-               case GDK_Control_R:
-                       set_rotate_flag(true);
-                       break;
-               case GDK_Alt_L:
-               case GDK_Alt_R:
-                       set_scale_flag(true);
-                       break;
-               case GDK_Shift_L:
-               case GDK_Shift_R:
-                       set_constrain_flag(true);
-                       break;
-               default:
-                       break;
-       }
-       return false; //Pass on the event to other handlers, just in case
-}
-
-bool
-StateNormal_Context::key_released(GdkEventKey *event)
-{
-       switch(event->keyval)
-       {
-               case GDK_Control_L:
-               case GDK_Control_R:
-                       set_rotate_flag(false);
-                       break;
-               case GDK_Alt_L:
-               case GDK_Alt_R:
-                       set_scale_flag(false);
-                       break;
-               case GDK_Shift_L:
-               case GDK_Shift_R:
-                       set_constrain_flag(false);
-                       break;
-               default:
-                       break;
-       }
-       return false; //Pass on the event to other handlers
 }
 
 void
@@ -309,7 +287,7 @@ StateNormal_Context::refresh_tool_options()
 {
        App::dialog_tool_options->clear();
        App::dialog_tool_options->set_widget(options_table);
-       App::dialog_tool_options->set_local_name(_("Normal Tool"));
+       App::dialog_tool_options->set_local_name(_("Transform Tool"));
        App::dialog_tool_options->set_name("normal");
 }
 
@@ -320,16 +298,214 @@ StateNormal_Context::~StateNormal_Context()
        save_settings();
 
        get_work_area()->clear_duck_dragger();
-       get_canvas_view()->work_area->reset_cursor();
-
-       keypress_connect.disconnect();
-       keyrelease_connect.disconnect();
+       get_work_area()->reset_cursor();
 
        App::dialog_tool_options->clear();
 
        App::toolbox->refresh();
 }
 
+DuckDrag_Combo::DuckDrag_Combo():
+       scale(false),
+       rotate(false),
+       constrain(false) // Lock aspect for scale; smooth move for translate
+{
+}
+
+void
+DuckDrag_Combo::begin_duck_drag(Duckmatic* duckmatic, const synfig::Vector& offset)
+{
+       last_move=Vector(1,1);
+
+       const DuckList selected_ducks(duckmatic->get_selected_ducks());
+       DuckList::const_iterator iter;
+
+       bad_drag=false;
+
+               drag_offset=duckmatic->find_duck(offset)->get_trans_point();
+
+               //snap=drag_offset-duckmatic->snap_point_to_grid(drag_offset);
+               //snap=offset-drag_offset_;
+               snap=Vector(0,0);
+
+       // Calculate center
+       Point vmin(100000000,100000000);
+       Point vmax(-100000000,-100000000);
+       //std::set<etl::handle<Duck> >::iterator iter;
+       positions.clear();
+       int i;
+       for(i=0,iter=selected_ducks.begin();iter!=selected_ducks.end();++iter,i++)
+       {
+               Point p((*iter)->get_trans_point());
+               vmin[0]=min(vmin[0],p[0]);
+               vmin[1]=min(vmin[1],p[1]);
+               vmax[0]=max(vmax[0],p[0]);
+               vmax[1]=max(vmax[1],p[1]);
+               positions.push_back(p);
+       }
+       center=(vmin+vmax)*0.5;
+       if((vmin-vmax).mag()<=EPSILON)
+               move_only=true;
+       else
+               move_only=false;
+
+
+       synfig::Vector vect(offset-center);
+       original_angle=Angle::tan(vect[1],vect[0]);
+       original_mag=vect.mag();
+}
+
+
+void
+DuckDrag_Combo::duck_drag(Duckmatic* duckmatic, const synfig::Vector& vector)
+{
+       if (!duckmatic) return;
+
+       if(bad_drag)
+               return;
+
+       //Override axis lock set in workarea when holding down the shift key
+       if (!move_only && (scale || rotate))
+               duckmatic->set_axis_lock(false);
+
+       synfig::Vector vect;
+       if (move_only || (!scale && !rotate))
+               vect= duckmatic->snap_point_to_grid(vector)-drag_offset+snap;
+       else
+               vect= duckmatic->snap_point_to_grid(vector)-center+snap;
+
+       last_move=vect;
+
+       const DuckList selected_ducks(duckmatic->get_selected_ducks());
+       DuckList::const_iterator iter;
+
+       Time time(duckmatic->get_time());
+
+       int i;
+       if( move_only || (!scale && !rotate) )
+       {
+               for(i=0,iter=selected_ducks.begin();iter!=selected_ducks.end();++iter,i++)
+               {
+                       if((*iter)->get_type()==Duck::TYPE_VERTEX || (*iter)->get_type()==Duck::TYPE_POSITION)
+                               (*iter)->set_trans_point(positions[i]+vect, time);
+               }
+               for(i=0,iter=selected_ducks.begin();iter!=selected_ducks.end();++iter,i++)
+               {
+                       if((*iter)->get_type()!=Duck::TYPE_VERTEX&&(*iter)->get_type()!=Duck::TYPE_POSITION)
+                               (*iter)->set_trans_point(positions[i]+vect, time);
+               }
+       }
+
+       if (rotate)
+       {
+               Angle::deg angle(Angle::tan(vect[1],vect[0]));
+               angle=original_angle-angle;
+               if (constrain)
+               {
+                       float degrees = angle.get()/15;
+                       angle= Angle::deg (degrees>0?std::floor(degrees)*15:std::ceil(degrees)*15);
+               }
+               Real mag(vect.mag()/original_mag);
+               Real sine(Angle::sin(angle).get());
+               Real cosine(Angle::cos(angle).get());
+
+               for(i=0,iter=selected_ducks.begin();iter!=selected_ducks.end();++iter,i++)
+               {
+                       if((*iter)->get_type()!=Duck::TYPE_VERTEX&&(*iter)->get_type()!=Duck::TYPE_POSITION)continue;
+
+                       Vector x(positions[i]-center),p;
+
+                       p[0]=cosine*x[0]+sine*x[1];
+                       p[1]=-sine*x[0]+cosine*x[1];
+                       if(scale)p*=mag;
+                       p+=center;
+                       (*iter)->set_trans_point(p, time);
+               }
+               for(i=0,iter=selected_ducks.begin();iter!=selected_ducks.end();++iter,i++)
+               {
+                       if(!((*iter)->get_type()!=Duck::TYPE_VERTEX&&(*iter)->get_type()!=Duck::TYPE_POSITION))continue;
+
+                       Vector x(positions[i]-center),p;
+
+                       p[0]=cosine*x[0]+sine*x[1];
+                       p[1]=-sine*x[0]+cosine*x[1];
+                       if(scale)p*=mag;
+                       p+=center;
+                       (*iter)->set_trans_point(p, time);
+               }
+       } else if (scale)
+       {
+               if(!constrain)
+               {
+                       if(abs(drag_offset[0]-center[0])>EPSILON)
+                               vect[0]/=drag_offset[0]-center[0];
+                       else
+                               vect[0]=1;
+                       if(abs(drag_offset[1]-center[1])>EPSILON)
+                               vect[1]/=drag_offset[1]-center[1];
+                       else
+                               vect[1]=1;
+                       }
+               else
+               {
+                       //vect[0]=vect[1]=vect.mag()*0.707106781;
+                       Real amount(vect.mag()/(drag_offset-center).mag());
+                       vect[0]=vect[1]=amount;
+               }
+
+               if(vect[0]<EPSILON && vect[0]>-EPSILON)
+                       vect[0]=1;
+               if(vect[1]<EPSILON && vect[1]>-EPSILON)
+                       vect[1]=1;
+
+               for(i=0,iter=selected_ducks.begin();iter!=selected_ducks.end();++iter,i++)
+               {
+                       if(((*iter)->get_type()!=Duck::TYPE_VERTEX&&(*iter)->get_type()!=Duck::TYPE_POSITION))continue;
+
+                       Vector p(positions[i]-center);
+
+                       p[0]*=vect[0];
+                       p[1]*=vect[1];
+                       p+=center;
+                       (*iter)->set_trans_point(p, time);
+               }
+               for(i=0,iter=selected_ducks.begin();iter!=selected_ducks.end();++iter,i++)
+               {
+                       if(!((*iter)->get_type()!=Duck::TYPE_VERTEX&&(*iter)->get_type()!=Duck::TYPE_POSITION))continue;
+
+                       Vector p(positions[i]-center);
+
+                       p[0]*=vect[0];
+                       p[1]*=vect[1];
+                       p+=center;
+                       (*iter)->set_trans_point(p, time);
+               }
+       }
+
+       // then patch up the tangents for the vertices we've moved
+       duckmatic->update_ducks();
+
+       last_move=vect;
+}
+
+bool
+DuckDrag_Combo::end_duck_drag(Duckmatic* duckmatic)
+{
+       if(bad_drag)return false;
+
+       //synfigapp::Action::PassiveGrouper group(get_canvas_interface()->get_instance().get(),_("Rotate Ducks"));
+
+       if((last_move-Vector(1,1)).mag()>0.0001)
+       {
+               duckmatic->signal_edited_selected_ducks();
+               return true;
+       }
+       else
+       {
+               duckmatic->signal_user_click_selected_ducks(0);
+               return false;
+       }
+}
 
 Smach::event_result
 StateNormal_Context::event_refresh_tool_options(const Smach::event& /*x*/)
@@ -397,6 +573,20 @@ StateNormal_Context::event_mouse_button_down_handler(const Smach::event& x)
 }
 
 Smach::event_result
+StateNormal_Context::event_mouse_motion_handler(const Smach::event& x)
+{
+       // synfig::info("STATE NORMAL: Received mouse button down Event");
+
+       const EventMouse& event(*reinterpret_cast<const EventMouse*>(&x));
+
+       set_rotate_flag(event.modifier&GDK_CONTROL_MASK);
+       set_scale_flag(event.modifier&GDK_MOD1_MASK);
+       set_constrain_flag(event.modifier&GDK_SHIFT_MASK);
+
+       return Smach::RESULT_OK;
+}
+
+Smach::event_result
 StateNormal_Context::event_layer_click(const Smach::event& x)
 {
        const EventLayerClick& event(*reinterpret_cast<const EventLayerClick*>(&x));
@@ -616,209 +806,4 @@ StateNormal_Context::event_multiple_ducks_clicked_handler(const Smach::event& /*
        return Smach::RESULT_ACCEPT;
 }
 
-DuckDrag_Combo::DuckDrag_Combo():
-       scale(false),
-       rotate(false),
-       constrain(false) // Lock aspect for scale; smooth move for translate
-{
-}
 
-void
-DuckDrag_Combo::begin_duck_drag(Duckmatic* duckmatic, const synfig::Vector& offset)
-{
-       last_move=Vector(1,1);
-
-       const DuckList selected_ducks(duckmatic->get_selected_ducks());
-       DuckList::const_iterator iter;
-
-       bad_drag=false;
-
-               drag_offset=duckmatic->find_duck(offset)->get_trans_point();
-
-               //snap=drag_offset-duckmatic->snap_point_to_grid(drag_offset);
-               //snap=offset-drag_offset_;
-               snap=Vector(0,0);
-
-       // Calculate center
-       Point vmin(100000000,100000000);
-       Point vmax(-100000000,-100000000);
-       //std::set<etl::handle<Duck> >::iterator iter;
-       positions.clear();
-       int i;
-       for(i=0,iter=selected_ducks.begin();iter!=selected_ducks.end();++iter,i++)
-       {
-               Point p((*iter)->get_trans_point());
-               vmin[0]=min(vmin[0],p[0]);
-               vmin[1]=min(vmin[1],p[1]);
-               vmax[0]=max(vmax[0],p[0]);
-               vmax[1]=max(vmax[1],p[1]);
-               positions.push_back(p);
-       }
-       center=(vmin+vmax)*0.5;
-       if((vmin-vmax).mag()<=EPSILON)
-               move_only=true;
-       else
-               move_only=false;
-
-
-       synfig::Vector vect(offset-center);
-       original_angle=Angle::tan(vect[1],vect[0]);
-       original_mag=vect.mag();
-}
-
-
-void
-DuckDrag_Combo::duck_drag(Duckmatic* duckmatic, const synfig::Vector& vector)
-{
-       if (!duckmatic) return;
-
-       if(bad_drag)
-               return;
-
-       //Override axis lock set in workarea when holding down the shift key
-       if (!move_only && (scale || rotate))
-               duckmatic->set_axis_lock(false);
-
-       synfig::Vector vect;
-       if (move_only || (!scale && !rotate))
-               vect= duckmatic->snap_point_to_grid(vector)-drag_offset+snap;
-       else
-               vect= duckmatic->snap_point_to_grid(vector)-center+snap;
-
-       last_move=vect;
-
-       const DuckList selected_ducks(duckmatic->get_selected_ducks());
-       DuckList::const_iterator iter;
-
-       Time time(duckmatic->get_time());
-
-       int i;
-       if( move_only || (!scale && !rotate) )
-       {
-               for(i=0,iter=selected_ducks.begin();iter!=selected_ducks.end();++iter,i++)
-               {
-                       if((*iter)->get_type()==Duck::TYPE_VERTEX || (*iter)->get_type()==Duck::TYPE_POSITION)
-                               (*iter)->set_trans_point(positions[i]+vect, time);
-               }
-               for(i=0,iter=selected_ducks.begin();iter!=selected_ducks.end();++iter,i++)
-               {
-                       if((*iter)->get_type()!=Duck::TYPE_VERTEX&&(*iter)->get_type()!=Duck::TYPE_POSITION)
-                               (*iter)->set_trans_point(positions[i]+vect, time);
-               }
-               DuckList duck_list(duckmatic->get_duck_list());
-               for (iter=duck_list.begin(); iter!=duck_list.end(); ++iter)
-               {
-                       if ((*iter)->get_type() == Duck::TYPE_TANGENT || (*iter)->get_type() == Duck::TYPE_WIDTH)
-                       {
-                               (*iter)->update(time);
-                       }
-               }
-               return;
-       }
-
-       if (rotate)
-       {
-               Angle::deg angle(Angle::tan(vect[1],vect[0]));
-               angle=original_angle-angle;
-               if (constrain)
-               {
-                       float degrees = angle.get()/15;
-                       angle= Angle::deg (degrees>0?std::floor(degrees)*15:std::ceil(degrees)*15);
-               }
-               Real mag(vect.mag()/original_mag);
-               Real sine(Angle::sin(angle).get());
-               Real cosine(Angle::cos(angle).get());
-
-               for(i=0,iter=selected_ducks.begin();iter!=selected_ducks.end();++iter,i++)
-               {
-                       if((*iter)->get_type()!=Duck::TYPE_VERTEX&&(*iter)->get_type()!=Duck::TYPE_POSITION)continue;
-
-                       Vector x(positions[i]-center),p;
-
-                       p[0]=cosine*x[0]+sine*x[1];
-                       p[1]=-sine*x[0]+cosine*x[1];
-                       if(scale)p*=mag;
-                       p+=center;
-                       (*iter)->set_trans_point(p, time);
-               }
-               for(i=0,iter=selected_ducks.begin();iter!=selected_ducks.end();++iter,i++)
-               {
-                       if(!((*iter)->get_type()!=Duck::TYPE_VERTEX&&(*iter)->get_type()!=Duck::TYPE_POSITION))continue;
-
-                       Vector x(positions[i]-center),p;
-
-                       p[0]=cosine*x[0]+sine*x[1];
-                       p[1]=-sine*x[0]+cosine*x[1];
-                       if(scale)p*=mag;
-                       p+=center;
-                       (*iter)->set_trans_point(p, time);
-               }
-       } else if (scale)
-       {
-               if(!constrain)
-               {
-                       if(abs(drag_offset[0]-center[0])>EPSILON)
-                               vect[0]/=drag_offset[0]-center[0];
-                       else
-                               vect[0]=1;
-                       if(abs(drag_offset[1]-center[1])>EPSILON)
-                               vect[1]/=drag_offset[1]-center[1];
-                       else
-                               vect[1]=1;
-                       }
-               else
-               {
-                       //vect[0]=vect[1]=vect.mag()*0.707106781;
-                       Real amount(vect.mag()/(drag_offset-center).mag());
-                       vect[0]=vect[1]=amount;
-               }
-
-               if(vect[0]<EPSILON && vect[0]>-EPSILON)
-                       vect[0]=1;
-               if(vect[1]<EPSILON && vect[1]>-EPSILON)
-                       vect[1]=1;
-
-               for(i=0,iter=selected_ducks.begin();iter!=selected_ducks.end();++iter,i++)
-               {
-                       if(((*iter)->get_type()!=Duck::TYPE_VERTEX&&(*iter)->get_type()!=Duck::TYPE_POSITION))continue;
-
-                       Vector p(positions[i]-center);
-
-                       p[0]*=vect[0];
-                       p[1]*=vect[1];
-                       p+=center;
-                       (*iter)->set_trans_point(p, time);
-               }
-               for(i=0,iter=selected_ducks.begin();iter!=selected_ducks.end();++iter,i++)
-               {
-                       if(!((*iter)->get_type()!=Duck::TYPE_VERTEX&&(*iter)->get_type()!=Duck::TYPE_POSITION))continue;
-
-                       Vector p(positions[i]-center);
-
-                       p[0]*=vect[0];
-                       p[1]*=vect[1];
-                       p+=center;
-                       (*iter)->set_trans_point(p, time);
-               }
-       }
-       last_move=vect;
-}
-
-bool
-DuckDrag_Combo::end_duck_drag(Duckmatic* duckmatic)
-{
-       if(bad_drag)return false;
-
-       //synfigapp::Action::PassiveGrouper group(get_canvas_interface()->get_instance().get(),_("Rotate Ducks"));
-
-       if((last_move-Vector(1,1)).mag()>0.0001)
-       {
-               duckmatic->signal_edited_selected_ducks();
-               return true;
-       }
-       else
-       {
-               duckmatic->signal_user_click_selected_ducks(0);
-               return false;
-       }
-}