1 | /* |
2 | Simple DirectMedia Layer |
3 | Copyright (C) 1997-2025 Sam Lantinga <slouken@libsdl.org> |
4 | |
5 | This software is provided 'as-is', without any express or implied |
6 | warranty. In no event will the authors be held liable for any damages |
7 | arising from the use of this software. |
8 | |
9 | Permission is granted to anyone to use this software for any purpose, |
10 | including commercial applications, and to alter it and redistribute it |
11 | freely, subject to the following restrictions: |
12 | |
13 | 1. The origin of this software must not be misrepresented; you must not |
14 | claim that you wrote the original software. If you use this software |
15 | in a product, an acknowledgment in the product documentation would be |
16 | appreciated but is not required. |
17 | 2. Altered source versions must be plainly marked as such, and must not be |
18 | misrepresented as being the original software. |
19 | 3. This notice may not be removed or altered from any source distribution. |
20 | */ |
21 | #include "SDL_internal.h" |
22 | |
23 | #ifndef SDL_mouse_c_h_ |
24 | #define SDL_mouse_c_h_ |
25 | |
26 | // Mouse events not associated with a specific input device |
27 | #define SDL_GLOBAL_MOUSE_ID 0 |
28 | |
29 | // The default mouse input device, for platforms that don't have multiple mice |
30 | #define SDL_DEFAULT_MOUSE_ID 1 |
31 | |
32 | typedef struct SDL_CursorData SDL_CursorData; |
33 | |
34 | struct SDL_Cursor |
35 | { |
36 | struct SDL_Cursor *next; |
37 | SDL_CursorData *internal; |
38 | }; |
39 | |
40 | typedef struct |
41 | { |
42 | Uint64 last_timestamp; |
43 | double click_motion_x; |
44 | double click_motion_y; |
45 | Uint8 click_count; |
46 | } SDL_MouseClickState; |
47 | |
48 | typedef struct |
49 | { |
50 | SDL_MouseID mouseID; |
51 | Uint32 buttonstate; |
52 | |
53 | // Data for double-click tracking |
54 | int num_clickstates; |
55 | SDL_MouseClickState *clickstate; |
56 | } SDL_MouseInputSource; |
57 | |
58 | typedef struct |
59 | { |
60 | // Create a cursor from a surface |
61 | SDL_Cursor *(*CreateCursor)(SDL_Surface *surface, int hot_x, int hot_y); |
62 | |
63 | // Create a system cursor |
64 | SDL_Cursor *(*CreateSystemCursor)(SDL_SystemCursor id); |
65 | |
66 | // Show the specified cursor, or hide if cursor is NULL |
67 | bool (*ShowCursor)(SDL_Cursor *cursor); |
68 | |
69 | // This is called when a mouse motion event occurs |
70 | bool (*MoveCursor)(SDL_Cursor *cursor); |
71 | |
72 | // Free a window manager cursor |
73 | void (*FreeCursor)(SDL_Cursor *cursor); |
74 | |
75 | // Warp the mouse to (x,y) within a window |
76 | bool (*WarpMouse)(SDL_Window *window, float x, float y); |
77 | |
78 | // Warp the mouse to (x,y) in screen space |
79 | bool (*WarpMouseGlobal)(float x, float y); |
80 | |
81 | // Set relative mode |
82 | bool (*SetRelativeMouseMode)(bool enabled); |
83 | |
84 | // Set mouse capture |
85 | bool (*CaptureMouse)(SDL_Window *window); |
86 | |
87 | // Get absolute mouse coordinates. (x) and (y) are never NULL and set to zero before call. |
88 | SDL_MouseButtonFlags (*GetGlobalMouseState)(float *x, float *y); |
89 | |
90 | // Platform-specific system mouse transform applied in relative mode |
91 | SDL_MouseMotionTransformCallback ApplySystemScale; |
92 | void *system_scale_data; |
93 | |
94 | // User-defined mouse input transform applied in relative mode |
95 | SDL_MouseMotionTransformCallback InputTransform; |
96 | void *input_transform_data; |
97 | |
98 | // Data common to all mice |
99 | SDL_Window *focus; |
100 | float x; |
101 | float y; |
102 | float x_accu; |
103 | float y_accu; |
104 | float last_x, last_y; // the last reported x and y coordinates |
105 | float xrel_frac; |
106 | float yrel_frac; |
107 | float wheel_x_frac; |
108 | float wheel_y_frac; |
109 | double click_motion_x; |
110 | double click_motion_y; |
111 | Uint8 integer_mode; |
112 | bool has_position; |
113 | bool relative_mode; |
114 | bool relative_mode_warp_motion; |
115 | bool relative_mode_cursor_visible; |
116 | bool relative_mode_center; |
117 | bool warp_emulation_hint; |
118 | bool warp_emulation_active; |
119 | bool warp_emulation_prohibited; |
120 | Uint64 last_center_warp_time_ns; |
121 | bool enable_normal_speed_scale; |
122 | float normal_speed_scale; |
123 | bool enable_relative_speed_scale; |
124 | float relative_speed_scale; |
125 | bool enable_relative_system_scale; |
126 | Uint32 double_click_time; |
127 | int double_click_radius; |
128 | bool touch_mouse_events; |
129 | bool mouse_touch_events; |
130 | bool pen_mouse_events; |
131 | bool pen_touch_events; |
132 | bool was_touch_mouse_events; // Was a touch-mouse event pending? |
133 | bool added_mouse_touch_device; // did we SDL_AddTouch() a virtual touch device for the mouse? |
134 | bool added_pen_touch_device; // did we SDL_AddTouch() a virtual touch device for pens? |
135 | #ifdef SDL_PLATFORM_VITA |
136 | Uint8 vita_touch_mouse_device; |
137 | #endif |
138 | bool auto_capture; |
139 | bool capture_desired; |
140 | SDL_Window *capture_window; |
141 | |
142 | // Data for input source state |
143 | int num_sources; |
144 | SDL_MouseInputSource *sources; |
145 | |
146 | SDL_Cursor *cursors; |
147 | SDL_Cursor *def_cursor; |
148 | SDL_Cursor *cur_cursor; |
149 | bool cursor_shown; |
150 | |
151 | // Driver-dependent data. |
152 | void *internal; |
153 | } SDL_Mouse; |
154 | |
155 | // Initialize the mouse subsystem, called before the main video driver is initialized |
156 | extern bool SDL_PreInitMouse(void); |
157 | |
158 | // Finish initializing the mouse subsystem, called after the main video driver was initialized |
159 | extern void SDL_PostInitMouse(void); |
160 | |
161 | // Return whether a device is actually a mouse |
162 | extern bool SDL_IsMouse(Uint16 vendor, Uint16 product); |
163 | |
164 | // A mouse has been added to the system |
165 | extern void SDL_AddMouse(SDL_MouseID mouseID, const char *name, bool send_event); |
166 | |
167 | // A mouse has been removed from the system |
168 | extern void SDL_RemoveMouse(SDL_MouseID mouseID, bool send_event); |
169 | |
170 | // Get the mouse state structure |
171 | extern SDL_Mouse *SDL_GetMouse(void); |
172 | |
173 | // Set the default mouse cursor |
174 | extern void SDL_SetDefaultCursor(SDL_Cursor *cursor); |
175 | |
176 | // Get the preferred default system cursor |
177 | extern SDL_SystemCursor SDL_GetDefaultSystemCursor(void); |
178 | |
179 | // Set the mouse focus window |
180 | extern void SDL_SetMouseFocus(SDL_Window *window); |
181 | |
182 | // Update the mouse capture window |
183 | extern bool SDL_UpdateMouseCapture(bool force_release); |
184 | |
185 | // Send a mouse motion event |
186 | extern void SDL_SendMouseMotion(Uint64 timestamp, SDL_Window *window, SDL_MouseID mouseID, bool relative, float x, float y); |
187 | |
188 | // Send a mouse button event |
189 | extern void SDL_SendMouseButton(Uint64 timestamp, SDL_Window *window, SDL_MouseID mouseID, Uint8 button, bool down); |
190 | |
191 | // Send a mouse button event with a click count |
192 | extern void SDL_SendMouseButtonClicks(Uint64 timestamp, SDL_Window *window, SDL_MouseID mouseID, Uint8 button, bool down, int clicks); |
193 | |
194 | // Send a mouse wheel event |
195 | extern void SDL_SendMouseWheel(Uint64 timestamp, SDL_Window *window, SDL_MouseID mouseID, float x, float y, SDL_MouseWheelDirection direction); |
196 | |
197 | // Warp the mouse within the window, potentially overriding relative mode |
198 | extern void SDL_PerformWarpMouseInWindow(SDL_Window *window, float x, float y, bool ignore_relative_mode); |
199 | |
200 | // Relative mouse mode |
201 | extern bool SDL_SetRelativeMouseMode(bool enabled); |
202 | extern bool SDL_GetRelativeMouseMode(void); |
203 | extern void SDL_UpdateRelativeMouseMode(void); |
204 | extern void SDL_DisableMouseWarpEmulation(void); |
205 | |
206 | // TODO RECONNECT: Set mouse state to "zero" |
207 | #if 0 |
208 | extern void SDL_ResetMouse(void); |
209 | #endif // 0 |
210 | |
211 | // Check if mouse position is within window or captured by window |
212 | extern bool SDL_MousePositionInWindow(SDL_Window *window, float x, float y); |
213 | |
214 | // Shutdown the mouse subsystem |
215 | extern void SDL_QuitMouse(void); |
216 | |
217 | #endif // SDL_mouse_c_h_ |
218 | |