DISTRHO Plugin Framework
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

306 lines
12KB

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