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.

229 lines
6.7KB

  1. /*
  2. * DISTRHO Plugin Framework (DPF)
  3. * Copyright (C) 2012-2021 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_EVENTS_HPP_INCLUDED
  17. #define DGL_EVENTS_HPP_INCLUDED
  18. #include "Geometry.hpp"
  19. START_NAMESPACE_DGL
  20. // --------------------------------------------------------------------------------------------------------------------
  21. namespace Events
  22. {
  23. /**
  24. Base event data.
  25. These are the fields present on all Widget events.
  26. @a mod Currently active keyboard modifiers, @see Modifier.
  27. @a mod Event flags, @see Flag.
  28. @a time Event timestamp (if any).
  29. */
  30. struct BaseEvent {
  31. uint mod;
  32. uint flags;
  33. uint time;
  34. /** Constuctor */
  35. BaseEvent() noexcept : mod(0x0), flags(0x0), time(0) {}
  36. /** Destuctor */
  37. virtual ~BaseEvent() noexcept {}
  38. };
  39. /**
  40. Keyboard event.
  41. This event represents low-level key presses and releases.
  42. This can be used for "direct" keyboard handing like key bindings, but must not be interpreted as text input.
  43. Keys are represented portably as Unicode code points, using the "natural" code point for the key.
  44. The @a key field is the code for the pressed key, without any modifiers applied.
  45. For example, a press or release of the 'A' key will have `key` 97 ('a')
  46. regardless of whether shift or control are being held.
  47. Alternatively, the raw @a keycode can be used to work directly with physical keys,
  48. but note that this value is not portable and differs between platforms and hardware.
  49. @a press True if the key was pressed, false if released.
  50. @a key Unicode point of the key pressed.
  51. @a keycode Raw keycode.
  52. @see onKeyboard
  53. */
  54. struct KeyboardEvent : BaseEvent {
  55. bool press;
  56. uint key;
  57. uint keycode;
  58. /** Constuctor */
  59. KeyboardEvent() noexcept
  60. : BaseEvent(),
  61. press(false),
  62. key(0),
  63. keycode(0) {}
  64. };
  65. /**
  66. Special keyboard event.
  67. This event allows the use of keys that do not have unicode points.
  68. Note that some are non-printable keys.
  69. @a press True if the key was pressed, false if released.
  70. @a key The key pressed.
  71. @see onSpecial
  72. */
  73. struct SpecialEvent : BaseEvent {
  74. bool press;
  75. Key key;
  76. /** Constuctor */
  77. SpecialEvent() noexcept
  78. : BaseEvent(),
  79. press(false),
  80. key(Key(0)) {}
  81. };
  82. /**
  83. Character input event.
  84. This event represents text input, usually as the result of a key press.
  85. The text is given both as a Unicode character code and a UTF-8 string.
  86. Note that this event is generated by the platform's input system,
  87. so there is not necessarily a direct correspondence between text events and physical key presses.
  88. For example, with some input methods a sequence of several key presses will generate a single character.
  89. @a keycode Raw key code.
  90. @a character Unicode character code.
  91. @a string UTF-8 string.
  92. @see onCharacterInput
  93. */
  94. struct CharacterInputEvent : BaseEvent {
  95. uint keycode;
  96. uint character;
  97. char string[8];
  98. /** Constuctor */
  99. CharacterInputEvent() noexcept
  100. : BaseEvent(),
  101. keycode(0),
  102. character(0),
  103. string{'\0','\0','\0','\0','\0','\0','\0','\0'} {}
  104. };
  105. /**
  106. Mouse press or release event.
  107. @a button The button number starting from 1 (1 = left, 2 = middle, 3 = right).
  108. @a press True if the button was pressed, false if released.
  109. @a pos The widget-relative coordinates of the pointer.
  110. @see onMouse
  111. */
  112. struct MouseEvent : BaseEvent {
  113. uint button;
  114. bool press;
  115. Point<double> pos;
  116. /** Constuctor */
  117. MouseEvent() noexcept
  118. : BaseEvent(),
  119. button(0),
  120. press(false),
  121. pos(0.0, 0.0) {}
  122. };
  123. /**
  124. Mouse motion event.
  125. @a pos The widget-relative coordinates of the pointer.
  126. @see onMotion
  127. */
  128. struct MotionEvent : BaseEvent {
  129. Point<double> pos;
  130. /** Constuctor */
  131. MotionEvent() noexcept
  132. : BaseEvent(),
  133. pos(0.0, 0.0) {}
  134. };
  135. /**
  136. Mouse scroll event.
  137. The scroll distance is expressed in "lines",
  138. an arbitrary unit that corresponds to a single tick of a detented mouse wheel.
  139. For example, `delta.y` = 1.0 scrolls 1 line up.
  140. Some systems and devices support finer resolution and/or higher values for fast scrolls,
  141. so programs should handle any value gracefully.
  142. @a pos The widget-relative coordinates of the pointer.
  143. @a delta The scroll distance.
  144. @a direction The direction of the scroll or "smooth".
  145. @see onScroll
  146. */
  147. struct ScrollEvent : BaseEvent {
  148. Point<double> pos;
  149. Point<double> delta;
  150. ScrollDirection direction;
  151. /** Constuctor */
  152. ScrollEvent() noexcept
  153. : BaseEvent(),
  154. pos(0.0, 0.0),
  155. delta(0.0, 0.0),
  156. direction(kScrollSmooth) {}
  157. };
  158. /**
  159. Resize event.
  160. @a size The new widget size.
  161. @a oldSize The previous size, may be null.
  162. @see onResize
  163. */
  164. struct ResizeEvent {
  165. Size<uint> size;
  166. Size<uint> oldSize;
  167. /** Constuctor */
  168. ResizeEvent() noexcept
  169. : size(0, 0),
  170. oldSize(0, 0) {}
  171. };
  172. /**
  173. Widget position changed event.
  174. @a pos The new absolute position of the widget.
  175. @a oldPos The previous absolute position of the widget.
  176. @see onPositionChanged
  177. */
  178. struct PositionChangedEvent {
  179. Point<int> pos;
  180. Point<int> oldPos;
  181. /** Constuctor */
  182. PositionChangedEvent() noexcept
  183. : pos(0, 0),
  184. oldPos(0, 0) {}
  185. };
  186. }
  187. // --------------------------------------------------------------------------------------------------------------------
  188. END_NAMESPACE_DGL
  189. #endif // DGL_EVENTS_HPP_INCLUDED