Code

Adding axis detection to new input dialog
[inkscape.git] / src / desktop-events.cpp
index 1144f0844a98973cde34eb5d6934e9847c9cc502..dc153e31d94826c6f3814b8e763745365e76cb24 100644 (file)
@@ -17,6 +17,7 @@
 #include <map>
 #include <string>
 #include "display/guideline.h"
+#include "display/snap-indicator.h"
 #include "helper/unit-menu.h"
 #include "helper/units.h"
 #include "desktop.h"
@@ -37,7 +38,7 @@
 #include "display/canvas-axonomgrid.h"
 #include "prefs-utils.h"
 #include "helper/action.h"
-#include "verbs.h"
+#include "tools-switch.h"
 #include <2geom/point.h>
 
 static void snoop_extended(GdkEvent* event, SPDesktop *desktop);
@@ -49,8 +50,10 @@ int sp_desktop_root_handler(SPCanvasItem */*item*/, GdkEvent *event, SPDesktop *
 {
     static bool watch = false;
     static bool first = true;
+
     if ( first ) {
-        if ( prefs_get_int_attribute("options.useextinput", "value", 1) ) {
+        if ( prefs_get_int_attribute("options.useextinput", "value", 1)
+            && prefs_get_int_attribute("options.switchonextinput", "value", 0) ) {
             watch = true;
             init_extended();
         }
@@ -140,11 +143,18 @@ static gint sp_dt_ruler_event(GtkWidget *widget, GdkEvent *event, SPDesktopWidge
                 NR::Point event_dt(desktop->w2d(event_w));
                 
                 SnapManager const &m = desktop->namedview->snap_manager;
-                event_dt = m.guideSnap(event_dt, normal).getPoint();
-                
+                Inkscape::SnappedPoint snappoint = m.guideSnap(event_dt, normal);
+                event_dt = snappoint.getPoint();
+
                 sp_guideline_set_position(SP_GUIDELINE(guide), event_dt.to_2geom());
                 desktop->set_coordinate_status(event_dt);
                 desktop->setPosition (event_dt);
+
+                if (snappoint.getDistance() < NR_HUGE) {
+                    desktop->snapindicator->set_new_snappoint(snappoint.getPoint().to_2geom());
+                } else {
+                    desktop->snapindicator->remove_snappoint();
+                }
             }
             break;
     case GDK_BUTTON_RELEASE:
@@ -236,12 +246,20 @@ gint sp_dt_guide_event(SPCanvasItem *item, GdkEvent *event, gpointer data)
                 // This is for snapping while dragging existing guidelines. New guidelines, 
                 // which are dragged off the ruler, are being snapped in sp_dt_ruler_event
                 SnapManager const &m = desktop->namedview->snap_manager;
-                motion_dt = m.guideSnap(motion_dt, guide->normal_to_line).getPoint();
-                
+                Inkscape::SnappedPoint snappoint = m.guideSnap(motion_dt, guide->normal_to_line);
+                motion_dt = snappoint.getPoint();
+
                 sp_guide_moveto(*guide, motion_dt.to_2geom(), false);
                 moved = true;
                 desktop->set_coordinate_status(motion_dt);
                 desktop->setPosition (motion_dt);
+
+                if (snappoint.getDistance() < NR_HUGE) {
+                    desktop->snapindicator->set_new_snappoint(snappoint.getPoint().to_2geom());
+                } else {
+                    desktop->snapindicator->remove_snappoint();
+                }
+
                 ret = TRUE;
             }
             break;
@@ -308,24 +326,24 @@ static void init_extended()
             GdkDevice* dev = reinterpret_cast<GdkDevice*>(curr->data);
             if ( dev->name
                  && (avoidName != dev->name)
-                 && switchMap.find(dev->source) == switchMap.end() ) {
+                 && (switchMap.find(dev->source) == switchMap.end())
+                 && (dev->source != GDK_SOURCE_MOUSE) ) {
                 switchMap[dev->source] = dev->name;
-//                 g_message("Adding '%s' as [%s]", dev->name, namefor(dev->source));
+//                 g_message("Adding '%s' as [%d]", dev->name, dev->source);
 
                 // Set the initial tool for the device
                 switch ( dev->source ) {
-                    case GDK_SOURCE_MOUSE:
-                        // Don't do anything for the main mouse.
-                        break;
                     case GDK_SOURCE_PEN:
-                        toolToUse[GDK_SOURCE_PEN] = SP_VERB_CONTEXT_CALLIGRAPHIC;
+                        toolToUse[GDK_SOURCE_PEN] = TOOLS_CALLIGRAPHIC;
                         break;
                     case GDK_SOURCE_ERASER:
-                        toolToUse[GDK_SOURCE_ERASER] = SP_VERB_CONTEXT_TWEAK;
+                        toolToUse[GDK_SOURCE_ERASER] = TOOLS_TWEAK;
                         break;
                     case GDK_SOURCE_CURSOR:
-                        toolToUse[GDK_SOURCE_CURSOR] = SP_VERB_CONTEXT_SELECT;
+                        toolToUse[GDK_SOURCE_CURSOR] = TOOLS_SELECT;
                         break;
+                    default:
+                        ; // do not add
                 }
 //             } else {
 //                 g_message("Skippn '%s' as [%s]", dev->name, namefor(dev->source));
@@ -393,24 +411,18 @@ void snoop_extended(GdkEvent* event, SPDesktop *desktop)
         if ( lastName != name || lastType != source ) {
             // The device switched. See if it is one we 'count'
             std::map<GdkInputSource, std::string>::iterator it = switchMap.find(source);
-            if ( it != switchMap.end() && (name == it->second) ) {
-                lastName = name;
-                lastType = source;
-
+            if ( (it != switchMap.end()) && (name == it->second) ) {
                 std::map<GdkInputSource, int>::iterator it2 = toolToUse.find(source);
                 if (it2 != toolToUse.end() ) {
-                    Inkscape::Verb* verb = Inkscape::Verb::get(it2->second);
-                    if ( verb ) {
-                        SPAction* action = verb->get_action(desktop);
-                        if ( action ) {
-                            sp_action_perform(action, 0);
-                        }
-                    } else {
-                        g_warning("     NO VERB FOUND");
+                    // Save the tool currently selected for next time the input device shows up.
+                    if ( (switchMap.find(lastType) != switchMap.end())
+                         && (lastName == switchMap.find(lastType)->second)) {
+                        toolToUse[lastType] = tools_active(desktop);
                     }
-                } else {
-                    g_warning("     NO ID FOUND");
+                    tools_switch(desktop, it2->second);
                 }
+                lastName = name;
+                lastType = source;
             }
         }
     }