SDL_mouse.h 32 KB

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