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