blob: 37961e39e22a32eab3339da6fa4bff5b90ea5d1d (
plain)
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
|
// SPDX-License-Identifier: GPL-2.0-or-later
/** @file
* Collection of shorthands to deal with GDK events.
*/
/* Authors:
* Krzysztof Kosiński <tweenk.pl@gmail.com>
*
* Copyright (C) 2009 Authors
* Released under GNU GPL v2+, read the file 'COPYING' for more information.
*/
#ifndef SEEN_UI_TOOL_EVENT_UTILS_H
#define SEEN_UI_TOOL_EVENT_UTILS_H
#include <gdk/gdk.h>
#include <2geom/point.h>
namespace Inkscape {
namespace UI {
inline bool state_held_shift(unsigned state) {
return state & GDK_SHIFT_MASK;
}
inline bool state_held_control(unsigned state) {
return state & GDK_CONTROL_MASK;
}
inline bool state_held_alt(unsigned state) {
return state & GDK_MOD1_MASK;
}
inline bool state_held_only_shift(unsigned state) {
return (state & GDK_SHIFT_MASK) && !(state & (GDK_CONTROL_MASK | GDK_MOD1_MASK));
}
inline bool state_held_only_control(unsigned state) {
return (state & GDK_CONTROL_MASK) && !(state & (GDK_SHIFT_MASK | GDK_MOD1_MASK));
}
inline bool state_held_only_alt(unsigned state) {
return (state & GDK_MOD1_MASK) && !(state & (GDK_SHIFT_MASK | GDK_CONTROL_MASK));
}
inline bool state_held_any_modifiers(unsigned state) {
return state & (GDK_SHIFT_MASK | GDK_CONTROL_MASK | GDK_MOD1_MASK);
}
inline bool state_held_no_modifiers(unsigned state) {
return !state_held_any_modifiers(state);
}
template <unsigned button>
inline bool state_held_button(unsigned state) {
return (button == 0 || button > 5) ? false : state & (GDK_BUTTON1_MASK << (button-1));
}
/** Checks whether Shift was held when the event was generated. */
template <typename E>
inline bool held_shift(E const &event) {
return state_held_shift(event.state);
}
/** Checks whether Control was held when the event was generated. */
template <typename E>
inline bool held_control(E const &event) {
return state_held_control(event.state);
}
/** Checks whether Alt was held when the event was generated. */
template <typename E>
inline bool held_alt(E const &event) {
return state_held_alt(event.state);
}
/** True if from the set of Ctrl, Shift and Alt only Ctrl was held when the event
* was generated. */
template <typename E>
inline bool held_only_control(E const &event) {
return state_held_only_control(event.state);
}
/** True if from the set of Ctrl, Shift and Alt only Shift was held when the event
* was generated. */
template <typename E>
inline bool held_only_shift(E const &event) {
return state_held_only_shift(event.state);
}
/** True if from the set of Ctrl, Shift and Alt only Alt was held when the event
* was generated. */
template <typename E>
inline bool held_only_alt(E const &event) {
return state_held_only_alt(event.state);
}
template <typename E>
inline bool held_no_modifiers(E const &event) {
return state_held_no_modifiers(event.state);
}
template <typename E>
inline bool held_any_modifiers(E const &event) {
return state_held_any_modifiers(event.state);
}
template <typename E>
inline Geom::Point event_point(E const &event) {
return Geom::Point(event.x, event.y);
}
/** Use like this:
* @code if (held_button<2>(event->motion)) { ... @endcode */
template <unsigned button, typename E>
inline bool held_button(E const &event) {
return state_held_button<button>(event.state);
}
guint shortcut_key(GdkEventKey const &event);
unsigned state_after_event(GdkEvent *event);
} // namespace UI
} // namespace Inkscape
#endif
/*
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:fileencoding=utf-8:textwidth=99 :
|