SDL_pen.h 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. /*
  2. Simple DirectMedia Layer
  3. Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
  4. This software is provided 'as-is', without any express or implied
  5. warranty. In no event will the authors be held liable for any damages
  6. arising from the use of this software.
  7. Permission is granted to anyone to use this software for any purpose,
  8. including commercial applications, and to alter it and redistribute it
  9. freely, subject to the following restrictions:
  10. 1. The origin of this software must not be misrepresented; you must not
  11. claim that you wrote the original software. If you use this software
  12. in a product, an acknowledgment in the product documentation would be
  13. appreciated but is not required.
  14. 2. Altered source versions must be plainly marked as such, and must not be
  15. misrepresented as being the original software.
  16. 3. This notice may not be removed or altered from any source distribution.
  17. */
  18. /**
  19. * # CategoryPen
  20. *
  21. * SDL pen event handling.
  22. *
  23. * SDL provides an API for pressure-sensitive pen (stylus and/or eraser)
  24. * handling, e.g., for input and drawing tablets or suitably equipped mobile /
  25. * tablet devices.
  26. *
  27. * To get started with pens, simply handle pen events:
  28. *
  29. * - SDL_EVENT_PEN_PROXIMITY_IN, SDL_EVENT_PEN_PROXIMITY_OUT
  30. * (SDL_PenProximityEvent)
  31. * - SDL_EVENT_PEN_DOWN, SDL_EVENT_PEN_UP (SDL_PenTouchEvent)
  32. * - SDL_EVENT_PEN_MOTION (SDL_PenMotionEvent)
  33. * - SDL_EVENT_PEN_BUTTON_DOWN, SDL_EVENT_PEN_BUTTON_UP (SDL_PenButtonEvent)
  34. * - SDL_EVENT_PEN_AXIS (SDL_PenAxisEvent)
  35. *
  36. * Pens may provide more than simple touch input; they might have other axes,
  37. * such as pressure, tilt, rotation, etc.
  38. *
  39. * When a pen starts providing input, SDL will assign it a unique SDL_PenID,
  40. * which will remain for the life of the process, as long as the pen stays
  41. * connected. A pen leaving proximity (being taken far enough away from the
  42. * digitizer tablet that it no longer reponds) and then coming back should
  43. * fire proximity events, but the SDL_PenID should remain consistent.
  44. * Unplugging the digitizer and reconnecting may cause future input to have
  45. * a new SDL_PenID, as SDL may not know that this is the same hardware.
  46. *
  47. * Please note that various platforms vary wildly in how (and how well) they
  48. * support pen input. If your pen supports some piece of functionality but SDL
  49. * doesn't seem to, it might actually be the operating system's fault. For
  50. * example, some platforms can manage multiple devices at the same time, but
  51. * others will make any connected pens look like a single logical device, much
  52. * how all USB mice connected to a computer will move the same system cursor.
  53. * cursor. Other platforms might not support pen buttons, or the distance
  54. * axis, etc. Very few platforms can even report _what_ functionality the pen
  55. * supports in the first place, so best practices is to either build UI to
  56. * let the user configure their pens, or be prepared to handle new
  57. * functionality for a pen the first time an event is reported.
  58. */
  59. #ifndef SDL_pen_h_
  60. #define SDL_pen_h_
  61. #include <SDL3/SDL_stdinc.h>
  62. #include <SDL3/SDL_mouse.h>
  63. #include <SDL3/SDL_touch.h>
  64. #include <SDL3/SDL_begin_code.h>
  65. /* Set up for C function definitions, even when using C++ */
  66. #ifdef __cplusplus
  67. extern "C" {
  68. #endif
  69. /**
  70. * SDL pen instance IDs.
  71. *
  72. * Zero is used to signify an invalid/null device.
  73. *
  74. * These show up in pen events when SDL sees input from them. They remain
  75. * consistent as long as SDL can recognize a tool to be the same pen; but if a
  76. * pen's digitizer table is physically detached from the computer, it might get
  77. * a new ID when reconnected, as SDL won't know it's the same device.
  78. *
  79. * These IDs are only stable within a single run of a program; the next time
  80. * a program is run, the pen's ID will likely be different, even if the
  81. * hardware hasn't been disconnected, etc.
  82. *
  83. * \since This datatype is available since SDL 3.2.0.
  84. */
  85. typedef Uint32 SDL_PenID;
  86. /**
  87. * The SDL_MouseID for mouse events simulated with pen input.
  88. *
  89. * \since This macro is available since SDL 3.2.0.
  90. */
  91. #define SDL_PEN_MOUSEID ((SDL_MouseID)-2)
  92. /**
  93. * The SDL_TouchID for touch events simulated with pen input.
  94. *
  95. * \since This macro is available since SDL 3.2.0.
  96. */
  97. #define SDL_PEN_TOUCHID ((SDL_TouchID)-2)
  98. /**
  99. * Pen input flags, as reported by various pen events' `pen_state` field.
  100. *
  101. * \since This datatype is available since SDL 3.2.0.
  102. */
  103. typedef Uint32 SDL_PenInputFlags;
  104. #define SDL_PEN_INPUT_DOWN (1u << 0) /**< pen is pressed down */
  105. #define SDL_PEN_INPUT_BUTTON_1 (1u << 1) /**< button 1 is pressed */
  106. #define SDL_PEN_INPUT_BUTTON_2 (1u << 2) /**< button 2 is pressed */
  107. #define SDL_PEN_INPUT_BUTTON_3 (1u << 3) /**< button 3 is pressed */
  108. #define SDL_PEN_INPUT_BUTTON_4 (1u << 4) /**< button 4 is pressed */
  109. #define SDL_PEN_INPUT_BUTTON_5 (1u << 5) /**< button 5 is pressed */
  110. #define SDL_PEN_INPUT_ERASER_TIP (1u << 30) /**< eraser tip is used */
  111. #define SDL_PEN_INPUT_IN_PROXIMITY (1u << 31) /**< pen is in proximity (since SDL 3.4.0) */
  112. /**
  113. * Pen axis indices.
  114. *
  115. * These are the valid values for the `axis` field in SDL_PenAxisEvent. All
  116. * axes are either normalised to 0..1 or report a (positive or negative) angle
  117. * in degrees, with 0.0 representing the centre. Not all pens/backends support
  118. * all axes: unsupported axes are always zero.
  119. *
  120. * To convert angles for tilt and rotation into vector representation, use
  121. * SDL_sinf on the XTILT, YTILT, or ROTATION component, for example:
  122. *
  123. * `SDL_sinf(xtilt * SDL_PI_F / 180.0)`.
  124. *
  125. * \since This enum is available since SDL 3.2.0.
  126. */
  127. typedef enum SDL_PenAxis
  128. {
  129. SDL_PEN_AXIS_PRESSURE, /**< Pen pressure. Unidirectional: 0 to 1.0 */
  130. SDL_PEN_AXIS_XTILT, /**< Pen horizontal tilt angle. Bidirectional: -90.0 to 90.0 (left-to-right). */
  131. SDL_PEN_AXIS_YTILT, /**< Pen vertical tilt angle. Bidirectional: -90.0 to 90.0 (top-to-down). */
  132. SDL_PEN_AXIS_DISTANCE, /**< Pen distance to drawing surface. Unidirectional: 0.0 to 1.0 */
  133. SDL_PEN_AXIS_ROTATION, /**< Pen barrel rotation. Bidirectional: -180 to 179.9 (clockwise, 0 is facing up, -180.0 is facing down). */
  134. SDL_PEN_AXIS_SLIDER, /**< Pen finger wheel or slider (e.g., Airbrush Pen). Unidirectional: 0 to 1.0 */
  135. SDL_PEN_AXIS_TANGENTIAL_PRESSURE, /**< Pressure from squeezing the pen ("barrel pressure"). */
  136. SDL_PEN_AXIS_COUNT /**< Total known pen axis types in this version of SDL. This number may grow in future releases! */
  137. } SDL_PenAxis;
  138. /**
  139. * An enum that describes the type of a pen device.
  140. *
  141. * A "direct" device is a pen that touches a graphic display (like an Apple
  142. * Pencil on an iPad's screen). "Indirect" devices touch an external tablet
  143. * surface that is connected to the machine but is not a display (like a
  144. * lower-end Wacom tablet connected over USB).
  145. *
  146. * Apps may use this information to decide if they should draw a cursor; if
  147. * the pen is touching the screen directly, a cursor doesn't make sense and
  148. * can be in the way, but becomes necessary for indirect devices to know where
  149. * on the display they are interacting.
  150. *
  151. * \since This enum is available since SDL 3.4.0.
  152. */
  153. typedef enum SDL_PenDeviceType
  154. {
  155. SDL_PEN_DEVICE_TYPE_INVALID = -1, /**< Not a valid pen device. */
  156. SDL_PEN_DEVICE_TYPE_UNKNOWN, /**< Don't know specifics of this pen. */
  157. SDL_PEN_DEVICE_TYPE_DIRECT, /**< Pen touches display. */
  158. SDL_PEN_DEVICE_TYPE_INDIRECT /**< Pen touches something that isn't the display. */
  159. } SDL_PenDeviceType;
  160. /**
  161. * Get the device type of the given pen.
  162. *
  163. * Many platforms do not supply this information, so an app must always be
  164. * prepared to get an SDL_PEN_DEVICE_TYPE_UNKNOWN result.
  165. *
  166. * \param instance_id the pen instance ID.
  167. * \returns the device type of the given pen, or SDL_PEN_DEVICE_TYPE_INVALID
  168. * on failure; call SDL_GetError() for more information.
  169. *
  170. * \threadsafety It is safe to call this function from any thread.
  171. *
  172. * \since This function is available since SDL 3.4.0.
  173. */
  174. extern SDL_DECLSPEC SDL_PenDeviceType SDLCALL SDL_GetPenDeviceType(SDL_PenID instance_id);
  175. /* Ends C function definitions when using C++ */
  176. #ifdef __cplusplus
  177. }
  178. #endif
  179. #include <SDL3/SDL_close_code.h>
  180. #endif /* SDL_pen_h_ */