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 "sp-namedview.h"
19 #include "display/sodipodi-ctrl.h"
20 #include "knot.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 SPNamedView *nv = sp_desktop_namedview(_desktop);
52 if (nv->snapindicator) {
53 // TODO add many different kinds of snap indicator :-)
54 // For this we should use p->getTarget() to find out what has snapped
55 // and adjust the shape of the snapindicator accordingly, e.g. a cross
56 // when snapping to an intersection, a circle when snapping to a node, etc.
57 SPCanvasItem * canvasitem = sp_canvas_item_new( sp_desktop_tempgroup (_desktop),
58 SP_TYPE_CTRL,
59 "anchor", GTK_ANCHOR_CENTER,
60 "size", 10.0,
61 "stroked", TRUE,
62 "stroke_color", 0xf000f0ff,
63 "mode", SP_KNOT_MODE_XOR,
64 "shape", SP_KNOT_SHAPE_CROSS,
65 NULL );
67 SP_CTRL(canvasitem)->moveto(p.getPoint());
68 _tempitem = _desktop->add_temporary_canvasitem(canvasitem, 1000); // TODO add preference for snap indicator timeout
69 }
70 }
72 void
73 SnapIndicator::remove_snappoint()
74 {
75 if (_tempitem) {
76 _desktop->remove_temporary_canvasitem(_tempitem);
77 _tempitem = NULL;
78 }
79 }
82 } //namespace Display
83 } /* namespace Inkscape */
85 /*
86 Local Variables:
87 mode:c++
88 c-file-style:"stroustrup"
89 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
90 indent-tabs-mode:nil
91 fill-column:99
92 End:
93 */
94 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :