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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
|
// SPDX-License-Identifier: GPL-2.0-or-later
/*
* Handy zooming tool
*
* Authors:
* Lauris Kaplinski <lauris@kaplinski.com>
* Frank Felfe <innerspace@iname.com>
* bulia byak <buliabyak@users.sf.net>
*
* Copyright (C) 1999-2002 Authors
*
* Released under GNU GPL v2+, read the file 'COPYING' for more information.
*/
#include <gdk/gdkkeysyms.h>
#include "include/macros.h"
#include "rubberband.h"
#include "display/sp-canvas-item.h"
#include "display/sp-canvas-util.h"
#include "desktop.h"
#include "ui/pixmaps/cursor-zoom.xpm"
#include "ui/pixmaps/cursor-zoom-out.xpm"
#include "selection-chemistry.h"
#include "ui/tools/zoom-tool.h"
namespace Inkscape {
namespace UI {
namespace Tools {
const std::string& ZoomTool::getPrefsPath() {
return ZoomTool::prefsPath;
}
const std::string ZoomTool::prefsPath = "/tools/zoom";
ZoomTool::ZoomTool()
: ToolBase(cursor_zoom_xpm)
, grabbed(nullptr)
, escaped(false)
{
}
ZoomTool::~ZoomTool() = default;
void ZoomTool::finish() {
this->enableGrDrag(false);
if (this->grabbed) {
sp_canvas_item_ungrab(this->grabbed);
this->grabbed = nullptr;
}
ToolBase::finish();
}
void ZoomTool::setup() {
Inkscape::Preferences *prefs = Inkscape::Preferences::get();
if (prefs->getBool("/tools/zoom/selcue")) {
this->enableSelectionCue();
}
if (prefs->getBool("/tools/zoom/gradientdrag")) {
this->enableGrDrag();
}
ToolBase::setup();
}
bool ZoomTool::root_handler(GdkEvent* event) {
Inkscape::Preferences *prefs = Inkscape::Preferences::get();
tolerance = prefs->getIntLimited("/options/dragtolerance/value", 0, 0, 100);
double const zoom_inc = prefs->getDoubleLimited("/options/zoomincrement/value", M_SQRT2, 1.01, 10);
bool ret = false;
switch (event->type) {
case GDK_BUTTON_PRESS:
{
Geom::Point const button_w(event->button.x, event->button.y);
Geom::Point const button_dt(desktop->w2d(button_w));
if (event->button.button == 1 && !this->space_panning) {
// save drag origin
xp = (gint) event->button.x;
yp = (gint) event->button.y;
within_tolerance = true;
Inkscape::Rubberband::get(desktop)->start(desktop, button_dt);
escaped = false;
ret = true;
} else if (event->button.button == 3) {
double const zoom_rel( (event->button.state & GDK_SHIFT_MASK)
? zoom_inc
: 1 / zoom_inc );
desktop->zoom_relative_keep_point(button_dt, zoom_rel);
ret = true;
}
sp_canvas_item_grab(SP_CANVAS_ITEM(desktop->acetate),
GDK_KEY_PRESS_MASK | GDK_KEY_RELEASE_MASK |
GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK |
GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK,
nullptr, event->button.time);
this->grabbed = SP_CANVAS_ITEM(desktop->acetate);
break;
}
case GDK_MOTION_NOTIFY:
if ((event->motion.state & GDK_BUTTON1_MASK) && !this->space_panning) {
ret = true;
if ( within_tolerance
&& ( abs( (gint) event->motion.x - xp ) < tolerance )
&& ( abs( (gint) event->motion.y - yp ) < tolerance ) ) {
break; // do not drag if we're within tolerance from origin
}
// Once the user has moved farther than tolerance from the original location
// (indicating they intend to move the object, not click), then always process the
// motion notify coordinates as given (no snapping back to origin)
within_tolerance = false;
Geom::Point const motion_w(event->motion.x, event->motion.y);
Geom::Point const motion_dt(desktop->w2d(motion_w));
Inkscape::Rubberband::get(desktop)->move(motion_dt);
gobble_motion_events(GDK_BUTTON1_MASK);
}
break;
case GDK_BUTTON_RELEASE:
{
Geom::Point const button_w(event->button.x, event->button.y);
Geom::Point const button_dt(desktop->w2d(button_w));
if ( event->button.button == 1 && !this->space_panning) {
Geom::OptRect const b = Inkscape::Rubberband::get(desktop)->getRectangle();
if (b && !within_tolerance && !(GDK_SHIFT_MASK & event->button.state) ) {
desktop->set_display_area(*b, 10);
} else if (!escaped) {
double const zoom_rel( (event->button.state & GDK_SHIFT_MASK)
? 1 / zoom_inc
: zoom_inc );
desktop->zoom_relative_keep_point(button_dt, zoom_rel);
}
ret = true;
}
Inkscape::Rubberband::get(desktop)->stop();
if (this->grabbed) {
sp_canvas_item_ungrab(this->grabbed);
this->grabbed = nullptr;
}
xp = yp = 0;
escaped = false;
break;
}
case GDK_KEY_PRESS:
switch (get_latin_keyval (&event->key)) {
case GDK_KEY_Escape:
if (!Inkscape::Rubberband::get(desktop)->is_started()) {
Inkscape::SelectionHelper::selectNone(desktop);
}
Inkscape::Rubberband::get(desktop)->stop();
xp = yp = 0;
escaped = true;
ret = true;
break;
case GDK_KEY_Up:
case GDK_KEY_Down:
case GDK_KEY_KP_Up:
case GDK_KEY_KP_Down:
// prevent the zoom field from activation
if (!MOD__CTRL_ONLY(event))
ret = true;
break;
case GDK_KEY_Shift_L:
case GDK_KEY_Shift_R:
this->cursor_shape = cursor_zoom_out_xpm;
this->sp_event_context_update_cursor();
break;
case GDK_KEY_Delete:
case GDK_KEY_KP_Delete:
case GDK_KEY_BackSpace:
ret = this->deleteSelectedDrag(MOD__CTRL_ONLY(event));
break;
default:
break;
}
break;
case GDK_KEY_RELEASE:
switch (get_latin_keyval (&event->key)) {
case GDK_KEY_Shift_L:
case GDK_KEY_Shift_R:
this->cursor_shape = cursor_zoom_xpm;
this->sp_event_context_update_cursor();
break;
default:
break;
}
break;
default:
break;
}
if (!ret) {
ret = ToolBase::root_handler(event);
}
return ret;
}
}
}
}
/*
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 :
|