1
0

SDL_mouse.h 26 KB

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