| 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 | |
| 22 | /** |
| 23 | * # CategoryMouse |
| 24 | * |
| 25 | * Any GUI application has to deal with the mouse, and SDL provides functions |
| 26 | * to manage mouse input and the displayed cursor. |
| 27 | * |
| 28 | * Most interactions with the mouse will come through the event subsystem. |
| 29 | * Moving a mouse generates an SDL_EVENT_MOUSE_MOTION event, pushing a button |
| 30 | * generates SDL_EVENT_MOUSE_BUTTON_DOWN, etc, but one can also query the |
| 31 | * current state of the mouse at any time with SDL_GetMouseState(). |
| 32 | * |
| 33 | * For certain games, it's useful to disassociate the mouse cursor from mouse |
| 34 | * input. An FPS, for example, would not want the player's motion to stop as |
| 35 | * the mouse hits the edge of the window. For these scenarios, use |
| 36 | * SDL_SetWindowRelativeMouseMode(), which hides the cursor, grabs mouse input |
| 37 | * to the window, and reads mouse input no matter how far it moves. |
| 38 | * |
| 39 | * Games that want the system to track the mouse but want to draw their own |
| 40 | * cursor can use SDL_HideCursor() and SDL_ShowCursor(). It might be more |
| 41 | * efficient to let the system manage the cursor, if possible, using |
| 42 | * SDL_SetCursor() with a custom image made through SDL_CreateColorCursor(), |
| 43 | * or perhaps just a specific system cursor from SDL_CreateSystemCursor(). |
| 44 | * |
| 45 | * SDL can, on many platforms, differentiate between multiple connected mice, |
| 46 | * allowing for interesting input scenarios and multiplayer games. They can be |
| 47 | * enumerated with SDL_GetMice(), and SDL will send SDL_EVENT_MOUSE_ADDED and |
| 48 | * SDL_EVENT_MOUSE_REMOVED events as they are connected and unplugged. |
| 49 | * |
| 50 | * Since many apps only care about basic mouse input, SDL offers a virtual |
| 51 | * mouse device for touch and pen input, which often can make a desktop |
| 52 | * application work on a touchscreen phone without any code changes. Apps that |
| 53 | * care about touch/pen separately from mouse input should filter out events |
| 54 | * with a `which` field of SDL_TOUCH_MOUSEID/SDL_PEN_MOUSEID. |
| 55 | */ |
| 56 | |
| 57 | #ifndef SDL_mouse_h_ |
| 58 | #define SDL_mouse_h_ |
| 59 | |
| 60 | #include <SDL3/SDL_stdinc.h> |
| 61 | #include <SDL3/SDL_error.h> |
| 62 | #include <SDL3/SDL_surface.h> |
| 63 | #include <SDL3/SDL_video.h> |
| 64 | |
| 65 | #include <SDL3/SDL_begin_code.h> |
| 66 | /* Set up for C function definitions, even when using C++ */ |
| 67 | #ifdef __cplusplus |
| 68 | extern "C" { |
| 69 | #endif |
| 70 | |
| 71 | /** |
| 72 | * This is a unique ID for a mouse for the time it is connected to the system, |
| 73 | * and is never reused for the lifetime of the application. |
| 74 | * |
| 75 | * If the mouse is disconnected and reconnected, it will get a new ID. |
| 76 | * |
| 77 | * The value 0 is an invalid ID. |
| 78 | * |
| 79 | * \since This datatype is available since SDL 3.2.0. |
| 80 | */ |
| 81 | typedef Uint32 SDL_MouseID; |
| 82 | |
| 83 | /** |
| 84 | * The structure used to identify an SDL cursor. |
| 85 | * |
| 86 | * This is opaque data. |
| 87 | * |
| 88 | * \since This struct is available since SDL 3.2.0. |
| 89 | */ |
| 90 | typedef struct SDL_Cursor SDL_Cursor; |
| 91 | |
| 92 | /** |
| 93 | * Cursor types for SDL_CreateSystemCursor(). |
| 94 | * |
| 95 | * \since This enum is available since SDL 3.2.0. |
| 96 | */ |
| 97 | typedef enum SDL_SystemCursor |
| 98 | { |
| 99 | SDL_SYSTEM_CURSOR_DEFAULT, /**< Default cursor. Usually an arrow. */ |
| 100 | SDL_SYSTEM_CURSOR_TEXT, /**< Text selection. Usually an I-beam. */ |
| 101 | SDL_SYSTEM_CURSOR_WAIT, /**< Wait. Usually an hourglass or watch or spinning ball. */ |
| 102 | SDL_SYSTEM_CURSOR_CROSSHAIR, /**< Crosshair. */ |
| 103 | SDL_SYSTEM_CURSOR_PROGRESS, /**< Program is busy but still interactive. Usually it's WAIT with an arrow. */ |
| 104 | SDL_SYSTEM_CURSOR_NWSE_RESIZE, /**< Double arrow pointing northwest and southeast. */ |
| 105 | SDL_SYSTEM_CURSOR_NESW_RESIZE, /**< Double arrow pointing northeast and southwest. */ |
| 106 | SDL_SYSTEM_CURSOR_EW_RESIZE, /**< Double arrow pointing west and east. */ |
| 107 | SDL_SYSTEM_CURSOR_NS_RESIZE, /**< Double arrow pointing north and south. */ |
| 108 | SDL_SYSTEM_CURSOR_MOVE, /**< Four pointed arrow pointing north, south, east, and west. */ |
| 109 | SDL_SYSTEM_CURSOR_NOT_ALLOWED, /**< Not permitted. Usually a slashed circle or crossbones. */ |
| 110 | SDL_SYSTEM_CURSOR_POINTER, /**< Pointer that indicates a link. Usually a pointing hand. */ |
| 111 | SDL_SYSTEM_CURSOR_NW_RESIZE, /**< Window resize top-left. This may be a single arrow or a double arrow like NWSE_RESIZE. */ |
| 112 | SDL_SYSTEM_CURSOR_N_RESIZE, /**< Window resize top. May be NS_RESIZE. */ |
| 113 | SDL_SYSTEM_CURSOR_NE_RESIZE, /**< Window resize top-right. May be NESW_RESIZE. */ |
| 114 | SDL_SYSTEM_CURSOR_E_RESIZE, /**< Window resize right. May be EW_RESIZE. */ |
| 115 | SDL_SYSTEM_CURSOR_SE_RESIZE, /**< Window resize bottom-right. May be NWSE_RESIZE. */ |
| 116 | SDL_SYSTEM_CURSOR_S_RESIZE, /**< Window resize bottom. May be NS_RESIZE. */ |
| 117 | SDL_SYSTEM_CURSOR_SW_RESIZE, /**< Window resize bottom-left. May be NESW_RESIZE. */ |
| 118 | SDL_SYSTEM_CURSOR_W_RESIZE, /**< Window resize left. May be EW_RESIZE. */ |
| 119 | SDL_SYSTEM_CURSOR_COUNT |
| 120 | } SDL_SystemCursor; |
| 121 | |
| 122 | /** |
| 123 | * Scroll direction types for the Scroll event |
| 124 | * |
| 125 | * \since This enum is available since SDL 3.2.0. |
| 126 | */ |
| 127 | typedef enum SDL_MouseWheelDirection |
| 128 | { |
| 129 | SDL_MOUSEWHEEL_NORMAL, /**< The scroll direction is normal */ |
| 130 | SDL_MOUSEWHEEL_FLIPPED /**< The scroll direction is flipped / natural */ |
| 131 | } SDL_MouseWheelDirection; |
| 132 | |
| 133 | /** |
| 134 | * A bitmask of pressed mouse buttons, as reported by SDL_GetMouseState, etc. |
| 135 | * |
| 136 | * - Button 1: Left mouse button |
| 137 | * - Button 2: Middle mouse button |
| 138 | * - Button 3: Right mouse button |
| 139 | * - Button 4: Side mouse button 1 |
| 140 | * - Button 5: Side mouse button 2 |
| 141 | * |
| 142 | * \since This datatype is available since SDL 3.2.0. |
| 143 | * |
| 144 | * \sa SDL_GetMouseState |
| 145 | * \sa SDL_GetGlobalMouseState |
| 146 | * \sa SDL_GetRelativeMouseState |
| 147 | */ |
| 148 | typedef Uint32 SDL_MouseButtonFlags; |
| 149 | |
| 150 | /** |
| 151 | * A callback used to transform mouse motion delta from raw values. |
| 152 | * |
| 153 | * This is called during SDL's handling of platform mouse events to scale the |
| 154 | * values of the resulting motion delta. |
| 155 | * |
| 156 | * \param userdata what was passed as `userdata` to |
| 157 | * SDL_SetRelativeMouseTransform(). |
| 158 | * \param timestamp the associated time at which this mouse motion event was |
| 159 | * received. |
| 160 | * \param window the associated window to which this mouse motion event was |
| 161 | * addressed. |
| 162 | * \param mouseID the associated mouse from which this mouse motion event was |
| 163 | * emitted. |
| 164 | * \param x pointer to a variable that will be treated as the resulting x-axis |
| 165 | * motion. |
| 166 | * \param y pointer to a variable that will be treated as the resulting y-axis |
| 167 | * motion. |
| 168 | * |
| 169 | * \threadsafety This callback is called by SDL's internal mouse input |
| 170 | * processing procedure, which may be a thread separate from the |
| 171 | * main event loop that is run at realtime priority. Stalling |
| 172 | * this thread with too much work in the callback can therefore |
| 173 | * potentially freeze the entire system. Care should be taken |
| 174 | * with proper synchronization practices when adding other side |
| 175 | * effects beyond mutation of the x and y values. |
| 176 | * |
| 177 | * \since This datatype is available since SDL 3.2.6. |
| 178 | * |
| 179 | * \sa SDL_SetRelativeMouseTransform |
| 180 | */ |
| 181 | typedef void (SDLCALL *SDL_MouseMotionTransformCallback)( |
| 182 | void *userdata, |
| 183 | Uint64 timestamp, |
| 184 | SDL_Window *window, |
| 185 | SDL_MouseID mouseID, |
| 186 | float *x, float *y |
| 187 | ); |
| 188 | |
| 189 | #define SDL_BUTTON_LEFT 1 |
| 190 | #define SDL_BUTTON_MIDDLE 2 |
| 191 | #define SDL_BUTTON_RIGHT 3 |
| 192 | #define SDL_BUTTON_X1 4 |
| 193 | #define SDL_BUTTON_X2 5 |
| 194 | |
| 195 | #define SDL_BUTTON_MASK(X) (1u << ((X)-1)) |
| 196 | #define SDL_BUTTON_LMASK SDL_BUTTON_MASK(SDL_BUTTON_LEFT) |
| 197 | #define SDL_BUTTON_MMASK SDL_BUTTON_MASK(SDL_BUTTON_MIDDLE) |
| 198 | #define SDL_BUTTON_RMASK SDL_BUTTON_MASK(SDL_BUTTON_RIGHT) |
| 199 | #define SDL_BUTTON_X1MASK SDL_BUTTON_MASK(SDL_BUTTON_X1) |
| 200 | #define SDL_BUTTON_X2MASK SDL_BUTTON_MASK(SDL_BUTTON_X2) |
| 201 | |
| 202 | |
| 203 | /* Function prototypes */ |
| 204 | |
| 205 | /** |
| 206 | * Return whether a mouse is currently connected. |
| 207 | * |
| 208 | * \returns true if a mouse is connected, false otherwise. |
| 209 | * |
| 210 | * \threadsafety This function should only be called on the main thread. |
| 211 | * |
| 212 | * \since This function is available since SDL 3.2.0. |
| 213 | * |
| 214 | * \sa SDL_GetMice |
| 215 | */ |
| 216 | extern SDL_DECLSPEC bool SDLCALL SDL_HasMouse(void); |
| 217 | |
| 218 | /** |
| 219 | * Get a list of currently connected mice. |
| 220 | * |
| 221 | * Note that this will include any device or virtual driver that includes |
| 222 | * mouse functionality, including some game controllers, KVM switches, etc. |
| 223 | * You should wait for input from a device before you consider it actively in |
| 224 | * use. |
| 225 | * |
| 226 | * \param count a pointer filled in with the number of mice returned, may be |
| 227 | * NULL. |
| 228 | * \returns a 0 terminated array of mouse instance IDs or NULL on failure; |
| 229 | * call SDL_GetError() for more information. This should be freed |
| 230 | * with SDL_free() when it is no longer needed. |
| 231 | * |
| 232 | * \threadsafety This function should only be called on the main thread. |
| 233 | * |
| 234 | * \since This function is available since SDL 3.2.0. |
| 235 | * |
| 236 | * \sa SDL_GetMouseNameForID |
| 237 | * \sa SDL_HasMouse |
| 238 | */ |
| 239 | extern SDL_DECLSPEC SDL_MouseID * SDLCALL SDL_GetMice(int *count); |
| 240 | |
| 241 | /** |
| 242 | * Get the name of a mouse. |
| 243 | * |
| 244 | * This function returns "" if the mouse doesn't have a name. |
| 245 | * |
| 246 | * \param instance_id the mouse instance ID. |
| 247 | * \returns the name of the selected mouse, or NULL on failure; call |
| 248 | * SDL_GetError() for more information. |
| 249 | * |
| 250 | * \threadsafety This function should only be called on the main thread. |
| 251 | * |
| 252 | * \since This function is available since SDL 3.2.0. |
| 253 | * |
| 254 | * \sa SDL_GetMice |
| 255 | */ |
| 256 | extern SDL_DECLSPEC const char * SDLCALL SDL_GetMouseNameForID(SDL_MouseID instance_id); |
| 257 | |
| 258 | /** |
| 259 | * Get the window which currently has mouse focus. |
| 260 | * |
| 261 | * \returns the window with mouse focus. |
| 262 | * |
| 263 | * \threadsafety This function should only be called on the main thread. |
| 264 | * |
| 265 | * \since This function is available since SDL 3.2.0. |
| 266 | */ |
| 267 | extern SDL_DECLSPEC SDL_Window * SDLCALL SDL_GetMouseFocus(void); |
| 268 | |
| 269 | /** |
| 270 | * Query SDL's cache for the synchronous mouse button state and the |
| 271 | * window-relative SDL-cursor position. |
| 272 | * |
| 273 | * This function returns the cached synchronous state as SDL understands it |
| 274 | * from the last pump of the event queue. |
| 275 | * |
| 276 | * To query the platform for immediate asynchronous state, use |
| 277 | * SDL_GetGlobalMouseState. |
| 278 | * |
| 279 | * Passing non-NULL pointers to `x` or `y` will write the destination with |
| 280 | * respective x or y coordinates relative to the focused window. |
| 281 | * |
| 282 | * In Relative Mode, the SDL-cursor's position usually contradicts the |
| 283 | * platform-cursor's position as manually calculated from |
| 284 | * SDL_GetGlobalMouseState() and SDL_GetWindowPosition. |
| 285 | * |
| 286 | * \param x a pointer to receive the SDL-cursor's x-position from the focused |
| 287 | * window's top left corner, can be NULL if unused. |
| 288 | * \param y a pointer to receive the SDL-cursor's y-position from the focused |
| 289 | * window's top left corner, can be NULL if unused. |
| 290 | * \returns a 32-bit bitmask of the button state that can be bitwise-compared |
| 291 | * against the SDL_BUTTON_MASK(X) macro. |
| 292 | * |
| 293 | * \threadsafety This function should only be called on the main thread. |
| 294 | * |
| 295 | * \since This function is available since SDL 3.2.0. |
| 296 | * |
| 297 | * \sa SDL_GetGlobalMouseState |
| 298 | * \sa SDL_GetRelativeMouseState |
| 299 | */ |
| 300 | extern SDL_DECLSPEC SDL_MouseButtonFlags SDLCALL SDL_GetMouseState(float *x, float *y); |
| 301 | |
| 302 | /** |
| 303 | * Query the platform for the asynchronous mouse button state and the |
| 304 | * desktop-relative platform-cursor position. |
| 305 | * |
| 306 | * This function immediately queries the platform for the most recent |
| 307 | * asynchronous state, more costly than retrieving SDL's cached state in |
| 308 | * SDL_GetMouseState(). |
| 309 | * |
| 310 | * Passing non-NULL pointers to `x` or `y` will write the destination with |
| 311 | * respective x or y coordinates relative to the desktop. |
| 312 | * |
| 313 | * In Relative Mode, the platform-cursor's position usually contradicts the |
| 314 | * SDL-cursor's position as manually calculated from SDL_GetMouseState() and |
| 315 | * SDL_GetWindowPosition. |
| 316 | * |
| 317 | * This function can be useful if you need to track the mouse outside of a |
| 318 | * specific window and SDL_CaptureMouse() doesn't fit your needs. For example, |
| 319 | * it could be useful if you need to track the mouse while dragging a window, |
| 320 | * where coordinates relative to a window might not be in sync at all times. |
| 321 | * |
| 322 | * \param x a pointer to receive the platform-cursor's x-position from the |
| 323 | * desktop's top left corner, can be NULL if unused. |
| 324 | * \param y a pointer to receive the platform-cursor's y-position from the |
| 325 | * desktop's top left corner, can be NULL if unused. |
| 326 | * \returns a 32-bit bitmask of the button state that can be bitwise-compared |
| 327 | * against the SDL_BUTTON_MASK(X) macro. |
| 328 | * |
| 329 | * \threadsafety This function should only be called on the main thread. |
| 330 | * |
| 331 | * \since This function is available since SDL 3.2.0. |
| 332 | * |
| 333 | * \sa SDL_CaptureMouse |
| 334 | * \sa SDL_GetMouseState |
| 335 | * \sa SDL_GetGlobalMouseState |
| 336 | */ |
| 337 | extern SDL_DECLSPEC SDL_MouseButtonFlags SDLCALL SDL_GetGlobalMouseState(float *x, float *y); |
| 338 | |
| 339 | /** |
| 340 | * Query SDL's cache for the synchronous mouse button state and accumulated |
| 341 | * mouse delta since last call. |
| 342 | * |
| 343 | * This function returns the cached synchronous state as SDL understands it |
| 344 | * from the last pump of the event queue. |
| 345 | * |
| 346 | * To query the platform for immediate asynchronous state, use |
| 347 | * SDL_GetGlobalMouseState. |
| 348 | * |
| 349 | * Passing non-NULL pointers to `x` or `y` will write the destination with |
| 350 | * respective x or y deltas accumulated since the last call to this function |
| 351 | * (or since event initialization). |
| 352 | * |
| 353 | * This function is useful for reducing overhead by processing relative mouse |
| 354 | * inputs in one go per-frame instead of individually per-event, at the |
| 355 | * expense of losing the order between events within the frame (e.g. quickly |
| 356 | * pressing and releasing a button within the same frame). |
| 357 | * |
| 358 | * \param x a pointer to receive the x mouse delta accumulated since last |
| 359 | * call, can be NULL if unused. |
| 360 | * \param y a pointer to receive the y mouse delta accumulated since last |
| 361 | * call, can be NULL if unused. |
| 362 | * \returns a 32-bit bitmask of the button state that can be bitwise-compared |
| 363 | * against the SDL_BUTTON_MASK(X) macro. |
| 364 | * |
| 365 | * \threadsafety This function should only be called on the main thread. |
| 366 | * |
| 367 | * \since This function is available since SDL 3.2.0. |
| 368 | * |
| 369 | * \sa SDL_GetMouseState |
| 370 | * \sa SDL_GetGlobalMouseState |
| 371 | */ |
| 372 | extern SDL_DECLSPEC SDL_MouseButtonFlags SDLCALL SDL_GetRelativeMouseState(float *x, float *y); |
| 373 | |
| 374 | /** |
| 375 | * Move the mouse cursor to the given position within the window. |
| 376 | * |
| 377 | * This function generates a mouse motion event if relative mode is not |
| 378 | * enabled. If relative mode is enabled, you can force mouse events for the |
| 379 | * warp by setting the SDL_HINT_MOUSE_RELATIVE_WARP_MOTION hint. |
| 380 | * |
| 381 | * Note that this function will appear to succeed, but not actually move the |
| 382 | * mouse when used over Microsoft Remote Desktop. |
| 383 | * |
| 384 | * \param window the window to move the mouse into, or NULL for the current |
| 385 | * mouse focus. |
| 386 | * \param x the x coordinate within the window. |
| 387 | * \param y the y coordinate within the window. |
| 388 | * |
| 389 | * \threadsafety This function should only be called on the main thread. |
| 390 | * |
| 391 | * \since This function is available since SDL 3.2.0. |
| 392 | * |
| 393 | * \sa SDL_WarpMouseGlobal |
| 394 | */ |
| 395 | extern SDL_DECLSPEC void SDLCALL SDL_WarpMouseInWindow(SDL_Window *window, |
| 396 | float x, float y); |
| 397 | |
| 398 | /** |
| 399 | * Move the mouse to the given position in global screen space. |
| 400 | * |
| 401 | * This function generates a mouse motion event. |
| 402 | * |
| 403 | * A failure of this function usually means that it is unsupported by a |
| 404 | * platform. |
| 405 | * |
| 406 | * Note that this function will appear to succeed, but not actually move the |
| 407 | * mouse when used over Microsoft Remote Desktop. |
| 408 | * |
| 409 | * \param x the x coordinate. |
| 410 | * \param y the y coordinate. |
| 411 | * \returns true on success or false on failure; call SDL_GetError() for more |
| 412 | * information. |
| 413 | * |
| 414 | * \threadsafety This function should only be called on the main thread. |
| 415 | * |
| 416 | * \since This function is available since SDL 3.2.0. |
| 417 | * |
| 418 | * \sa SDL_WarpMouseInWindow |
| 419 | */ |
| 420 | extern SDL_DECLSPEC bool SDLCALL SDL_WarpMouseGlobal(float x, float y); |
| 421 | |
| 422 | /** |
| 423 | * Set a user-defined function by which to transform relative mouse inputs. |
| 424 | * |
| 425 | * This overrides the relative system scale and relative speed scale hints. |
| 426 | * Should be called prior to enabling relative mouse mode, fails otherwise. |
| 427 | * |
| 428 | * \param callback a callback used to transform relative mouse motion, or NULL |
| 429 | * for default behavior. |
| 430 | * \param userdata a pointer that will be passed to `callback`. |
| 431 | * \returns true on success or false on failure; call SDL_GetError() for more |
| 432 | * information. |
| 433 | * |
| 434 | * \threadsafety This function should only be called on the main thread. |
| 435 | * |
| 436 | * \since This function is available since SDL 3.4.0. |
| 437 | */ |
| 438 | extern SDL_DECLSPEC bool SDLCALL SDL_SetRelativeMouseTransform(SDL_MouseMotionTransformCallback callback, void *userdata); |
| 439 | |
| 440 | /** |
| 441 | * Set relative mouse mode for a window. |
| 442 | * |
| 443 | * While the window has focus and relative mouse mode is enabled, the cursor |
| 444 | * is hidden, the mouse position is constrained to the window, and SDL will |
| 445 | * report continuous relative mouse motion even if the mouse is at the edge of |
| 446 | * the window. |
| 447 | * |
| 448 | * If you'd like to keep the mouse position fixed while in relative mode you |
| 449 | * can use SDL_SetWindowMouseRect(). If you'd like the cursor to be at a |
| 450 | * specific location when relative mode ends, you should use |
| 451 | * SDL_WarpMouseInWindow() before disabling relative mode. |
| 452 | * |
| 453 | * This function will flush any pending mouse motion for this window. |
| 454 | * |
| 455 | * \param window the window to change. |
| 456 | * \param enabled true to enable relative mode, false to disable. |
| 457 | * \returns true on success or false on failure; call SDL_GetError() for more |
| 458 | * information. |
| 459 | * |
| 460 | * \threadsafety This function should only be called on the main thread. |
| 461 | * |
| 462 | * \since This function is available since SDL 3.2.0. |
| 463 | * |
| 464 | * \sa SDL_GetWindowRelativeMouseMode |
| 465 | */ |
| 466 | extern SDL_DECLSPEC bool SDLCALL SDL_SetWindowRelativeMouseMode(SDL_Window *window, bool enabled); |
| 467 | |
| 468 | /** |
| 469 | * Query whether relative mouse mode is enabled for a window. |
| 470 | * |
| 471 | * \param window the window to query. |
| 472 | * \returns true if relative mode is enabled for a window or false otherwise. |
| 473 | * |
| 474 | * \threadsafety This function should only be called on the main thread. |
| 475 | * |
| 476 | * \since This function is available since SDL 3.2.0. |
| 477 | * |
| 478 | * \sa SDL_SetWindowRelativeMouseMode |
| 479 | */ |
| 480 | extern SDL_DECLSPEC bool SDLCALL SDL_GetWindowRelativeMouseMode(SDL_Window *window); |
| 481 | |
| 482 | /** |
| 483 | * Capture the mouse and to track input outside an SDL window. |
| 484 | * |
| 485 | * Capturing enables your app to obtain mouse events globally, instead of just |
| 486 | * within your window. Not all video targets support this function. When |
| 487 | * capturing is enabled, the current window will get all mouse events, but |
| 488 | * unlike relative mode, no change is made to the cursor and it is not |
| 489 | * restrained to your window. |
| 490 | * |
| 491 | * This function may also deny mouse input to other windows--both those in |
| 492 | * your application and others on the system--so you should use this function |
| 493 | * sparingly, and in small bursts. For example, you might want to track the |
| 494 | * mouse while the user is dragging something, until the user releases a mouse |
| 495 | * button. It is not recommended that you capture the mouse for long periods |
| 496 | * of time, such as the entire time your app is running. For that, you should |
| 497 | * probably use SDL_SetWindowRelativeMouseMode() or SDL_SetWindowMouseGrab(), |
| 498 | * depending on your goals. |
| 499 | * |
| 500 | * While captured, mouse events still report coordinates relative to the |
| 501 | * current (foreground) window, but those coordinates may be outside the |
| 502 | * bounds of the window (including negative values). Capturing is only allowed |
| 503 | * for the foreground window. If the window loses focus while capturing, the |
| 504 | * capture will be disabled automatically. |
| 505 | * |
| 506 | * While capturing is enabled, the current window will have the |
| 507 | * `SDL_WINDOW_MOUSE_CAPTURE` flag set. |
| 508 | * |
| 509 | * Please note that SDL will attempt to "auto capture" the mouse while the |
| 510 | * user is pressing a button; this is to try and make mouse behavior more |
| 511 | * consistent between platforms, and deal with the common case of a user |
| 512 | * dragging the mouse outside of the window. This means that if you are |
| 513 | * calling SDL_CaptureMouse() only to deal with this situation, you do not |
| 514 | * have to (although it is safe to do so). If this causes problems for your |
| 515 | * app, you can disable auto capture by setting the |
| 516 | * `SDL_HINT_MOUSE_AUTO_CAPTURE` hint to zero. |
| 517 | * |
| 518 | * \param enabled true to enable capturing, false to disable. |
| 519 | * \returns true on success or false on failure; call SDL_GetError() for more |
| 520 | * information. |
| 521 | * |
| 522 | * \threadsafety This function should only be called on the main thread. |
| 523 | * |
| 524 | * \since This function is available since SDL 3.2.0. |
| 525 | * |
| 526 | * \sa SDL_GetGlobalMouseState |
| 527 | */ |
| 528 | extern SDL_DECLSPEC bool SDLCALL SDL_CaptureMouse(bool enabled); |
| 529 | |
| 530 | /** |
| 531 | * Create a cursor using the specified bitmap data and mask (in MSB format). |
| 532 | * |
| 533 | * `mask` has to be in MSB (Most Significant Bit) format. |
| 534 | * |
| 535 | * The cursor width (`w`) must be a multiple of 8 bits. |
| 536 | * |
| 537 | * The cursor is created in black and white according to the following: |
| 538 | * |
| 539 | * - data=0, mask=1: white |
| 540 | * - data=1, mask=1: black |
| 541 | * - data=0, mask=0: transparent |
| 542 | * - data=1, mask=0: inverted color if possible, black if not. |
| 543 | * |
| 544 | * Cursors created with this function must be freed with SDL_DestroyCursor(). |
| 545 | * |
| 546 | * If you want to have a color cursor, or create your cursor from an |
| 547 | * SDL_Surface, you should use SDL_CreateColorCursor(). Alternately, you can |
| 548 | * hide the cursor and draw your own as part of your game's rendering, but it |
| 549 | * will be bound to the framerate. |
| 550 | * |
| 551 | * Also, SDL_CreateSystemCursor() is available, which provides several |
| 552 | * readily-available system cursors to pick from. |
| 553 | * |
| 554 | * \param data the color value for each pixel of the cursor. |
| 555 | * \param mask the mask value for each pixel of the cursor. |
| 556 | * \param w the width of the cursor. |
| 557 | * \param h the height of the cursor. |
| 558 | * \param hot_x the x-axis offset from the left of the cursor image to the |
| 559 | * mouse x position, in the range of 0 to `w` - 1. |
| 560 | * \param hot_y the y-axis offset from the top of the cursor image to the |
| 561 | * mouse y position, in the range of 0 to `h` - 1. |
| 562 | * \returns a new cursor with the specified parameters on success or NULL on |
| 563 | * failure; call SDL_GetError() for more information. |
| 564 | * |
| 565 | * \threadsafety This function should only be called on the main thread. |
| 566 | * |
| 567 | * \since This function is available since SDL 3.2.0. |
| 568 | * |
| 569 | * \sa SDL_CreateColorCursor |
| 570 | * \sa SDL_CreateSystemCursor |
| 571 | * \sa SDL_DestroyCursor |
| 572 | * \sa SDL_SetCursor |
| 573 | */ |
| 574 | extern SDL_DECLSPEC SDL_Cursor * SDLCALL SDL_CreateCursor(const Uint8 *data, |
| 575 | const Uint8 *mask, |
| 576 | int w, int h, int hot_x, |
| 577 | int hot_y); |
| 578 | |
| 579 | /** |
| 580 | * Create a color cursor. |
| 581 | * |
| 582 | * If this function is passed a surface with alternate representations, the |
| 583 | * surface will be interpreted as the content to be used for 100% display |
| 584 | * scale, and the alternate representations will be used for high DPI |
| 585 | * situations. For example, if the original surface is 32x32, then on a 2x |
| 586 | * macOS display or 200% display scale on Windows, a 64x64 version of the |
| 587 | * image will be used, if available. If a matching version of the image isn't |
| 588 | * available, the closest larger size image will be downscaled to the |
| 589 | * appropriate size and be used instead, if available. Otherwise, the closest |
| 590 | * smaller image will be upscaled and be used instead. |
| 591 | * |
| 592 | * \param surface an SDL_Surface structure representing the cursor image. |
| 593 | * \param hot_x the x position of the cursor hot spot. |
| 594 | * \param hot_y the y position of the cursor hot spot. |
| 595 | * \returns the new cursor on success or NULL on failure; call SDL_GetError() |
| 596 | * for more information. |
| 597 | * |
| 598 | * \threadsafety This function should only be called on the main thread. |
| 599 | * |
| 600 | * \since This function is available since SDL 3.2.0. |
| 601 | * |
| 602 | * \sa SDL_CreateCursor |
| 603 | * \sa SDL_CreateSystemCursor |
| 604 | * \sa SDL_DestroyCursor |
| 605 | * \sa SDL_SetCursor |
| 606 | */ |
| 607 | extern SDL_DECLSPEC SDL_Cursor * SDLCALL SDL_CreateColorCursor(SDL_Surface *surface, |
| 608 | int hot_x, |
| 609 | int hot_y); |
| 610 | |
| 611 | /** |
| 612 | * Create a system cursor. |
| 613 | * |
| 614 | * \param id an SDL_SystemCursor enum value. |
| 615 | * \returns a cursor on success or NULL on failure; call SDL_GetError() for |
| 616 | * more information. |
| 617 | * |
| 618 | * \threadsafety This function should only be called on the main thread. |
| 619 | * |
| 620 | * \since This function is available since SDL 3.2.0. |
| 621 | * |
| 622 | * \sa SDL_DestroyCursor |
| 623 | */ |
| 624 | extern SDL_DECLSPEC SDL_Cursor * SDLCALL SDL_CreateSystemCursor(SDL_SystemCursor id); |
| 625 | |
| 626 | /** |
| 627 | * Set the active cursor. |
| 628 | * |
| 629 | * This function sets the currently active cursor to the specified one. If the |
| 630 | * cursor is currently visible, the change will be immediately represented on |
| 631 | * the display. SDL_SetCursor(NULL) can be used to force cursor redraw, if |
| 632 | * this is desired for any reason. |
| 633 | * |
| 634 | * \param cursor a cursor to make active. |
| 635 | * \returns true on success or false on failure; call SDL_GetError() for more |
| 636 | * information. |
| 637 | * |
| 638 | * \threadsafety This function should only be called on the main thread. |
| 639 | * |
| 640 | * \since This function is available since SDL 3.2.0. |
| 641 | * |
| 642 | * \sa SDL_GetCursor |
| 643 | */ |
| 644 | extern SDL_DECLSPEC bool SDLCALL SDL_SetCursor(SDL_Cursor *cursor); |
| 645 | |
| 646 | /** |
| 647 | * Get the active cursor. |
| 648 | * |
| 649 | * This function returns a pointer to the current cursor which is owned by the |
| 650 | * library. It is not necessary to free the cursor with SDL_DestroyCursor(). |
| 651 | * |
| 652 | * \returns the active cursor or NULL if there is no mouse. |
| 653 | * |
| 654 | * \threadsafety This function should only be called on the main thread. |
| 655 | * |
| 656 | * \since This function is available since SDL 3.2.0. |
| 657 | * |
| 658 | * \sa SDL_SetCursor |
| 659 | */ |
| 660 | extern SDL_DECLSPEC SDL_Cursor * SDLCALL SDL_GetCursor(void); |
| 661 | |
| 662 | /** |
| 663 | * Get the default cursor. |
| 664 | * |
| 665 | * You do not have to call SDL_DestroyCursor() on the return value, but it is |
| 666 | * safe to do so. |
| 667 | * |
| 668 | * \returns the default cursor on success or NULL on failuree; call |
| 669 | * SDL_GetError() for more information. |
| 670 | * |
| 671 | * \threadsafety This function should only be called on the main thread. |
| 672 | * |
| 673 | * \since This function is available since SDL 3.2.0. |
| 674 | */ |
| 675 | extern SDL_DECLSPEC SDL_Cursor * SDLCALL SDL_GetDefaultCursor(void); |
| 676 | |
| 677 | /** |
| 678 | * Free a previously-created cursor. |
| 679 | * |
| 680 | * Use this function to free cursor resources created with SDL_CreateCursor(), |
| 681 | * SDL_CreateColorCursor() or SDL_CreateSystemCursor(). |
| 682 | * |
| 683 | * \param cursor the cursor to free. |
| 684 | * |
| 685 | * \threadsafety This function should only be called on the main thread. |
| 686 | * |
| 687 | * \since This function is available since SDL 3.2.0. |
| 688 | * |
| 689 | * \sa SDL_CreateColorCursor |
| 690 | * \sa SDL_CreateCursor |
| 691 | * \sa SDL_CreateSystemCursor |
| 692 | */ |
| 693 | extern SDL_DECLSPEC void SDLCALL SDL_DestroyCursor(SDL_Cursor *cursor); |
| 694 | |
| 695 | /** |
| 696 | * Show the cursor. |
| 697 | * |
| 698 | * \returns true on success or false on failure; call SDL_GetError() for more |
| 699 | * information. |
| 700 | * |
| 701 | * \threadsafety This function should only be called on the main thread. |
| 702 | * |
| 703 | * \since This function is available since SDL 3.2.0. |
| 704 | * |
| 705 | * \sa SDL_CursorVisible |
| 706 | * \sa SDL_HideCursor |
| 707 | */ |
| 708 | extern SDL_DECLSPEC bool SDLCALL SDL_ShowCursor(void); |
| 709 | |
| 710 | /** |
| 711 | * Hide the cursor. |
| 712 | * |
| 713 | * \returns true on success or false on failure; call SDL_GetError() for more |
| 714 | * information. |
| 715 | * |
| 716 | * \threadsafety This function should only be called on the main thread. |
| 717 | * |
| 718 | * \since This function is available since SDL 3.2.0. |
| 719 | * |
| 720 | * \sa SDL_CursorVisible |
| 721 | * \sa SDL_ShowCursor |
| 722 | */ |
| 723 | extern SDL_DECLSPEC bool SDLCALL SDL_HideCursor(void); |
| 724 | |
| 725 | /** |
| 726 | * Return whether the cursor is currently being shown. |
| 727 | * |
| 728 | * \returns `true` if the cursor is being shown, or `false` if the cursor is |
| 729 | * hidden. |
| 730 | * |
| 731 | * \threadsafety This function should only be called on the main thread. |
| 732 | * |
| 733 | * \since This function is available since SDL 3.2.0. |
| 734 | * |
| 735 | * \sa SDL_HideCursor |
| 736 | * \sa SDL_ShowCursor |
| 737 | */ |
| 738 | extern SDL_DECLSPEC bool SDLCALL SDL_CursorVisible(void); |
| 739 | |
| 740 | /* Ends C function definitions when using C++ */ |
| 741 | #ifdef __cplusplus |
| 742 | } |
| 743 | #endif |
| 744 | #include <SDL3/SDL_close_code.h> |
| 745 | |
| 746 | #endif /* SDL_mouse_h_ */ |
| 747 | |