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.

277 lines
10KB

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