SDL_mouse.h 28 KB

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