-
-
Notifications
You must be signed in to change notification settings - Fork 98
/
Base.hpp
305 lines (264 loc) · 11.5 KB
/
Base.hpp
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
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
/*
* DISTRHO Plugin Framework (DPF)
* Copyright (C) 2012-2024 Filipe Coelho <falktx@falktx.com>
*
* Permission to use, copy, modify, and/or distribute this software for any purpose with
* or without fee is hereby granted, provided that the above copyright notice and this
* permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD
* TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN
* NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
* DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
* IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#ifndef DGL_BASE_HPP_INCLUDED
#define DGL_BASE_HPP_INCLUDED
#include "../distrho/extra/LeakDetector.hpp"
#include "../distrho/extra/ScopedPointer.hpp"
// --------------------------------------------------------------------------------------------------------------------
// Compatibility checks
#if defined(DGL_CAIRO) && defined(DGL_EXTERNAL)
# error invalid build config: trying to build for both cairo and external at the same time
#elif defined(DGL_CAIRO) && defined(DGL_OPENGL)
# error invalid build config: trying to build for both cairo and opengl at the same time
#elif defined(DGL_CAIRO) && defined(DGL_VULKAN)
# error invalid build config: trying to build for both cairo and vulkan at the same time
#elif defined(DGL_EXTERNAL) && defined(DGL_OPENGL)
# error invalid build config: trying to build for both external and opengl at the same time
#elif defined(DGL_EXTERNAL) && defined(DGL_VULKAN)
# error invalid build config: trying to build for both external and vulkan at the same time
#elif defined(DGL_OPENGL) && defined(DGL_VULKAN)
# error invalid build config: trying to build for both opengl and vulkan at the same time
#endif
#ifdef DGL_USE_FILEBROWSER
# error typo detected use DGL_USE_FILE_BROWSER instead of DGL_USE_FILEBROWSER
#endif
#ifdef DGL_UI_USE_WEBVIEW
# error typo detected use DGL_UI_USE_WEB_VIEW instead of DGL_UI_USE_WEBVIEW
#endif
#if defined(DGL_FILE_BROWSER_DISABLED)
# error DGL_FILE_BROWSER_DISABLED has been replaced by DGL_USE_FILE_BROWSER (opt-in vs opt-out)
#endif
// --------------------------------------------------------------------------------------------------------------------
// Define namespace
#ifndef DGL_NAMESPACE
# define DGL_NAMESPACE DGL
#endif
#define START_NAMESPACE_DGL namespace DGL_NAMESPACE {
#define END_NAMESPACE_DGL }
#define USE_NAMESPACE_DGL using namespace DGL_NAMESPACE;
START_NAMESPACE_DGL
// --------------------------------------------------------------------------------------------------------------------
// Base DGL enums
/**
Keyboard modifier flags.
*/
enum Modifier {
kModifierShift = 1U << 0U, ///< Shift key
kModifierControl = 1U << 1U, ///< Control key
kModifierAlt = 1U << 2U, ///< Alt/Option key
kModifierSuper = 1U << 3U, ///< Mod4/Command/Windows key
kModifierNumLock = 1U << 4U, ///< Num lock enabled
kModifierScrollLock = 1U << 5U, ///< Scroll lock enabled
kModifierCapsLock = 1U << 6U, ///< Caps lock enabled
};
/**
Keyboard key codepoints.
All keys are identified by a Unicode code point in Widget::KeyboardEvent::key.
This enumeration defines constants for special keys that do not have a standard
code point, and some convenience constants for control characters.
Note that all keys are handled in the same way, this enumeration is just for
convenience when writing hard-coded key bindings.
Keys that do not have a standard code point use values in the Private Use
Area in the Basic Multilingual Plane (`U+E000` to `U+F8FF`).
Applications must take care to not interpret these values beyond key detection,
the mapping used here is arbitrary and specific to DPF.
*/
enum Key {
// Convenience symbols for ASCII control characters
kKeyBackspace = 0x00000008U, ///< Backspace
kKeyTab = 0x00000009U, ///< Tab
kKeyEnter = 0x0000000DU, ///< Enter
kKeyEscape = 0x0000001BU, ///< Escape
kKeyDelete = 0x0000007FU, ///< Delete
kKeySpace = 0x00000020U, ///< Space
// Unicode Private Use Area
kKeyF1 = 0xE000U, ///< F1
kKeyF2, ///< F2
kKeyF3, ///< F3
kKeyF4, ///< F4
kKeyF5, ///< F5
kKeyF6, ///< F6
kKeyF7, ///< F7
kKeyF8, ///< F8
kKeyF9, ///< F9
kKeyF10, ///< F10
kKeyF11, ///< F11
kKeyF12, ///< F12
kKeyPageUp = 0xE031U, ///< Page Up
kKeyPageDown, ///< Page Down
kKeyEnd, ///< End
kKeyHome, ///< Home
kKeyLeft, ///< Left
kKeyUp, ///< Up
kKeyRight, ///< Right
kKeyDown, ///< Down
kKeyPrintScreen = 0xE041U, ///< Print Screen
kKeyInsert, ///< Insert
kKeyPause, ///< Pause/Break
kKeyMenu, ///< Menu
kKeyNumLock, ///< Num Lock
kKeyScrollLock, ///< Scroll Lock
kKeyCapsLock, ///< Caps Lock
kKeyShiftL = 0xE051U, ///< Left Shift
kKeyShiftR, ///< Right Shift
kKeyControlL, ///< Left Control
kKeyControlR, ///< Right Control
kKeyAltL, ///< Left Alt
kKeyAltR, ///< Right Alt / AltGr
kKeySuperL, ///< Left Super
kKeySuperR, ///< Right Super
kKeyPad0 = 0xE060U, ///< Keypad 0
kKeyPad1, ///< Keypad 1
kKeyPad2, ///< Keypad 2
kKeyPad3, ///< Keypad 3
kKeyPad4, ///< Keypad 4
kKeyPad5, ///< Keypad 5
kKeyPad6, ///< Keypad 6
kKeyPad7, ///< Keypad 7
kKeyPad8, ///< Keypad 8
kKeyPad9, ///< Keypad 9
kKeyPadEnter, ///< Keypad Enter
kKeyPadPageUp = 0xE071U, ///< Keypad Page Up
kKeyPadPageDown, ///< Keypad Page Down
kKeyPadEnd, ///< Keypad End
kKeyPadHome, ///< Keypad Home
kKeyPadLeft, ///< Keypad Left
kKeyPadUp, ///< Keypad Up
kKeyPadRight, ///< Keypad Right
kKeyPadDown, ///< Keypad Down
kKeyPadClear = 0xE09DU, ///< Keypad Clear/Begin
kKeyPadInsert, ///< Keypad Insert
kKeyPadDelete, ///< Keypad Delete
kKeyPadEqual, ///< Keypad Equal
kKeyPadMultiply = 0xE0AAU, ///< Keypad Multiply
kKeyPadAdd, ///< Keypad Add
kKeyPadSeparator, ///< Keypad Separator
kKeyPadSubtract, ///< Keypad Subtract
kKeyPadDecimal, ///< Keypad Decimal
kKeyPadDivide, ///< Keypad Divide
// Backwards compatibility with old DPF
kCharBackspace DISTRHO_DEPRECATED_BY("kKeyBackspace") = kKeyBackspace,
kCharEscape DISTRHO_DEPRECATED_BY("kKeyEscape") = kKeyEscape,
kCharDelete DISTRHO_DEPRECATED_BY("kKeyDelete") = kKeyDelete,
kKeyShift DISTRHO_DEPRECATED_BY("kKeyShiftL") = kKeyShiftL,
kKeyControl DISTRHO_DEPRECATED_BY("kKeyControlL") = kKeyControlL,
kKeyAlt DISTRHO_DEPRECATED_BY("kKeyAltL") = kKeyAltL,
kKeySuper DISTRHO_DEPRECATED_BY("kKeySuperL") = kKeySuperL,
};
/**
Common flags for all events.
*/
enum EventFlag {
kFlagSendEvent = 1, ///< Event is synthetic
kFlagIsHint = 2, ///< Event is a hint (not direct user input)
};
/**
Reason for a crossing event.
*/
enum CrossingMode {
kCrossingNormal, ///< Crossing due to pointer motion
kCrossingGrab, ///< Crossing due to a grab
kCrossingUngrab, ///< Crossing due to a grab release
};
/**
A mouse button.
Mouse button numbers start from 1, and are ordered: primary, secondary, middle.
So, on a typical right-handed mouse, the button numbers are:
Left: 1
Right: 2
Middle (often a wheel): 3
Higher button numbers are reported in the same order they are represented on the system.
There is no universal standard here, but buttons 4 and 5 are typically a pair of buttons or a rocker,
which are usually bound to "back" and "forward" operations.
Note that these numbers may differ from those used on the underlying
platform, since they are manipulated to provide a consistent portable API.
*/
enum MouseButton {
kMouseButtonLeft = 1,
kMouseButtonRight,
kMouseButtonMiddle,
};
/**
A mouse cursor type.
This is a portable subset of mouse cursors that exist on X11, MacOS, and Windows.
*/
enum MouseCursor {
kMouseCursorArrow, ///< Default pointing arrow
kMouseCursorCaret, ///< Caret (I-Beam) for text entry
kMouseCursorCrosshair, ///< Cross-hair
kMouseCursorHand, ///< Hand with a pointing finger
kMouseCursorNotAllowed, ///< Operation not allowed
kMouseCursorLeftRight, ///< Left/right arrow for horizontal resize
kMouseCursorUpDown, ///< Up/down arrow for vertical resize
kMouseCursorUpLeftDownRight, ///< Diagonal arrow for down/right resize
kMouseCursorUpRightDownLeft, ///< Diagonal arrow for down/left resize
kMouseCursorAllScroll, ///< Omnidirectional "arrow" for scrolling
// Backwards compatibility with old DPF
kMouseCursorDiagonal DISTRHO_DEPRECATED_BY("kMouseCursorUpLeftDownRight") = kMouseCursorUpLeftDownRight,
kMouseCursorAntiDiagonal DISTRHO_DEPRECATED_BY("kMouseCursorUpRightDownLeft") = kMouseCursorUpRightDownLeft,
};
/**
Scroll direction.
Describes the direction of a scroll event along with whether the scroll is a "smooth" scroll.
The discrete directions are for devices like mouse wheels with constrained axes,
while a smooth scroll is for those with arbitrary scroll direction freedom, like some touchpads.
*/
enum ScrollDirection {
kScrollUp, ///< Scroll up
kScrollDown, ///< Scroll down
kScrollLeft, ///< Scroll left
kScrollRight, ///< Scroll right
kScrollSmooth, ///< Smooth scroll in any direction
};
/**
A clipboard data offer.
@see Window::onClipboardDataOffer
*/
struct ClipboardDataOffer {
/**
The id of this data offer.
@note The value 0 is reserved for null/invalid.
*/
uint32_t id;
/**
The type of this data offer.
Usually a MIME type, but may also be another platform-specific type identifier.
*/
const char* type;
};
// --------------------------------------------------------------------------------------------------------------------
// Base DGL classes
/**
Graphics context, definition depends on build type.
*/
struct GraphicsContext {};
/**
Idle callback.
*/
struct IdleCallback
{
virtual ~IdleCallback() {}
virtual void idleCallback() = 0;
};
// --------------------------------------------------------------------------------------------------------------------
END_NAMESPACE_DGL
#ifndef DONT_SET_USING_DGL_NAMESPACE
// If your code uses a lot of DGL classes, then this will obviously save you
// a lot of typing, but can be disabled by setting DONT_SET_USING_DGL_NAMESPACE.
using namespace DGL_NAMESPACE;
#endif
// --------------------------------------------------------------------------------------------------------------------
#endif // DGL_BASE_HPP_INCLUDED