Code

work a bit on snapindicator: added switch statement for different types
authorjohanengelen <johanengelen@users.sourceforge.net>
Fri, 16 Jan 2009 22:06:40 +0000 (22:06 +0000)
committerjohanengelen <johanengelen@users.sourceforge.net>
Fri, 16 Jan 2009 22:06:40 +0000 (22:06 +0000)
src/display/snap-indicator.cpp
src/snapped-point.h

index e48f48cedb77823530a3cc241295ba0509a76f63..d642816afebf4e183a7e4626e4e4ed8a786cdff4 100644 (file)
@@ -51,22 +51,36 @@ SnapIndicator::set_new_snaptarget(Inkscape::SnappedPoint const p)
     
     Inkscape::Preferences *prefs = Inkscape::Preferences::get();
     bool value = prefs->getBool("/options/snapindicator/value", true);
-       
+
     if (value) {
-        // TODO add many different kinds of snap indicator :-)
-        // For this we should use p->getTarget() to find out what has snapped 
-        // and adjust the shape of the snapindicator accordingly, e.g. a cross
-        // when snapping to an intersection, a circle when snapping to a node, etc. 
-        SPCanvasItem * canvasitem = sp_canvas_item_new( sp_desktop_tempgroup (_desktop),
-                                                        SP_TYPE_CTRL,
-                                                        "anchor", GTK_ANCHOR_CENTER,
-                                                        "size", 10.0,
-                                                        "stroked", TRUE,
-                                                        "stroke_color", 0xf000f0ff,
-                                                        "mode", SP_KNOT_MODE_XOR,
-                                                        "shape", SP_KNOT_SHAPE_CROSS,
-                                                        NULL );        
-        
+        SPCanvasItem * canvasitem = NULL;
+        switch (p.getTarget()) {
+            /// @todo  add the different kinds of snapindicator visuals
+            case SNAPTARGET_GRID:
+            case SNAPTARGET_GRID_INTERSECTION:
+            case SNAPTARGET_GUIDE:
+            case SNAPTARGET_GUIDE_INTERSECTION:
+            case SNAPTARGET_GRID_GUIDE_INTERSECTION:
+            case SNAPTARGET_NODE:
+            case SNAPTARGET_PATH:
+            case SNAPTARGET_PATH_INTERSECTION:
+            case SNAPTARGET_BBOX_CORNER:
+            case SNAPTARGET_BBOX_EDGE:
+            case SNAPTARGET_GRADIENT:
+            case SNAPTARGET_UNDEFINED:
+            default:
+                canvasitem = sp_canvas_item_new(sp_desktop_tempgroup (_desktop),
+                                                SP_TYPE_CTRL,
+                                                "anchor", GTK_ANCHOR_CENTER,
+                                                "size", 10.0,
+                                                "stroked", TRUE,
+                                                "stroke_color", 0xf000f0ff,
+                                                "mode", SP_KNOT_MODE_XOR,
+                                                "shape", SP_KNOT_SHAPE_CROSS,
+                                                NULL );
+                break;
+        }
+
         SP_CTRL(canvasitem)->moveto(p.getPoint());
         remove_snapsource(); // Don't set both the source and target indicators, as these will overlap
         _snaptarget = _desktop->add_temporary_canvasitem(canvasitem, 1000); // TODO add preference for snap indicator timeout
index dbd672bdfd1018276875fc6dd097d01d9b6dfb94..254d573df895a708ab59436eeff8996ee2fb647c 100644 (file)
@@ -77,7 +77,7 @@ public:
     Geom::Point getTransformation() const {return _transformation;}
     void setTransformation(Geom::Point const t) {_transformation = t;}
     void setTarget(SnapTargetType const target) {_target = target;}
-    SnapTargetType getTarget() {return _target;}
+    SnapTargetType getTarget() const {return _target;}
 
     bool isOtherSnapBetter(SnappedPoint const &other_one, bool weighted) const;