Audio plugin host https://kx.studio/carla
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.

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