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.

273 lines
10.0KB

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