SDL_pen.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. /*
  2. Simple DirectMedia Layer
  3. Copyright (C) 1997-2024 Sam Lantinga <slouken@libsdl.org>
  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 SDL_EVENT_PEN_* events. When a pen
  28. * starts providing input, SDL will assign it a unique SDL_PenID, which will
  29. * remain for the life of the process, as long as the pen stays connected.
  30. *
  31. * Pens may provide more than simple touch input; they might have other axes,
  32. * such as pressure, tilt, rotation, etc.
  33. */
  34. #ifndef SDL_pen_h_
  35. #define SDL_pen_h_
  36. #include <SDL3/SDL_stdinc.h>
  37. /* Set up for C function definitions, even when using C++ */
  38. #ifdef __cplusplus
  39. extern "C" {
  40. #endif
  41. /**
  42. * SDL pen instance IDs.
  43. *
  44. * Zero is used to signify an invalid/null device.
  45. *
  46. * These show up in pen events when SDL sees input from them. They remain
  47. * consistent as long as SDL can recognize a tool to be the same pen; but if a
  48. * pen physically leaves the area and returns, it might get a new ID.
  49. *
  50. * \since This datatype is available since SDL 3.0.0.
  51. */
  52. typedef Uint32 SDL_PenID;
  53. /**
  54. * Pen input flags, as reported by various pen events' `pen_state` field.
  55. *
  56. * \since This datatype is available since SDL 3.0.0.
  57. */
  58. typedef Uint32 SDL_PenInputFlags;
  59. #define SDL_PEN_INPUT_DOWN (1u << 0) /**< pen is pressed down */
  60. #define SDL_PEN_INPUT_BUTTON_1 (1u << 1) /**< button 1 is pressed */
  61. #define SDL_PEN_INPUT_BUTTON_2 (1u << 2) /**< button 2 is pressed */
  62. #define SDL_PEN_INPUT_BUTTON_3 (1u << 3) /**< button 3 is pressed */
  63. #define SDL_PEN_INPUT_BUTTON_4 (1u << 4) /**< button 4 is pressed */
  64. #define SDL_PEN_INPUT_BUTTON_5 (1u << 5) /**< button 5 is pressed */
  65. #define SDL_PEN_INPUT_ERASER_TIP (1u << 30) /**< eraser tip is used */
  66. /**
  67. * Pen axis indices.
  68. *
  69. * These are the valid values for the `axis` field in SDL_PenAxisEvent. All
  70. * axes are either normalised to 0..1 or report a (positive or negative) angle
  71. * in degrees, with 0.0 representing the centre. Not all pens/backends support
  72. * all axes: unsupported axes are always zero.
  73. *
  74. * To convert angles for tilt and rotation into vector representation, use
  75. * SDL_sinf on the XTILT, YTILT, or ROTATION component, for example:
  76. *
  77. * `SDL_sinf(xtilt * SDL_PI_F / 180.0)`.
  78. *
  79. * \since This enum is available since SDL 3.0.0
  80. */
  81. typedef enum SDL_PenAxis
  82. {
  83. SDL_PEN_AXIS_PRESSURE, /**< Pen pressure. Unidirectional: 0 to 1.0 */
  84. SDL_PEN_AXIS_XTILT, /**< Pen horizontal tilt angle. Bidirectional: -90.0 to 90.0 (left-to-right). */
  85. SDL_PEN_AXIS_YTILT, /**< Pen vertical tilt angle. Bidirectional: -90.0 to 90.0 (top-to-down). */
  86. SDL_PEN_AXIS_DISTANCE, /**< Pen distance to drawing surface. Unidirectional: 0.0 to 1.0 */
  87. SDL_PEN_AXIS_ROTATION, /**< Pen barrel rotation. Bidirectional: -180 to 179.9 (clockwise, 0 is facing up, -180.0 is facing down). */
  88. SDL_PEN_AXIS_SLIDER, /**< Pen finger wheel or slider (e.g., Airbrush Pen). Unidirectional: 0 to 1.0 */
  89. SDL_PEN_AXIS_TANGENTIAL_PRESSURE, /**< Pressure from squeezing the pen ("barrel pressure"). */
  90. SDL_PEN_AXIS_COUNT /**< Total known pen axis types in this version of SDL. This number may grow in future releases! */
  91. } SDL_PenAxis;
  92. /* Ends C function definitions when using C++ */
  93. #ifdef __cplusplus
  94. }
  95. #endif
  96. #endif /* SDL_pen_h_ */