2
* Provides a class that shows a temporary indicator on the canvas of where the snap was, and what kind of snap
8
* Copyright (C) Johan Engelen 2009 <j.b.c.engelen@utwente.nl>
9
* Copyright (C) Diederik van Lierop 2009 <mail@diedenrezi.nl>
11
* Released under GNU GPL, read the file 'COPYING' for more information
14
#include "display/snap-indicator.h"
17
#include "desktop-handles.h"
18
#include "display/sodipodi-ctrl.h"
19
#include "display/canvas-text.h"
21
#include "preferences.h"
22
#include <glibmm/i18n.h>
27
SnapIndicator::SnapIndicator(SPDesktop * desktop)
29
_snaptarget_tooltip(NULL),
35
SnapIndicator::~SnapIndicator()
37
// remove item that might be present
43
SnapIndicator::set_new_snaptarget(Inkscape::SnappedPoint const p)
45
remove_snaptarget(); //only display one snaptarget at a time
47
g_assert(_desktop != NULL);
49
/* Commented out for now, because this might hide any snapping bug!
50
if (!p.getSnapped()) {
51
return; // If we haven't snapped, then it is of no use to draw a snapindicator
55
Inkscape::Preferences *prefs = Inkscape::Preferences::get();
56
bool value = prefs->getBool("/options/snapindicator/value", true);
59
// TRANSLATORS: undefined target for snapping
60
gchar *target_name = _("UNDEFINED");
61
switch (p.getTarget()) {
62
case SNAPTARGET_UNDEFINED:
63
target_name = _("UNDEFINED");
66
target_name = _("grid line");
68
case SNAPTARGET_GRID_INTERSECTION:
69
target_name = _("grid intersection");
71
case SNAPTARGET_GUIDE:
72
target_name = _("guide");
74
case SNAPTARGET_GUIDE_INTERSECTION:
75
target_name = _("guide intersection");
77
case SNAPTARGET_GRID_GUIDE_INTERSECTION:
78
target_name = _("grid-guide intersection");
80
case SNAPTARGET_NODE_CUSP:
81
target_name = _("cusp node");
83
case SNAPTARGET_NODE_SMOOTH:
84
target_name = _("smooth node");
87
target_name = _("path");
89
case SNAPTARGET_PATH_INTERSECTION:
90
target_name = _("path intersection");
92
case SNAPTARGET_BBOX_CORNER:
93
target_name = _("bounding box corner");
95
case SNAPTARGET_BBOX_EDGE:
96
target_name = _("bounding box side");
98
case SNAPTARGET_GRADIENTS_PARENT_BBOX:
99
target_name = _("bounding box");
101
case SNAPTARGET_PAGE_BORDER:
102
target_name = _("page border");
104
case SNAPTARGET_LINE_MIDPOINT:
105
target_name = _("line midpoint");
107
case SNAPTARGET_OBJECT_MIDPOINT:
108
target_name = _("object midpoint");
110
case SNAPTARGET_ROTATION_CENTER:
111
target_name = _("object rotation center");
113
case SNAPTARGET_HANDLE:
114
target_name = _("handle");
116
case SNAPTARGET_BBOX_EDGE_MIDPOINT:
117
target_name = _("bounding box side midpoint");
119
case SNAPTARGET_BBOX_MIDPOINT:
120
target_name = _("bounding box midpoint");
122
case SNAPTARGET_PAGE_CORNER:
123
target_name = _("page corner");
125
case SNAPTARGET_CONVEX_HULL_CORNER:
126
target_name = _("convex hull corner");
128
case SNAPTARGET_ELLIPSE_QUADRANT_POINT:
129
target_name = _("quadrant point");
131
case SNAPTARGET_CENTER:
132
target_name = _("center");
134
case SNAPTARGET_CORNER:
135
target_name = _("corner");
137
case SNAPTARGET_TEXT_BASELINE:
138
target_name = _("text baseline");
141
g_warning("Snap target has not yet been defined!");
145
gchar *source_name = _("UNDEFINED");
146
switch (p.getSource()) {
147
case SNAPSOURCE_UNDEFINED:
148
source_name = _("UNDEFINED");
150
case SNAPSOURCE_BBOX_CORNER:
151
source_name = _("Bounding box corner");
153
case SNAPSOURCE_BBOX_MIDPOINT:
154
source_name = _("Bounding box midpoint");
156
case SNAPSOURCE_BBOX_EDGE_MIDPOINT:
157
source_name = _("Bounding box side midpoint");
159
case SNAPSOURCE_NODE_SMOOTH:
160
source_name = _("Smooth node");
162
case SNAPSOURCE_NODE_CUSP:
163
source_name = _("Cusp node");
165
case SNAPSOURCE_LINE_MIDPOINT:
166
source_name = _("Line midpoint");
168
case SNAPSOURCE_OBJECT_MIDPOINT:
169
source_name = _("Object midpoint");
171
case SNAPSOURCE_ROTATION_CENTER:
172
source_name = _("Object rotation center");
174
case SNAPSOURCE_HANDLE:
175
source_name = _("Handle");
177
case SNAPSOURCE_PATH_INTERSECTION:
178
source_name = _("Path intersection");
180
case SNAPSOURCE_GUIDE:
181
source_name = _("Guide");
183
case SNAPSOURCE_GUIDE_ORIGIN:
184
source_name = _("Guide origin");
186
case SNAPSOURCE_CONVEX_HULL_CORNER:
187
source_name = _("Convex hull corner");
189
case SNAPSOURCE_ELLIPSE_QUADRANT_POINT:
190
source_name = _("Quadrant point");
192
case SNAPSOURCE_CENTER:
193
source_name = _("Center");
195
case SNAPSOURCE_CORNER:
196
source_name = _("Corner");
198
case SNAPSOURCE_TEXT_BASELINE:
199
source_name = _("Text baseline");
202
g_warning("Snap source has not yet been defined!");
205
//std::cout << "Snapped " << source_name << " to " << target_name << std::endl;
207
remove_snapsource(); // Don't set both the source and target indicators, as these will overlap
209
// Display the snap indicator (i.e. the cross)
210
SPCanvasItem * canvasitem = NULL;
211
if (p.getTarget() == SNAPTARGET_NODE_SMOOTH || p.getTarget() == SNAPTARGET_NODE_CUSP) {
212
canvasitem = sp_canvas_item_new(sp_desktop_tempgroup (_desktop),
214
"anchor", GTK_ANCHOR_CENTER,
217
"stroke_color", 0xf000f0ff,
218
"mode", SP_KNOT_MODE_XOR,
219
"shape", SP_KNOT_SHAPE_DIAMOND,
222
canvasitem = sp_canvas_item_new(sp_desktop_tempgroup (_desktop),
224
"anchor", GTK_ANCHOR_CENTER,
227
"stroke_color", 0xf000f0ff,
228
"mode", SP_KNOT_MODE_XOR,
229
"shape", SP_KNOT_SHAPE_CROSS,
233
const int timeout_val = 1200; // TODO add preference for snap indicator timeout?
235
SP_CTRL(canvasitem)->moveto(p.getPoint());
236
_snaptarget = _desktop->add_temporary_canvasitem(canvasitem, timeout_val);
238
gchar *tooltip_str = g_strconcat(source_name, _(" to "), target_name, NULL);
239
Geom::Point tooltip_pos = p.getPoint() + _desktop->w2d(Geom::Point(15, -15));
241
SPCanvasItem *canvas_tooltip = sp_canvastext_new(sp_desktop_tempgroup(_desktop), _desktop, tooltip_pos, tooltip_str);
244
sp_canvastext_set_anchor((SPCanvasText* )canvas_tooltip, -1, 1);
245
_snaptarget_tooltip = _desktop->add_temporary_canvasitem(canvas_tooltip, timeout_val);
250
SnapIndicator::remove_snaptarget()
253
_desktop->remove_temporary_canvasitem(_snaptarget);
257
if (_snaptarget_tooltip) {
258
_desktop->remove_temporary_canvasitem(_snaptarget_tooltip);
259
_snaptarget_tooltip = NULL;
265
SnapIndicator::set_new_snapsource(std::pair<Geom::Point, int> const p)
269
g_assert(_desktop != NULL);
271
Inkscape::Preferences *prefs = Inkscape::Preferences::get();
272
bool value = prefs->getBool("/options/snapindicator/value", true);
275
SPCanvasItem * canvasitem = sp_canvas_item_new( sp_desktop_tempgroup (_desktop),
277
"anchor", GTK_ANCHOR_CENTER,
280
"stroke_color", 0xf000f0ff,
281
"mode", SP_KNOT_MODE_XOR,
282
"shape", SP_KNOT_SHAPE_CIRCLE,
285
SP_CTRL(canvasitem)->moveto(p.first);
286
_snapsource = _desktop->add_temporary_canvasitem(canvasitem, 1000);
291
SnapIndicator::remove_snapsource()
294
_desktop->remove_temporary_canvasitem(_snapsource);
299
} //namespace Display
300
} /* namespace Inkscape */
306
c-file-style:"stroustrup"
307
c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
312
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 :