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