Code

Refactor snapper and snapindicator (in order to enable the snapindicator in the selec...
[inkscape.git] / src / display / snap-indicator.cpp
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  *
7  * Copyright (C) Johan Engelen 2008 <j.b.c.engelen@utwente.nl>
8  *
9  * Released under GNU GPL, read the file 'COPYING' for more information
10  */
12 #include "display/snap-indicator.h"
14 #include "desktop.h"
15 #include "desktop-handles.h"
16 #include "display/sodipodi-ctrl.h"
17 #include "knot.h"
19 namespace Inkscape {
20 namespace Display {
22 SnapIndicator::SnapIndicator(SPDesktop * desktop)
23     :   tempitem(NULL),
24         desktop(desktop)
25 {
26 }
28 SnapIndicator::~SnapIndicator()
29 {
30     // remove item that might be present
31     remove_snappoint();
32 }
34 void
35 SnapIndicator::set_new_snappoint(Inkscape::SnappedPoint const p)
36 {
37     remove_snappoint();
39     bool enabled = true;  // TODO add preference for snap indicator.
40     if (enabled) {
41         // TODO add many different kinds of snap indicator :-)
42         SPCanvasItem * canvasitem = sp_canvas_item_new( sp_desktop_tempgroup (desktop),
43                                                         SP_TYPE_CTRL,
44                                                         "anchor", GTK_ANCHOR_CENTER,
45                                                         "size", 10.0,
46                                                         "stroked", TRUE,
47                                                         "stroke_color", 0xf000f0ff,
48                                                         "mode", SP_KNOT_MODE_XOR,
49                                                         "shape", SP_KNOT_SHAPE_CROSS,
50                                                         NULL );
51         
52         
53         SP_CTRL(canvasitem)->moveto(p.getPoint());
54         tempitem = desktop->add_temporary_canvasitem(canvasitem, 1000); // TODO add preference for snap indicator timeout
55     }
56 }
58 void
59 SnapIndicator::remove_snappoint()
60 {
61     if (tempitem) {
62         desktop->remove_temporary_canvasitem(tempitem);
63         tempitem = NULL;
64     }
65 }
68 } //namespace Display
69 } /* namespace Inkscape */
71 /*
72   Local Variables:
73   mode:c++
74   c-file-style:"stroustrup"
75   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
76   indent-tabs-mode:nil
77   fill-column:99
78   End:
79 */
80 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :