1 /** \file
2 * Provides a class that shows a temporary indicator on the canvas of where the snap was, and what kind of snap
3 *
4 * Authors:
5 * Johan Engelen
6 * Diederik van Lierop
7 *
8 * Copyright (C) Johan Engelen 2008 <j.b.c.engelen@utwente.nl>
9 * Copyright (C) Diederik van Lierop 2008 <mail@diedenrezi.nl>
10 *
11 * Released under GNU GPL, read the file 'COPYING' for more information
12 */
14 #include "display/snap-indicator.h"
16 #include "desktop.h"
17 #include "desktop-handles.h"
18 #include "display/sodipodi-ctrl.h"
19 #include "knot.h"
20 #include "preferences.h"
22 namespace Inkscape {
23 namespace Display {
25 SnapIndicator::SnapIndicator(SPDesktop * desktop)
26 : _tempitem(NULL),
27 _desktop(desktop)
28 {
29 }
31 SnapIndicator::~SnapIndicator()
32 {
33 // remove item that might be present
34 remove_snappoint();
35 }
37 void
38 SnapIndicator::set_new_snappoint(Inkscape::SnappedPoint const p)
39 {
40 remove_snappoint();
42 g_assert(_desktop != NULL);
44 /* Commented out for now, because this might hide any snapping bug!
45 if (!p.getSnapped()) {
46 return; // If we haven't snapped, then it is of no use to draw a snapindicator
47 }
48 */
50 Inkscape::Preferences *prefs = Inkscape::Preferences::get();
51 bool value = prefs->getBool("/options/snapindicator/value", true);
53 if (value) {
54 // TODO add many different kinds of snap indicator :-)
55 // For this we should use p->getTarget() to find out what has snapped
56 // and adjust the shape of the snapindicator accordingly, e.g. a cross
57 // when snapping to an intersection, a circle when snapping to a node, etc.
58 SPCanvasItem * canvasitem = sp_canvas_item_new( sp_desktop_tempgroup (_desktop),
59 SP_TYPE_CTRL,
60 "anchor", GTK_ANCHOR_CENTER,
61 "size", 10.0,
62 "stroked", TRUE,
63 "stroke_color", 0xf000f0ff,
64 "mode", SP_KNOT_MODE_XOR,
65 "shape", SP_KNOT_SHAPE_CROSS,
66 NULL );
68 SP_CTRL(canvasitem)->moveto(p.getPoint());
69 _tempitem = _desktop->add_temporary_canvasitem(canvasitem, 1000); // TODO add preference for snap indicator timeout
70 }
71 }
73 void
74 SnapIndicator::remove_snappoint()
75 {
76 if (_tempitem) {
77 _desktop->remove_temporary_canvasitem(_tempitem);
78 _tempitem = NULL;
79 }
80 }
83 } //namespace Display
84 } /* namespace Inkscape */
86 /*
87 Local Variables:
88 mode:c++
89 c-file-style:"stroustrup"
90 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
91 indent-tabs-mode:nil
92 fill-column:99
93 End:
94 */
95 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :