SDL_mouse.h 31 KB

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