Code

Fixed icon loading, cacheing and fallback to use stock mechanisms.
[inkscape.git] / src / display / snap-indicator.cpp
index 03fcad484027eab5b54da16e0376ace969282b39..59578123e12e4d9e754c1897a9cf422d21a11634 100644 (file)
@@ -3,8 +3,10 @@
  *
  * Authors:
  *   Johan Engelen
+ *   Diederik van Lierop
  *
  * Copyright (C) Johan Engelen 2008 <j.b.c.engelen@utwente.nl>
+ * Copyright (C) Diederik van Lierop 2008 <mail@diedenrezi.nl>
  *
  * Released under GNU GPL, read the file 'COPYING' for more information
  */
@@ -13,6 +15,7 @@
 
 #include "desktop.h"
 #include "desktop-handles.h"
+#include "sp-namedview.h"
 #include "display/sodipodi-ctrl.h"
 #include "knot.h"
 
@@ -20,8 +23,8 @@ namespace Inkscape {
 namespace Display {
 
 SnapIndicator::SnapIndicator(SPDesktop * desktop)
-    :   tempitem(NULL),
-        desktop(desktop)
+    :   _tempitem(NULL),
+        _desktop(desktop)
 {
 }
 
@@ -35,11 +38,23 @@ void
 SnapIndicator::set_new_snappoint(Inkscape::SnappedPoint const p)
 {
     remove_snappoint();
-
-    bool enabled = true;  // TODO add preference for snap indicator.
-    if (enabled) {
+    
+    g_assert(_desktop != NULL);
+    
+    /* Commented out for now, because this might hide any snapping bug!
+    if (!p.getSnapped()) {
+       return; // If we haven't snapped, then it is of no use to draw a snapindicator
+    }
+    */
+    
+    SPNamedView *nv = sp_desktop_namedview(_desktop);
+    
+    if (nv->snapindicator) {
         // TODO add many different kinds of snap indicator :-)
-        SPCanvasItem * canvasitem = sp_canvas_item_new( sp_desktop_tempgroup (desktop),
+        // 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,
@@ -47,20 +62,19 @@ SnapIndicator::set_new_snappoint(Inkscape::SnappedPoint const p)
                                                         "stroke_color", 0xf000f0ff,
                                                         "mode", SP_KNOT_MODE_XOR,
                                                         "shape", SP_KNOT_SHAPE_CROSS,
-                                                        NULL );
-        
+                                                        NULL );        
         
         SP_CTRL(canvasitem)->moveto(p.getPoint());
-        tempitem = desktop->add_temporary_canvasitem(canvasitem, 1000); // TODO add preference for snap indicator timeout
+        _tempitem = _desktop->add_temporary_canvasitem(canvasitem, 1000); // TODO add preference for snap indicator timeout
     }
 }
 
 void
 SnapIndicator::remove_snappoint()
 {
-    if (tempitem) {
-        desktop->remove_temporary_canvasitem(tempitem);
-        tempitem = NULL;
+    if (_tempitem) {
+        _desktop->remove_temporary_canvasitem(_tempitem);
+        _tempitem = NULL;
     }
 }