Dusk Audio Framework
Loading...
Searching...
No Matches
Base.hpp
1/*
2 * DISTRHO Plugin Framework (DPF)
3 * Copyright (C) 2012-2025 Filipe Coelho <falktx@falktx.com>
4 *
5 * Permission to use, copy, modify, and/or distribute this software for any purpose with
6 * or without fee is hereby granted, provided that the above copyright notice and this
7 * permission notice appear in all copies.
8 *
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD
10 * TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN
11 * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
12 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
13 * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
14 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 */
16
17#ifndef DGL_BASE_HPP_INCLUDED
18#define DGL_BASE_HPP_INCLUDED
19
20#include "../daf/extra/LeakDetector.hpp"
21#include "../daf/extra/ScopedPointer.hpp"
22
23// --------------------------------------------------------------------------------------------------------------------
24// Compatibility checks
25
26#if defined(DGL_CAIRO) && defined(DGL_EXTERNAL)
27# error invalid build config: trying to build for both cairo and external at the same time
28#elif defined(DGL_CAIRO) && defined(DGL_OPENGL)
29# error invalid build config: trying to build for both cairo and opengl at the same time
30#elif defined(DGL_CAIRO) && defined(DGL_VULKAN)
31# error invalid build config: trying to build for both cairo and vulkan at the same time
32#elif defined(DGL_EXTERNAL) && defined(DGL_OPENGL)
33# error invalid build config: trying to build for both external and opengl at the same time
34#elif defined(DGL_EXTERNAL) && defined(DGL_VULKAN)
35# error invalid build config: trying to build for both external and vulkan at the same time
36#elif defined(DGL_OPENGL) && defined(DGL_VULKAN)
37# error invalid build config: trying to build for both opengl and vulkan at the same time
38#endif
39
40#ifdef DGL_USE_FILEBROWSER
41# error typo detected use DGL_USE_FILE_BROWSER instead of DGL_USE_FILEBROWSER
42#endif
43
44#ifdef DGL_USE_WEBVIEW
45# error typo detected use DGL_USE_WEB_VIEW instead of DGL_USE_WEBVIEW
46#endif
47
48#if defined(DGL_FILE_BROWSER_DISABLED)
49# error DGL_FILE_BROWSER_DISABLED has been replaced by DGL_USE_FILE_BROWSER (opt-in vs opt-out)
50#endif
51
52#ifndef DGL_ALLOW_DEPRECATED_METHODS
53# define DGL_ALLOW_DEPRECATED_METHODS 1
54#endif
55
56// --------------------------------------------------------------------------------------------------------------------
57// Define namespace
58
59#ifndef DGL_NAMESPACE
60# define DGL_NAMESPACE DGL
61#endif
62
63#define START_NAMESPACE_DGL namespace DGL_NAMESPACE {
64#define END_NAMESPACE_DGL }
65#define USE_NAMESPACE_DGL using namespace DGL_NAMESPACE;
66
67START_NAMESPACE_DGL
68
69// --------------------------------------------------------------------------------------------------------------------
70// Base DGL enums
71
72/**
73 Keyboard modifier flags.
74 */
75enum Modifier {
76 kModifierShift = 1U << 0U, ///< Shift key
77 kModifierControl = 1U << 1U, ///< Control key
78 kModifierAlt = 1U << 2U, ///< Alt/Option key
79 kModifierSuper = 1U << 3U, ///< Mod4/Command/Windows key
80 kModifierNumLock = 1U << 4U, ///< Num lock enabled
81 kModifierScrollLock = 1U << 5U, ///< Scroll lock enabled
82 kModifierCapsLock = 1U << 6U, ///< Caps lock enabled
83};
84
85/**
86 Keyboard key codepoints.
87
88 All keys are identified by a Unicode code point in Widget::KeyboardEvent::key.
89 This enumeration defines constants for special keys that do not have a standard
90 code point, and some convenience constants for control characters.
91 Note that all keys are handled in the same way, this enumeration is just for
92 convenience when writing hard-coded key bindings.
93
94 Keys that do not have a standard code point use values in the Private Use
95 Area in the Basic Multilingual Plane (`U+E000` to `U+F8FF`).
96 Applications must take care to not interpret these values beyond key detection,
97 the mapping used here is arbitrary and specific to DAF.
98 */
99enum Key {
100 // Convenience symbols for ASCII control characters
101 kKeyBackspace = 0x00000008U, ///< Backspace
102 kKeyTab = 0x00000009U, ///< Tab
103 kKeyEnter = 0x0000000DU, ///< Enter
104 kKeyEscape = 0x0000001BU, ///< Escape
105 kKeyDelete = 0x0000007FU, ///< Delete
106 kKeySpace = 0x00000020U, ///< Space
107
108 // Unicode Private Use Area
109 kKeyF1 = 0xE000U, ///< F1
110 kKeyF2, ///< F2
111 kKeyF3, ///< F3
112 kKeyF4, ///< F4
113 kKeyF5, ///< F5
114 kKeyF6, ///< F6
115 kKeyF7, ///< F7
116 kKeyF8, ///< F8
117 kKeyF9, ///< F9
118 kKeyF10, ///< F10
119 kKeyF11, ///< F11
120 kKeyF12, ///< F12
121 kKeyPageUp = 0xE031U, ///< Page Up
122 kKeyPageDown, ///< Page Down
123 kKeyEnd, ///< End
124 kKeyHome, ///< Home
125 kKeyLeft, ///< Left
126 kKeyUp, ///< Up
127 kKeyRight, ///< Right
128 kKeyDown, ///< Down
129 kKeyPrintScreen = 0xE041U, ///< Print Screen
130 kKeyInsert, ///< Insert
131 kKeyPause, ///< Pause/Break
132 kKeyMenu, ///< Menu
133 kKeyNumLock, ///< Num Lock
134 kKeyScrollLock, ///< Scroll Lock
135 kKeyCapsLock, ///< Caps Lock
136 kKeyShiftL = 0xE051U, ///< Left Shift
137 kKeyShiftR, ///< Right Shift
138 kKeyControlL, ///< Left Control
139 kKeyControlR, ///< Right Control
140 kKeyAltL, ///< Left Alt
141 kKeyAltR, ///< Right Alt / AltGr
142 kKeySuperL, ///< Left Super
143 kKeySuperR, ///< Right Super
144 kKeyPad0 = 0xE060U, ///< Keypad 0
145 kKeyPad1, ///< Keypad 1
146 kKeyPad2, ///< Keypad 2
147 kKeyPad3, ///< Keypad 3
148 kKeyPad4, ///< Keypad 4
149 kKeyPad5, ///< Keypad 5
150 kKeyPad6, ///< Keypad 6
151 kKeyPad7, ///< Keypad 7
152 kKeyPad8, ///< Keypad 8
153 kKeyPad9, ///< Keypad 9
154 kKeyPadEnter, ///< Keypad Enter
155 kKeyPadPageUp = 0xE071U, ///< Keypad Page Up
156 kKeyPadPageDown, ///< Keypad Page Down
157 kKeyPadEnd, ///< Keypad End
158 kKeyPadHome, ///< Keypad Home
159 kKeyPadLeft, ///< Keypad Left
160 kKeyPadUp, ///< Keypad Up
161 kKeyPadRight, ///< Keypad Right
162 kKeyPadDown, ///< Keypad Down
163 kKeyPadClear = 0xE09DU, ///< Keypad Clear/Begin
164 kKeyPadInsert, ///< Keypad Insert
165 kKeyPadDelete, ///< Keypad Delete
166 kKeyPadEqual, ///< Keypad Equal
167 kKeyPadMultiply = 0xE0AAU, ///< Keypad Multiply
168 kKeyPadAdd, ///< Keypad Add
169 kKeyPadSeparator, ///< Keypad Separator
170 kKeyPadSubtract, ///< Keypad Subtract
171 kKeyPadDecimal, ///< Keypad Decimal
172 kKeyPadDivide, ///< Keypad Divide
173
174 // Backwards compatibility with old DAF
175 kCharBackspace DAF_DEPRECATED_BY("kKeyBackspace") = kKeyBackspace,
176 kCharEscape DAF_DEPRECATED_BY("kKeyEscape") = kKeyEscape,
177 kCharDelete DAF_DEPRECATED_BY("kKeyDelete") = kKeyDelete,
178
179 kKeyShift DAF_DEPRECATED_BY("kKeyShiftL") = kKeyShiftL,
180 kKeyControl DAF_DEPRECATED_BY("kKeyControlL") = kKeyControlL,
181 kKeyAlt DAF_DEPRECATED_BY("kKeyAltL") = kKeyAltL,
182 kKeySuper DAF_DEPRECATED_BY("kKeySuperL") = kKeySuperL,
183};
184
185/**
186 Common flags for all events.
187 */
188enum EventFlag {
189 kFlagSendEvent = 1, ///< Event is synthetic
190 kFlagIsHint = 2, ///< Event is a hint (not direct user input)
191};
192
193/**
194 Reason for a crossing event.
195 */
196enum CrossingMode {
197 kCrossingNormal, ///< Crossing due to pointer motion
198 kCrossingGrab, ///< Crossing due to a grab
199 kCrossingUngrab, ///< Crossing due to a grab release
200};
201
202/**
203 A mouse button.
204
205 Mouse button numbers start from 1, and are ordered: primary, secondary, middle.
206 So, on a typical right-handed mouse, the button numbers are:
207
208 Left: 1
209 Right: 2
210 Middle (often a wheel): 3
211
212 Higher button numbers are reported in the same order they are represented on the system.
213 There is no universal standard here, but buttons 4 and 5 are typically a pair of buttons or a rocker,
214 which are usually bound to "back" and "forward" operations.
215
216 Note that these numbers may differ from those used on the underlying
217 platform, since they are manipulated to provide a consistent portable API.
218*/
219enum MouseButton {
220 kMouseButtonLeft = 1,
221 kMouseButtonRight,
222 kMouseButtonMiddle,
223};
224
225/**
226 A mouse cursor type.
227
228 This is a portable subset of mouse cursors that exist on X11, MacOS, and Windows.
229*/
230enum MouseCursor {
231 kMouseCursorArrow, ///< Default pointing arrow
232 kMouseCursorCaret, ///< Caret (I-Beam) for text entry
233 kMouseCursorCrosshair, ///< Cross-hair
234 kMouseCursorHand, ///< Hand with a pointing finger
235 kMouseCursorNotAllowed, ///< Operation not allowed
236 kMouseCursorLeftRight, ///< Left/right arrow for horizontal resize
237 kMouseCursorUpDown, ///< Up/down arrow for vertical resize
238 kMouseCursorUpLeftDownRight, ///< Diagonal arrow for down/right resize
239 kMouseCursorUpRightDownLeft, ///< Diagonal arrow for down/left resize
240 kMouseCursorAllScroll, ///< Omnidirectional "arrow" for scrolling
241 kMouseCursorNone, ///< No cursor at all, the pointer is hidden
242
243 // Backwards compatibility with old DAF
244 kMouseCursorDiagonal DAF_DEPRECATED_BY("kMouseCursorUpLeftDownRight") = kMouseCursorUpLeftDownRight,
245 kMouseCursorAntiDiagonal DAF_DEPRECATED_BY("kMouseCursorUpRightDownLeft") = kMouseCursorUpRightDownLeft,
246};
247
248/**
249 Scroll direction.
250
251 Describes the direction of a scroll event along with whether the scroll is a "smooth" scroll.
252 The discrete directions are for devices like mouse wheels with constrained axes,
253 while a smooth scroll is for those with arbitrary scroll direction freedom, like some touchpads.
254*/
255enum ScrollDirection {
256 kScrollUp, ///< Scroll up
257 kScrollDown, ///< Scroll down
258 kScrollLeft, ///< Scroll left
259 kScrollRight, ///< Scroll right
260 kScrollSmooth, ///< Smooth scroll in any direction
261};
262
263/**
264 A clipboard data offer.
265 @see Window::onClipboardDataOffer
266*/
268 /**
269 The id of this data offer.
270 @note The value 0 is reserved for null/invalid.
271 */
272 uint32_t id;
273
274 /**
275 The type of this data offer.
276 Usually a MIME type, but may also be another platform-specific type identifier.
277 */
278 const char* type;
279};
280
281// --------------------------------------------------------------------------------------------------------------------
282// Base DGL classes
283
284/**
285 Graphics context, definition depends on build type.
286 */
288
289/**
290 Idle callback.
291 */
293{
294 virtual ~IdleCallback() {}
295 virtual void idleCallback() = 0;
296};
297
298// --------------------------------------------------------------------------------------------------------------------
299
300END_NAMESPACE_DGL
301
302#ifndef DONT_SET_USING_DGL_NAMESPACE
303 // If your code uses a lot of DGL classes, then this will obviously save you
304 // a lot of typing, but can be disabled by setting DONT_SET_USING_DGL_NAMESPACE.
305 using namespace DGL_NAMESPACE;
306#endif
307
308// --------------------------------------------------------------------------------------------------------------------
309
310#endif // DGL_BASE_HPP_INCLUDED
Definition Base.hpp:267
const char * type
Definition Base.hpp:278
uint32_t id
Definition Base.hpp:272
Definition Base.hpp:287
Definition Base.hpp:293