Pulp 1.88.0
Cross-platform audio plugin framework
Loading...
Searching...
No Matches
input_events.hpp
Go to the documentation of this file.
1#pragma once
2
6
8#include <cstdint>
9#include <string>
10
11namespace pulp::view {
12
13// ── Modifier flags ───────────────────────────────────────────────────────
14
15enum Modifier : uint16_t {
17 kModShift = 1 << 0,
18 kModCtrl = 1 << 1,
19 kModAlt = 1 << 2,
20 kModMeta = 1 << 3,
21 kModCmd = 1 << 4,
22};
23
25inline bool is_main_modifier(uint16_t mods) {
26#ifdef __APPLE__
27 return (mods & kModCmd) != 0;
28#else
29 return (mods & kModCtrl) != 0;
30#endif
31}
32
33// ── Key codes ────────────────────────────────────────────────────────────
34
35enum class KeyCode : int {
37
38 // Letters
39 a = 'a', b = 'b', c = 'c', d = 'd', e = 'e', f = 'f', g = 'g', h = 'h',
40 i = 'i', j = 'j', k = 'k', l = 'l', m = 'm', n = 'n', o = 'o', p = 'p',
41 q = 'q', r = 'r', s = 's', t = 't', u = 'u', v = 'v', w = 'w', x = 'x',
42 y = 'y', z = 'z',
43
44 // Numbers
45 num0 = '0', num1 = '1', num2 = '2', num3 = '3', num4 = '4',
46 num5 = '5', num6 = '6', num7 = '7', num8 = '8', num9 = '9',
47
48 // Punctuation (ASCII-valued). The Musical Typing layout's two top keys
49 // beyond `p` are `;` and `'`, so they must be nameable to map them.
50 semicolon = ';', apostrophe = '\'',
51
52 // Navigation
53 left = 256, right, up, down,
55
56 // Editing
58 space = ' ',
59
60 // Function keys
61 f1 = 290, f2, f3, f4, f5, f6, f7, f8, f9, f10, f11, f12,
62};
63
64// ── Mouse / pointer event ────────────────────────────────────────────────
65
67enum class MouseButton : uint8_t {
68 none = 0,
69 left = 1,
70 right = 2,
71 middle = 3,
72};
73
75enum class PointerType : uint8_t {
76 mouse = 0,
77 touch = 1,
78 pen = 2,
79};
80
94enum class MousePhase : uint8_t {
100};
101
108 uint16_t modifiers = 0;
109 int pointer_id = 0;
110 int click_count = 1;
111 bool is_down = false;
113 bool is_cancelled = false;
114 bool is_wheel = false;
115 float scroll_delta_x = 0;
116 float scroll_delta_y = 0;
117
118 // ── Pointer / stylus properties (W3C PointerEvent) ──────────────
120 float pressure = 0.5f;
121 float altitude_angle = 0;
122 float azimuth_angle = 0;
123 float movement_x = 0;
124 float movement_y = 0;
125 bool has_movement_delta = false;
126
127 bool isShiftDown() const { return (modifiers & kModShift) != 0; }
128 bool isCtrlDown() const { return (modifiers & kModCtrl) != 0; }
129 bool isAltDown() const { return (modifiers & kModAlt) != 0; }
130 bool isCmdDown() const { return (modifiers & kModCmd) != 0; }
131 bool isMetaDown() const { return (modifiers & kModMeta) != 0; }
132 bool isMainModifier() const { return is_main_modifier(modifiers); }
133 bool isTouch() const { return pointer_type == PointerType::touch || (modifiers & 0x8000) != 0; }
134 bool isPen() const { return pointer_type == PointerType::pen; }
135 bool isWheel() const { return is_wheel; }
136 bool isPrimary() const { return pointer_id == 0; }
137
138 // ── Gesture-phase resolution ─────────────────────────────────────
139 // When `phase` is set explicitly (a real platform host), use it.
140 // When it is `automatic` (legacy / headless callers that only set
141 // `is_down`), keep the historical inference: `is_down` events that
142 // begin a gesture read as a press. Callers on the button-state-CHANGED
143 // convention (drag=is_down=false, release=is_down=true) are unchanged
144 // because they leave `phase == automatic`.
146 bool isPress() const {
149 }
150
154 bool isDrag() const { return phase == MousePhase::drag; }
156 bool isRelease() const { return phase == MousePhase::release; }
158 bool hasExplicitPhase() const { return phase != MousePhase::automatic; }
159
161 const char* pointerTypeString() const {
162 switch (pointer_type) {
163 case PointerType::touch: return "touch";
164 case PointerType::pen: return "pen";
165 default: return "mouse";
166 }
167 }
168};
169
170// ── Gesture event (pinch / rotate) ──────────────────────────────────────
171
172enum class GesturePhase : uint8_t {
173 began = 0,
175 ended = 2,
177};
178
183 float scale = 1.0f;
184 float rotation = 0.0f;
185 float delta_scale = 0.0f;
186 float delta_rotation = 0.0f;
188};
189
190// ── Key event ────────────────────────────────────────────────────────────
191
193struct KeyEvent {
195 uint16_t modifiers = 0;
196 bool is_down = true;
197 bool is_repeat = false;
198
199 bool isShiftDown() const { return (modifiers & kModShift) != 0; }
200 bool isCtrlDown() const { return (modifiers & kModCtrl) != 0; }
201 bool isAltDown() const { return (modifiers & kModAlt) != 0; }
202 bool isCmdDown() const { return (modifiers & kModCmd) != 0; }
203 bool isMainModifier() const { return is_main_modifier(modifiers); }
204};
205
206// ── Text input event ─────────────────────────────────────────────────────
207
211 std::string text;
212};
213
214} // namespace pulp::view
Hover-cursor tracking for platform window hosts.
Definition fwd.hpp:27
@ up
Definition buttons.hpp:119
@ down
Definition buttons.hpp:119
@ end_
Pack items to end.
Definition geometry.hpp:376
Modifier
Definition input_events.hpp:15
@ kModCmd
Command (macOS) — alias for platform primary modifier.
Definition input_events.hpp:21
@ kModMeta
Windows key / Command key.
Definition input_events.hpp:20
@ kModNone
Definition input_events.hpp:16
@ kModShift
Definition input_events.hpp:17
@ kModAlt
Alt / Option.
Definition input_events.hpp:19
@ kModCtrl
Control key (Ctrl on Windows/Linux).
Definition input_events.hpp:18
@ right
Definition border_style.hpp:31
@ left
Definition border_style.hpp:31
@ none
Definition appearance_defects.hpp:53
GesturePhase
Definition input_events.hpp:172
@ began
Definition input_events.hpp:173
MouseButton
Mouse button identifiers.
Definition input_events.hpp:67
@ middle
Definition input_events.hpp:71
@ left
Definition input_events.hpp:69
bool is_main_modifier(uint16_t mods)
True if the primary action modifier is held (Cmd on macOS, Ctrl on Windows/Linux).
Definition input_events.hpp:25
PointerType
Pointer device type (W3C PointerEvent.pointerType).
Definition input_events.hpp:75
@ pen
Stylus / Apple Pencil.
Definition input_events.hpp:78
@ mouse
Mouse cursor (default).
Definition input_events.hpp:76
@ touch
Direct touch (finger).
Definition input_events.hpp:77
KeyCode
Definition input_events.hpp:35
@ delete_
Definition input_events.hpp:57
@ s
Definition input_events.hpp:41
@ num3
Definition input_events.hpp:45
@ a
Definition input_events.hpp:39
@ home
Definition input_events.hpp:54
@ f3
Definition input_events.hpp:61
@ h
Definition input_events.hpp:39
@ l
Definition input_events.hpp:40
@ j
Definition input_events.hpp:40
@ f2
Definition input_events.hpp:61
@ y
Definition input_events.hpp:42
@ num6
Definition input_events.hpp:46
@ c
Definition input_events.hpp:39
@ num4
Definition input_events.hpp:45
@ r
Definition input_events.hpp:41
@ backspace
Definition input_events.hpp:57
@ f8
Definition input_events.hpp:61
@ num2
Definition input_events.hpp:45
@ apostrophe
Definition input_events.hpp:50
@ num9
Definition input_events.hpp:46
@ f6
Definition input_events.hpp:61
@ f9
Definition input_events.hpp:61
@ num7
Definition input_events.hpp:46
@ f7
Definition input_events.hpp:61
@ f4
Definition input_events.hpp:61
@ m
Definition input_events.hpp:40
@ f5
Definition input_events.hpp:61
@ q
Definition input_events.hpp:41
@ semicolon
Definition input_events.hpp:50
@ u
Definition input_events.hpp:41
@ n
Definition input_events.hpp:40
@ f12
Definition input_events.hpp:61
@ d
Definition input_events.hpp:39
@ f10
Definition input_events.hpp:61
@ p
Definition input_events.hpp:40
@ i
Definition input_events.hpp:40
@ k
Definition input_events.hpp:40
@ f
Definition input_events.hpp:39
@ num0
Definition input_events.hpp:45
@ b
Definition input_events.hpp:39
@ x
Definition input_events.hpp:41
@ v
Definition input_events.hpp:41
@ unknown
Definition input_events.hpp:36
@ g
Definition input_events.hpp:39
@ num1
Definition input_events.hpp:45
@ f1
Definition input_events.hpp:61
@ num5
Definition input_events.hpp:46
@ page_down
Definition input_events.hpp:54
@ o
Definition input_events.hpp:40
@ escape
Definition input_events.hpp:57
@ e
Definition input_events.hpp:39
@ enter
Definition input_events.hpp:57
@ t
Definition input_events.hpp:41
@ tab
Definition input_events.hpp:57
@ num8
Definition input_events.hpp:46
@ w
Definition input_events.hpp:41
@ f11
Definition input_events.hpp:61
@ page_up
Definition input_events.hpp:54
@ z
Definition input_events.hpp:42
@ space
Definition input_events.hpp:58
@ unknown
Definition design_ir.hpp:701
@ cancelled
Definition gesture.hpp:19
@ began
Definition gesture.hpp:16
@ changed
Definition gesture.hpp:17
@ ended
Definition gesture.hpp:18
MousePhase
Explicit press/drag/release phase for a pointer gesture.
Definition input_events.hpp:94
@ release
Button-up that ends a gesture.
Definition input_events.hpp:98
@ automatic
Infer from is_down (legacy / headless default).
Definition input_events.hpp:95
@ press
Initial button-down that begins a gesture.
Definition input_events.hpp:96
@ drag
Pointer moved with the button held (a drag tick).
Definition input_events.hpp:97
@ hover
Pointer moved with no button held.
Definition input_events.hpp:99
High-level gesture event for pinch (scale) and rotate.
Definition input_events.hpp:181
float scale
Cumulative scale factor (1.0 = no change).
Definition input_events.hpp:183
float rotation
Cumulative rotation in radians.
Definition input_events.hpp:184
Point position
Center point of the gesture.
Definition input_events.hpp:187
GesturePhase phase
Definition input_events.hpp:182
float delta_rotation
Rotation delta since last event.
Definition input_events.hpp:186
float delta_scale
Scale delta since last event.
Definition input_events.hpp:185
Rich key event with key code, modifiers, and repeat state.
Definition input_events.hpp:193
uint16_t modifiers
Definition input_events.hpp:195
bool isAltDown() const
Definition input_events.hpp:201
bool isMainModifier() const
Definition input_events.hpp:203
bool isShiftDown() const
Definition input_events.hpp:199
bool is_repeat
True if this is a key repeat.
Definition input_events.hpp:197
KeyCode key
Definition input_events.hpp:194
bool isCtrlDown() const
Definition input_events.hpp:200
bool is_down
True for key-down, false for key-up.
Definition input_events.hpp:196
bool isCmdDown() const
Definition input_events.hpp:202
Rich mouse/pointer event with position, modifiers, button state, pointer ID, and stylus properties.
Definition input_events.hpp:104
bool is_wheel
True for scroll wheel events.
Definition input_events.hpp:114
bool isWheel() const
Definition input_events.hpp:135
bool isRelease() const
True for the button-up that ends a gesture.
Definition input_events.hpp:156
bool is_down
True for mouse-down / touch-began events.
Definition input_events.hpp:111
Point window_position
Position in window coordinates.
Definition input_events.hpp:106
bool isDrag() const
True for a drag tick (pointer moved with the button held).
Definition input_events.hpp:154
bool isPen() const
Definition input_events.hpp:134
float azimuth_angle
Stylus rotation in radians (0–2π).
Definition input_events.hpp:122
float scroll_delta_y
Vertical scroll delta (positive = down).
Definition input_events.hpp:116
float altitude_angle
Stylus tilt in radians (0 = perpendicular).
Definition input_events.hpp:121
int click_count
1=single, 2=double, 3=triple click
Definition input_events.hpp:110
bool isPrimary() const
Definition input_events.hpp:136
bool is_cancelled
True for touchesCancelled (→ pointercancel).
Definition input_events.hpp:113
bool isAltDown() const
Definition input_events.hpp:129
bool isShiftDown() const
Definition input_events.hpp:127
Point position
Position in local view coordinates.
Definition input_events.hpp:105
uint16_t modifiers
Bitfield of Modifier flags.
Definition input_events.hpp:108
bool isTouch() const
Definition input_events.hpp:133
MouseButton button
Definition input_events.hpp:107
bool isMainModifier() const
Definition input_events.hpp:132
MousePhase phase
Explicit gesture phase (see MousePhase).
Definition input_events.hpp:112
bool isCtrlDown() const
Definition input_events.hpp:128
float movement_y
Host-reported vertical movement since the prior event.
Definition input_events.hpp:124
const char * pointerTypeString() const
W3C pointerType string.
Definition input_events.hpp:161
float movement_x
Host-reported horizontal movement since the prior event.
Definition input_events.hpp:123
float pressure
0.0–1.0 (0.5 = default for mouse)
Definition input_events.hpp:120
bool isPress() const
True for the initial button-down that begins a gesture.
Definition input_events.hpp:146
bool has_movement_delta
Movement fields came from the native host.
Definition input_events.hpp:125
bool hasExplicitPhase() const
True when an explicit (non-automatic) phase is present.
Definition input_events.hpp:158
bool isCmdDown() const
Definition input_events.hpp:130
PointerType pointer_type
Definition input_events.hpp:119
float scroll_delta_x
Horizontal scroll delta (positive = right).
Definition input_events.hpp:115
int pointer_id
0 = primary, >0 = additional touches (multi-touch)
Definition input_events.hpp:109
bool isMetaDown() const
Definition input_events.hpp:131
Definition geometry.hpp:20
Text input from IME or keyboard composition (separate from KeyEvent).
Definition input_events.hpp:210
std::string text
UTF-8 encoded text.
Definition input_events.hpp:211