SDL_mouse_c.h 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  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. #include "SDL_internal.h"
  19. #ifndef SDL_mouse_c_h_
  20. #define SDL_mouse_c_h_
  21. // Mouse events not associated with a specific input device
  22. #define SDL_GLOBAL_MOUSE_ID 0
  23. // The default mouse input device, for platforms that don't have multiple mice
  24. #define SDL_DEFAULT_MOUSE_ID 1
  25. typedef struct SDL_CursorData SDL_CursorData;
  26. struct SDL_Cursor
  27. {
  28. struct SDL_Cursor *next;
  29. SDL_CursorData *internal;
  30. };
  31. typedef struct
  32. {
  33. Uint64 last_timestamp;
  34. double click_motion_x;
  35. double click_motion_y;
  36. Uint8 click_count;
  37. } SDL_MouseClickState;
  38. typedef struct
  39. {
  40. SDL_MouseID mouseID;
  41. Uint32 buttonstate;
  42. // Data for double-click tracking
  43. int num_clickstates;
  44. SDL_MouseClickState *clickstate;
  45. } SDL_MouseInputSource;
  46. typedef struct
  47. {
  48. // Create a cursor from a surface
  49. SDL_Cursor *(*CreateCursor)(SDL_Surface *surface, int hot_x, int hot_y);
  50. // Create a system cursor
  51. SDL_Cursor *(*CreateSystemCursor)(SDL_SystemCursor id);
  52. // Show the specified cursor, or hide if cursor is NULL
  53. bool (*ShowCursor)(SDL_Cursor *cursor);
  54. // This is called when a mouse motion event occurs
  55. bool (*MoveCursor)(SDL_Cursor *cursor);
  56. // Free a window manager cursor
  57. void (*FreeCursor)(SDL_Cursor *cursor);
  58. // Warp the mouse to (x,y) within a window
  59. bool (*WarpMouse)(SDL_Window *window, float x, float y);
  60. // Warp the mouse to (x,y) in screen space
  61. bool (*WarpMouseGlobal)(float x, float y);
  62. // Set relative mode
  63. bool (*SetRelativeMouseMode)(bool enabled);
  64. // Set mouse capture
  65. bool (*CaptureMouse)(SDL_Window *window);
  66. // Get absolute mouse coordinates. (x) and (y) are never NULL and set to zero before call.
  67. SDL_MouseButtonFlags (*GetGlobalMouseState)(float *x, float *y);
  68. // Platform-specific system mouse transform
  69. void (*ApplySystemScale)(void *internal, Uint64 timestamp, SDL_Window *window, SDL_MouseID mouseID, float *x, float *y);
  70. void *system_scale_data;
  71. // integer mode data
  72. Uint8 integer_mode_flags; // 1 to enable mouse quantization, 2 to enable wheel quantization
  73. float integer_mode_residual_motion_x;
  74. float integer_mode_residual_motion_y;
  75. // Data common to all mice
  76. SDL_Window *focus;
  77. float x;
  78. float y;
  79. float x_accu;
  80. float y_accu;
  81. float last_x, last_y; // the last reported x and y coordinates
  82. float residual_scroll_x;
  83. float residual_scroll_y;
  84. double click_motion_x;
  85. double click_motion_y;
  86. bool has_position;
  87. bool relative_mode;
  88. bool relative_mode_warp_motion;
  89. bool relative_mode_cursor_visible;
  90. bool relative_mode_center;
  91. bool warp_emulation_hint;
  92. bool warp_emulation_active;
  93. bool warp_emulation_prohibited;
  94. Uint64 last_center_warp_time_ns;
  95. bool enable_normal_speed_scale;
  96. float normal_speed_scale;
  97. bool enable_relative_speed_scale;
  98. float relative_speed_scale;
  99. bool enable_relative_system_scale;
  100. Uint32 double_click_time;
  101. int double_click_radius;
  102. bool touch_mouse_events;
  103. bool mouse_touch_events;
  104. bool pen_mouse_events;
  105. bool pen_touch_events;
  106. bool was_touch_mouse_events; // Was a touch-mouse event pending?
  107. bool added_mouse_touch_device; // did we SDL_AddTouch() a virtual touch device for the mouse?
  108. bool added_pen_touch_device; // did we SDL_AddTouch() a virtual touch device for pens?
  109. #ifdef SDL_PLATFORM_VITA
  110. Uint8 vita_touch_mouse_device;
  111. #endif
  112. bool auto_capture;
  113. bool capture_desired;
  114. SDL_Window *capture_window;
  115. // Data for input source state
  116. int num_sources;
  117. SDL_MouseInputSource *sources;
  118. SDL_Cursor *cursors;
  119. SDL_Cursor *def_cursor;
  120. SDL_Cursor *cur_cursor;
  121. bool cursor_shown;
  122. // Driver-dependent data.
  123. void *internal;
  124. } SDL_Mouse;
  125. // Initialize the mouse subsystem, called before the main video driver is initialized
  126. extern bool SDL_PreInitMouse(void);
  127. // Finish initializing the mouse subsystem, called after the main video driver was initialized
  128. extern void SDL_PostInitMouse(void);
  129. // Return whether a device is actually a mouse
  130. extern bool SDL_IsMouse(Uint16 vendor, Uint16 product);
  131. // A mouse has been added to the system
  132. extern void SDL_AddMouse(SDL_MouseID mouseID, const char *name, bool send_event);
  133. // A mouse has been removed from the system
  134. extern void SDL_RemoveMouse(SDL_MouseID mouseID, bool send_event);
  135. // Get the mouse state structure
  136. extern SDL_Mouse *SDL_GetMouse(void);
  137. // Set the default mouse cursor
  138. extern void SDL_SetDefaultCursor(SDL_Cursor *cursor);
  139. // Get the preferred default system cursor
  140. extern SDL_SystemCursor SDL_GetDefaultSystemCursor(void);
  141. // Set the mouse focus window
  142. extern void SDL_SetMouseFocus(SDL_Window *window);
  143. // Update the mouse capture window
  144. extern bool SDL_UpdateMouseCapture(bool force_release);
  145. // Send a mouse motion event
  146. extern void SDL_SendMouseMotion(Uint64 timestamp, SDL_Window *window, SDL_MouseID mouseID, bool relative, float x, float y);
  147. // Send a mouse button event
  148. extern void SDL_SendMouseButton(Uint64 timestamp, SDL_Window *window, SDL_MouseID mouseID, Uint8 button, bool down);
  149. // Send a mouse button event with a click count
  150. extern void SDL_SendMouseButtonClicks(Uint64 timestamp, SDL_Window *window, SDL_MouseID mouseID, Uint8 button, bool down, int clicks);
  151. // Send a mouse wheel event
  152. extern void SDL_SendMouseWheel(Uint64 timestamp, SDL_Window *window, SDL_MouseID mouseID, float x, float y, SDL_MouseWheelDirection direction);
  153. // Warp the mouse within the window, potentially overriding relative mode
  154. extern void SDL_PerformWarpMouseInWindow(SDL_Window *window, float x, float y, bool ignore_relative_mode);
  155. // Relative mouse mode
  156. extern bool SDL_SetRelativeMouseMode(bool enabled);
  157. extern bool SDL_GetRelativeMouseMode(void);
  158. extern void SDL_UpdateRelativeMouseMode(void);
  159. extern void SDL_DisableMouseWarpEmulation(void);
  160. // TODO RECONNECT: Set mouse state to "zero"
  161. #if 0
  162. extern void SDL_ResetMouse(void);
  163. #endif // 0
  164. // Check if mouse position is within window or captured by window
  165. extern bool SDL_MousePositionInWindow(SDL_Window *window, float x, float y);
  166. // Shutdown the mouse subsystem
  167. extern void SDL_QuitMouse(void);
  168. #endif // SDL_mouse_c_h_