index 1d005ceb896c39ede19735266ef72d792536d07b..59578123e12e4d9e754c1897a9cf422d21a11634 100644 (file)
-/** \file\r
- * Provides a class that shows a temporary indicator on the canvas of where the snap was, and what kind of snap\r
- *\r
- * Authors:\r
- * Johan Engelen\r
- *\r
- * Copyright (C) Johan Engelen 2008 <j.b.c.engelen@utwente.nl>\r
- *\r
- * Released under GNU GPL, read the file 'COPYING' for more information\r
- */\r
-\r
-#include "display/snap-indicator.h"\r
-\r
-#include "desktop.h"\r
-#include "desktop-handles.h"\r
-#include "display/sodipodi-ctrl.h"\r
-#include "knot.h"\r
-\r
-namespace Inkscape {\r
-namespace Display {\r
-\r
-/** lifetime is measured in milliseconds\r
- */\r
-SnapIndicator::SnapIndicator(SPDesktop * desktop)\r
- : tempitem(NULL),\r
- desktop(desktop)\r
-{\r
-}\r
-\r
-SnapIndicator::~SnapIndicator()\r
-{\r
- // remove item that might be present\r
- remove_snappoint();\r
-}\r
-\r
-void\r
-SnapIndicator::set_new_snappoint(Geom::Point p)\r
-{\r
- remove_snappoint();\r
-\r
- SPCanvasItem * canvasitem = sp_canvas_item_new( sp_desktop_tempgroup (desktop),\r
- SP_TYPE_CTRL,\r
- "anchor", GTK_ANCHOR_CENTER,\r
- "size", 6.0,\r
- "stroked", TRUE,\r
- "stroke_color", 0xf000f0ff,\r
- "mode", SP_KNOT_MODE_XOR,\r
- "shape", SP_KNOT_SHAPE_CROSS,\r
- NULL );\r
- SP_CTRL(canvasitem)->moveto ( p );\r
- tempitem = desktop->add_temporary_canvasitem(canvasitem, 2000);\r
-}\r
-\r
-void\r
-SnapIndicator::remove_snappoint()\r
-{\r
- if (tempitem) {\r
- desktop->remove_temporary_canvasitem(tempitem);\r
- tempitem = NULL;\r
- }\r
-}\r
-\r
-\r
-} //namespace Display\r
-} /* namespace Inkscape */\r
-\r
-/*\r
- Local Variables:\r
- mode:c++\r
- c-file-style:"stroustrup"\r
- c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))\r
- indent-tabs-mode:nil\r
- fill-column:99\r
- End:\r
-*/\r
-// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :\r
+/** \file
+ * Provides a class that shows a temporary indicator on the canvas of where the snap was, and what kind of snap
+ *
+ * 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
+ */
+
+#include "display/snap-indicator.h"
+
+#include "desktop.h"
+#include "desktop-handles.h"
+#include "sp-namedview.h"
+#include "display/sodipodi-ctrl.h"
+#include "knot.h"
+
+namespace Inkscape {
+namespace Display {
+
+SnapIndicator::SnapIndicator(SPDesktop * desktop)
+ : _tempitem(NULL),
+ _desktop(desktop)
+{
+}
+
+SnapIndicator::~SnapIndicator()
+{
+ // remove item that might be present
+ remove_snappoint();
+}
+
+void
+SnapIndicator::set_new_snappoint(Inkscape::SnappedPoint const p)
+{
+ remove_snappoint();
+
+ 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 :-)
+ // 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 );
+
+ SP_CTRL(canvasitem)->moveto(p.getPoint());
+ _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;
+ }
+}
+
+
+} //namespace Display
+} /* namespace Inkscape */
+
+/*
+ Local Variables:
+ mode:c++
+ c-file-style:"stroustrup"
+ c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
+ indent-tabs-mode:nil
+ fill-column:99
+ End:
+*/
+// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :