SDL_touch.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. /*
  2. Simple DirectMedia Layer
  3. Copyright (C) 1997-2024 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. * \file SDL_touch.h
  20. *
  21. * Include file for SDL touch event handling.
  22. */
  23. #ifndef SDL_touch_h_
  24. #define SDL_touch_h_
  25. #include <SDL3/SDL_stdinc.h>
  26. #include <SDL3/SDL_error.h>
  27. #include <SDL3/SDL_mouse.h>
  28. #include <SDL3/SDL_video.h>
  29. #include <SDL3/SDL_begin_code.h>
  30. /* Set up for C function definitions, even when using C++ */
  31. #ifdef __cplusplus
  32. extern "C" {
  33. #endif
  34. typedef Uint64 SDL_TouchID;
  35. typedef Uint64 SDL_FingerID;
  36. typedef enum
  37. {
  38. SDL_TOUCH_DEVICE_INVALID = -1,
  39. SDL_TOUCH_DEVICE_DIRECT, /* touch screen with window-relative coordinates */
  40. SDL_TOUCH_DEVICE_INDIRECT_ABSOLUTE, /* trackpad with absolute device coordinates */
  41. SDL_TOUCH_DEVICE_INDIRECT_RELATIVE /* trackpad with screen cursor-relative coordinates */
  42. } SDL_TouchDeviceType;
  43. /**
  44. * Data about a single finger in a multitouch event.
  45. *
  46. * Each touch even is a collection of fingers that are simultaneously in
  47. * contact with the touch device (so a "touch" can be a "multitouch," in
  48. * reality), and this struct reports details of the specific fingers.
  49. *
  50. * \since This struct is available since SDL 3.0.0.
  51. *
  52. * \sa SDL_GetTouchFinger
  53. */
  54. typedef struct SDL_Finger
  55. {
  56. SDL_FingerID id; /**< the finger ID */
  57. float x; /**< the x-axis location of the touch event, normalized (0...1) */
  58. float y; /**< the y-axis location of the touch event, normalized (0...1) */
  59. float pressure; /**< the quantity of pressure applied, normalized (0...1) */
  60. } SDL_Finger;
  61. /* Used as the device ID for mouse events simulated with touch input */
  62. #define SDL_TOUCH_MOUSEID ((SDL_MouseID)-1)
  63. /* Used as the SDL_TouchID for touch events simulated with mouse input */
  64. #define SDL_MOUSE_TOUCHID ((SDL_TouchID)-1)
  65. /**
  66. * Get a list of registered touch devices.
  67. *
  68. * On some platforms SDL first sees the touch device if it was actually used.
  69. * Therefore the returned list might be empty, although devices are available.
  70. * After using all devices at least once the number will be correct.
  71. *
  72. * This was fixed for Android in SDL 2.0.1.
  73. *
  74. * \param count a pointer filled in with the number of devices returned, can
  75. * be NULL.
  76. * \returns a 0 terminated array of touch device IDs which should be freed
  77. * with SDL_free(), or NULL on error; call SDL_GetError() for more
  78. * details.
  79. *
  80. * \since This function is available since SDL 3.0.0.
  81. */
  82. extern DECLSPEC SDL_TouchID *SDLCALL SDL_GetTouchDevices(int *count);
  83. /**
  84. * Get the touch device name as reported from the driver.
  85. *
  86. * You do not own the returned string, do not modify or free it.
  87. *
  88. * \param touchID the touch device instance ID.
  89. * \returns touch device name, or NULL on error; call SDL_GetError() for more
  90. * details.
  91. *
  92. * \since This function is available since SDL 3.0.0.
  93. */
  94. extern DECLSPEC const char* SDLCALL SDL_GetTouchDeviceName(SDL_TouchID touchID);
  95. /**
  96. * Get the type of the given touch device.
  97. *
  98. * \param touchID the ID of a touch device
  99. * \returns touch device type
  100. *
  101. * \since This function is available since SDL 3.0.0.
  102. */
  103. extern DECLSPEC SDL_TouchDeviceType SDLCALL SDL_GetTouchDeviceType(SDL_TouchID touchID);
  104. /**
  105. * Get the number of active fingers for a given touch device.
  106. *
  107. * \param touchID the ID of a touch device
  108. * \returns the number of active fingers for a given touch device on success
  109. * or a negative error code on failure; call SDL_GetError() for more
  110. * information.
  111. *
  112. * \since This function is available since SDL 3.0.0.
  113. *
  114. * \sa SDL_GetTouchFinger
  115. */
  116. extern DECLSPEC int SDLCALL SDL_GetNumTouchFingers(SDL_TouchID touchID);
  117. /**
  118. * Get the finger object for specified touch device ID and finger index.
  119. *
  120. * The returned resource is owned by SDL and should not be deallocated.
  121. *
  122. * \param touchID the ID of the requested touch device
  123. * \param index the index of the requested finger
  124. * \returns a pointer to the SDL_Finger object or NULL if no object at the
  125. * given ID and index could be found.
  126. *
  127. * \since This function is available since SDL 3.0.0.
  128. *
  129. * \sa SDL_GetNumTouchFingers
  130. */
  131. extern DECLSPEC SDL_Finger * SDLCALL SDL_GetTouchFinger(SDL_TouchID touchID, int index);
  132. /* Ends C function definitions when using C++ */
  133. #ifdef __cplusplus
  134. }
  135. #endif
  136. #include <SDL3/SDL_close_code.h>
  137. #endif /* SDL_touch_h_ */