Inkscape
Vector Graphics Editor
Loading...
Searching...
No Matches
zoom-tool.cpp
Go to the documentation of this file.
1// SPDX-License-Identifier: GPL-2.0-or-later
2/*
3 * Handy zooming tool
4 *
5 * Authors:
6 * Lauris Kaplinski <lauris@kaplinski.com>
7 * Frank Felfe <innerspace@iname.com>
8 * bulia byak <buliabyak@users.sf.net>
9 *
10 * Copyright (C) 1999-2002 Authors
11 *
12 * Released under GNU GPL v2+, read the file 'COPYING' for more information.
13 */
14
15#include "zoom-tool.h"
16
17#include "desktop.h"
18#include "rubberband.h"
19#include "selection-chemistry.h"
21
22namespace Inkscape::UI::Tools {
23
25 : ToolBase(desktop, "/tools/zoom", "zoom-in.svg")
26{
27 auto prefs = Preferences::get();
28
29 if (prefs->getBool("/tools/zoom/selcue")) {
31 }
32
33 if (prefs->getBool("/tools/zoom/gradientdrag")) {
35 }
36}
37
43
45{
46 auto prefs = Preferences::get();
47 tolerance = prefs->getIntLimited("/options/dragtolerance/value", 0, 0, 100);
48 double const zoom_inc = prefs->getDoubleLimited("/options/zoomincrement/value", M_SQRT2, 1.01, 10);
49
50 bool ret = false;
51
52 inspect_event(event,
53 [&] (ButtonPressEvent const &event) {
54 if (event.num_press != 1) {
55 return;
56 }
57
58 auto const button_w = event.pos;
59 auto const button_dt = _desktop->w2d(button_w);
60
61 if (event.button == 1) {
62 saveDragOrigin(event.pos);
63 auto rubberband = Rubberband::get(_desktop);
64 rubberband->start(_desktop, button_dt);
65 escaped = false;
66 ret = true;
67 } else if (event.button == 3) {
68 double const zoom_rel = (event.modifiers & GDK_SHIFT_MASK)
69 ? zoom_inc
70 : 1 / zoom_inc;
71 _desktop->zoom_relative(button_dt, zoom_rel);
72 ret = true;
73 }
74
80 },
81
82 [&] (MotionEvent const &event) {
83 if (!(event.modifiers & GDK_BUTTON1_MASK)) {
84 return;
85 }
86
87 if (!checkDragMoved(event.pos)) {
88 return;
89 }
90
91 auto const motion_dt = _desktop->w2d(event.pos);
92 Rubberband::get(_desktop)->move(motion_dt);
93 gobble_motion_events(GDK_BUTTON1_MASK);
94
95 ret = true;
96 },
97
98 [&] (ButtonReleaseEvent const &event) {
99 auto const button_dt = _desktop->w2d(event.pos);
100
101 if (event.button == 1) {
102 auto const b = Rubberband::get(_desktop)->getRectangle();
103
104 if (b && !within_tolerance && !(event.modifiers & GDK_SHIFT_MASK)) {
105 _desktop->set_display_area(*b, 10);
106 } else if (!escaped) {
107 double const zoom_rel = (event.modifiers & GDK_SHIFT_MASK)
108 ? 1 / zoom_inc
109 : zoom_inc;
110 _desktop->zoom_relative(button_dt, zoom_rel);
111 }
112
113 ret = true;
114 }
115
117
119
120 xyp = {};
121 escaped = false;
122 },
123
124 [&] (KeyPressEvent const &event) {
125 switch (get_latin_keyval(event)) {
126 case GDK_KEY_Escape:
127 xyp = {};
128 escaped = true;
130 // DANGER: this operation may switch tool and delete *this instance from under us!
132 }
133 else {
135 }
136 ret = true;
137 break;
138
139 case GDK_KEY_Up:
140 case GDK_KEY_Down:
141 case GDK_KEY_KP_Up:
142 case GDK_KEY_KP_Down:
143 // prevent the zoom field from activation
144 if (!mod_ctrl_only(event)) {
145 ret = true;
146 }
147 break;
148
149 case GDK_KEY_Shift_L:
150 case GDK_KEY_Shift_R:
151 set_cursor("zoom-out.svg");
152 break;
153
154 case GDK_KEY_Delete:
155 case GDK_KEY_KP_Delete:
156 case GDK_KEY_BackSpace:
157 ret = deleteSelectedDrag(mod_ctrl_only(event));
158 break;
159
160 default:
161 break;
162 }
163 },
164
165 [&] (KeyReleaseEvent const &event) {
166 switch (get_latin_keyval(event)) {
167 case GDK_KEY_Shift_L:
168 case GDK_KEY_Shift_R:
169 set_cursor("zoom-in.svg");
170 break;
171 default:
172 break;
173 }
174 },
175
176 [&] (CanvasEvent const &event) {}
177 );
178
179 return ret || ToolBase::root_handler(event);
180}
181
182} // namespace Inkscape::UI::Tools
183
184/*
185 Local Variables:
186 mode:c++
187 c-file-style:"stroustrup"
188 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
189 indent-tabs-mode:nil
190 fill-column:99
191 End:
192*/
193// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :
static Preferences * get()
Access the singleton Preferences object.
static Rubberband * get(SPDesktop *desktop)
void move(Geom::Point const &p)
Geom::OptRect getRectangle() const
bool isStarted() const
Definition rubberband.h:52
Base class for Event processors.
Definition tool-base.h:95
void ungrabCanvasEvents()
Ungrab events from the Canvas Catchall.
void set_cursor(std::string filename)
Sets the current cursor to the given filename.
void grabCanvasEvents(EventMask mask=EventType::KEY_PRESS|EventType::BUTTON_RELEASE|EventType::MOTION|EventType::BUTTON_PRESS)
Grab events from the Canvas Catchall.
bool within_tolerance
are we still within tolerance of origin
Definition tool-base.h:136
Geom::IntPoint xyp
where drag started
Definition tool-base.h:133
virtual bool root_handler(CanvasEvent const &event)
void saveDragOrigin(Geom::Point const &pos)
bool checkDragMoved(Geom::Point const &pos)
Analyse the current position and return true once it has moved farther than tolerance from the drag o...
void enableGrDrag(bool enable=true)
void enableSelectionCue(bool enable=true)
Enables/disables the ToolBase's SelCue.
bool deleteSelectedDrag(bool just_one)
Delete a selected GrDrag point.
ZoomTool(SPDesktop *desktop)
Definition zoom-tool.cpp:24
bool root_handler(CanvasEvent const &event) override
Definition zoom-tool.cpp:44
To do: update description of desktop.
Definition desktop.h:149
void set_display_area(bool log=true)
Does all the dirty work in setting the display area.
Definition desktop.cpp:448
void zoom_relative(Geom::Point const &c, double zoom, bool keep_point=true)
Zoom in or out relatively to the current zoom.
Definition desktop.cpp:557
Geom::Affine const & w2d() const
Transformation from window to desktop coordinates (zoom/rotate).
Definition desktop.h:416
Editable view implementation.
void selectNone(SPDesktop *desktop)
void gobble_motion_events(unsigned mask)
Definition tool-base.h:232
unsigned get_latin_keyval(GtkEventControllerKey const *const controller, unsigned const keyval, unsigned const keycode, GdkModifierType const state, unsigned *consumed_modifiers)
Return the keyval corresponding to the event controller key in Latin group.
void inspect_event(E &&event, Fs... funcs)
Perform pattern-matching on a CanvasEvent.
bool mod_ctrl_only(unsigned modifiers)
A mouse button (left/right/middle) is pressed.
A mouse button (left/right/middle) is released.
Abstract base class for events.
unsigned modifiers
The modifiers mask immediately before the event.
A key has been pressed.
A key has been released.
Movement of the mouse pointer.
SPDesktop * desktop