1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
|
/** \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 "display/sodipodi-ctrl.h"
#include "knot.h"
#include "preferences.h"
namespace Inkscape {
namespace Display {
SnapIndicator::SnapIndicator(SPDesktop * desktop)
: _snaptarget(NULL),
_snapsource(NULL),
_desktop(desktop)
{
}
SnapIndicator::~SnapIndicator()
{
// remove item that might be present
remove_snaptarget();
remove_snapsource();
}
void
SnapIndicator::set_new_snaptarget(Inkscape::SnappedPoint const p)
{
remove_snaptarget();
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
}
*/
Inkscape::Preferences *prefs = Inkscape::Preferences::get();
bool value = prefs->getBool("/options/snapindicator/value", true);
if (value) {
// 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());
remove_snapsource(); // Don't set both the source and target indicators, as these will overlap
_snaptarget = _desktop->add_temporary_canvasitem(canvasitem, 1000); // TODO add preference for snap indicator timeout
}
}
void
SnapIndicator::remove_snaptarget()
{
if (_snaptarget) {
_desktop->remove_temporary_canvasitem(_snaptarget);
_snaptarget = NULL;
}
}
void
SnapIndicator::set_new_snapsource(Geom::Point const p)
{
remove_snapsource();
g_assert(_desktop != NULL);
Inkscape::Preferences *prefs = Inkscape::Preferences::get();
bool value = prefs->getBool("/options/snapindicator/value", true);
if (value) {
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_DIAMOND,
NULL );
SP_CTRL(canvasitem)->moveto(p);
_snapsource = _desktop->add_temporary_canvasitem(canvasitem, 1000);
}
}
void
SnapIndicator::remove_snapsource()
{
if (_snapsource) {
_desktop->remove_temporary_canvasitem(_snapsource);
_snapsource = 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 :
|