🛠️🐜 Antkeeper superbuild with dependencies included https://antkeeper.com
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

465 lines
17 KiB

  1. /*
  2. Simple DirectMedia Layer
  3. Copyright (C) 1997-2022 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. * \file SDL_mouse.h
  20. *
  21. * Include file for SDL mouse event handling.
  22. */
  23. #ifndef SDL_mouse_h_
  24. #define SDL_mouse_h_
  25. #include "SDL_stdinc.h"
  26. #include "SDL_error.h"
  27. #include "SDL_video.h"
  28. #include "begin_code.h"
  29. /* Set up for C function definitions, even when using C++ */
  30. #ifdef __cplusplus
  31. extern "C" {
  32. #endif
  33. typedef struct SDL_Cursor SDL_Cursor; /**< Implementation dependent */
  34. /**
  35. * \brief Cursor types for SDL_CreateSystemCursor().
  36. */
  37. typedef enum
  38. {
  39. SDL_SYSTEM_CURSOR_ARROW, /**< Arrow */
  40. SDL_SYSTEM_CURSOR_IBEAM, /**< I-beam */
  41. SDL_SYSTEM_CURSOR_WAIT, /**< Wait */
  42. SDL_SYSTEM_CURSOR_CROSSHAIR, /**< Crosshair */
  43. SDL_SYSTEM_CURSOR_WAITARROW, /**< Small wait cursor (or Wait if not available) */
  44. SDL_SYSTEM_CURSOR_SIZENWSE, /**< Double arrow pointing northwest and southeast */
  45. SDL_SYSTEM_CURSOR_SIZENESW, /**< Double arrow pointing northeast and southwest */
  46. SDL_SYSTEM_CURSOR_SIZEWE, /**< Double arrow pointing west and east */
  47. SDL_SYSTEM_CURSOR_SIZENS, /**< Double arrow pointing north and south */
  48. SDL_SYSTEM_CURSOR_SIZEALL, /**< Four pointed arrow pointing north, south, east, and west */
  49. SDL_SYSTEM_CURSOR_NO, /**< Slashed circle or crossbones */
  50. SDL_SYSTEM_CURSOR_HAND, /**< Hand */
  51. SDL_NUM_SYSTEM_CURSORS
  52. } SDL_SystemCursor;
  53. /**
  54. * \brief Scroll direction types for the Scroll event
  55. */
  56. typedef enum
  57. {
  58. SDL_MOUSEWHEEL_NORMAL, /**< The scroll direction is normal */
  59. SDL_MOUSEWHEEL_FLIPPED /**< The scroll direction is flipped / natural */
  60. } SDL_MouseWheelDirection;
  61. /* Function prototypes */
  62. /**
  63. * Get the window which currently has mouse focus.
  64. *
  65. * \returns the window with mouse focus.
  66. *
  67. * \since This function is available since SDL 2.0.0.
  68. */
  69. extern DECLSPEC SDL_Window * SDLCALL SDL_GetMouseFocus(void);
  70. /**
  71. * Retrieve the current state of the mouse.
  72. *
  73. * The current button state is returned as a button bitmask, which can be
  74. * tested using the `SDL_BUTTON(X)` macros (where `X` is generally 1 for the
  75. * left, 2 for middle, 3 for the right button), and `x` and `y` are set to the
  76. * mouse cursor position relative to the focus window. You can pass NULL for
  77. * either `x` or `y`.
  78. *
  79. * \param x the x coordinate of the mouse cursor position relative to the
  80. * focus window
  81. * \param y the y coordinate of the mouse cursor position relative to the
  82. * focus window
  83. * \returns a 32-bit button bitmask of the current button state.
  84. *
  85. * \since This function is available since SDL 2.0.0.
  86. *
  87. * \sa SDL_GetGlobalMouseState
  88. * \sa SDL_GetRelativeMouseState
  89. * \sa SDL_PumpEvents
  90. */
  91. extern DECLSPEC Uint32 SDLCALL SDL_GetMouseState(int *x, int *y);
  92. /**
  93. * Get the current state of the mouse in relation to the desktop.
  94. *
  95. * This works similarly to SDL_GetMouseState(), but the coordinates will be
  96. * reported relative to the top-left of the desktop. This can be useful if you
  97. * need to track the mouse outside of a specific window and SDL_CaptureMouse()
  98. * doesn't fit your needs. For example, it could be useful if you need to
  99. * track the mouse while dragging a window, where coordinates relative to a
  100. * window might not be in sync at all times.
  101. *
  102. * Note: SDL_GetMouseState() returns the mouse position as SDL understands it
  103. * from the last pump of the event queue. This function, however, queries the
  104. * OS for the current mouse position, and as such, might be a slightly less
  105. * efficient function. Unless you know what you're doing and have a good
  106. * reason to use this function, you probably want SDL_GetMouseState() instead.
  107. *
  108. * \param x filled in with the current X coord relative to the desktop; can be
  109. * NULL
  110. * \param y filled in with the current Y coord relative to the desktop; can be
  111. * NULL
  112. * \returns the current button state as a bitmask which can be tested using
  113. * the SDL_BUTTON(X) macros.
  114. *
  115. * \since This function is available since SDL 2.0.4.
  116. *
  117. * \sa SDL_CaptureMouse
  118. */
  119. extern DECLSPEC Uint32 SDLCALL SDL_GetGlobalMouseState(int *x, int *y);
  120. /**
  121. * Retrieve the relative state of the mouse.
  122. *
  123. * The current button state is returned as a button bitmask, which can be
  124. * tested using the `SDL_BUTTON(X)` macros (where `X` is generally 1 for the
  125. * left, 2 for middle, 3 for the right button), and `x` and `y` are set to the
  126. * mouse deltas since the last call to SDL_GetRelativeMouseState() or since
  127. * event initialization. You can pass NULL for either `x` or `y`.
  128. *
  129. * \param x a pointer filled with the last recorded x coordinate of the mouse
  130. * \param y a pointer filled with the last recorded y coordinate of the mouse
  131. * \returns a 32-bit button bitmask of the relative button state.
  132. *
  133. * \since This function is available since SDL 2.0.0.
  134. *
  135. * \sa SDL_GetMouseState
  136. */
  137. extern DECLSPEC Uint32 SDLCALL SDL_GetRelativeMouseState(int *x, int *y);
  138. /**
  139. * Move the mouse cursor to the given position within the window.
  140. *
  141. * This function generates a mouse motion event if relative mode is not
  142. * enabled. If relative mode is enabled, you can force mouse events for the
  143. * warp by setting the SDL_HINT_MOUSE_RELATIVE_WARP_MOTION hint.
  144. *
  145. * Note that this function will appear to succeed, but not actually move the
  146. * mouse when used over Microsoft Remote Desktop.
  147. *
  148. * \param window the window to move the mouse into, or NULL for the current
  149. * mouse focus
  150. * \param x the x coordinate within the window
  151. * \param y the y coordinate within the window
  152. *
  153. * \since This function is available since SDL 2.0.0.
  154. *
  155. * \sa SDL_WarpMouseGlobal
  156. */
  157. extern DECLSPEC void SDLCALL SDL_WarpMouseInWindow(SDL_Window * window,
  158. int x, int y);
  159. /**
  160. * Move the mouse to the given position in global screen space.
  161. *
  162. * This function generates a mouse motion event.
  163. *
  164. * A failure of this function usually means that it is unsupported by a
  165. * platform.
  166. *
  167. * Note that this function will appear to succeed, but not actually move the
  168. * mouse when used over Microsoft Remote Desktop.
  169. *
  170. * \param x the x coordinate
  171. * \param y the y coordinate
  172. * \returns 0 on success or a negative error code on failure; call
  173. * SDL_GetError() for more information.
  174. *
  175. * \since This function is available since SDL 2.0.4.
  176. *
  177. * \sa SDL_WarpMouseInWindow
  178. */
  179. extern DECLSPEC int SDLCALL SDL_WarpMouseGlobal(int x, int y);
  180. /**
  181. * Set relative mouse mode.
  182. *
  183. * While the mouse is in relative mode, the cursor is hidden, and the driver
  184. * will try to report continuous motion in the current window. Only relative
  185. * motion events will be delivered, the mouse position will not change.
  186. *
  187. * Note that this function will not be able to provide continuous relative
  188. * motion when used over Microsoft Remote Desktop, instead motion is limited
  189. * to the bounds of the screen.
  190. *
  191. * This function will flush any pending mouse motion.
  192. *
  193. * \param enabled SDL_TRUE to enable relative mode, SDL_FALSE to disable.
  194. * \returns 0 on success or a negative error code on failure; call
  195. * SDL_GetError() for more information.
  196. *
  197. * If relative mode is not supported, this returns -1.
  198. *
  199. * \since This function is available since SDL 2.0.0.
  200. *
  201. * \sa SDL_GetRelativeMouseMode
  202. */
  203. extern DECLSPEC int SDLCALL SDL_SetRelativeMouseMode(SDL_bool enabled);
  204. /**
  205. * Capture the mouse and to track input outside an SDL window.
  206. *
  207. * Capturing enables your app to obtain mouse events globally, instead of just
  208. * within your window. Not all video targets support this function. When
  209. * capturing is enabled, the current window will get all mouse events, but
  210. * unlike relative mode, no change is made to the cursor and it is not
  211. * restrained to your window.
  212. *
  213. * This function may also deny mouse input to other windows--both those in
  214. * your application and others on the system--so you should use this function
  215. * sparingly, and in small bursts. For example, you might want to track the
  216. * mouse while the user is dragging something, until the user releases a mouse
  217. * button. It is not recommended that you capture the mouse for long periods
  218. * of time, such as the entire time your app is running. For that, you should
  219. * probably use SDL_SetRelativeMouseMode() or SDL_SetWindowGrab(), depending
  220. * on your goals.
  221. *
  222. * While captured, mouse events still report coordinates relative to the
  223. * current (foreground) window, but those coordinates may be outside the
  224. * bounds of the window (including negative values). Capturing is only allowed
  225. * for the foreground window. If the window loses focus while capturing, the
  226. * capture will be disabled automatically.
  227. *
  228. * While capturing is enabled, the current window will have the
  229. * `SDL_WINDOW_MOUSE_CAPTURE` flag set.
  230. *
  231. * Please note that as of SDL 2.0.22, SDL will attempt to "auto capture" the
  232. * mouse while the user is pressing a button; this is to try and make mouse
  233. * behavior more consistent between platforms, and deal with the common case
  234. * of a user dragging the mouse outside of the window. This means that if you
  235. * are calling SDL_CaptureMouse() only to deal with this situation, you no
  236. * longer have to (although it is safe to do so). If this causes problems for
  237. * your app, you can disable auto capture by setting the
  238. * `SDL_HINT_MOUSE_AUTO_CAPTURE` hint to zero.
  239. *
  240. * \param enabled SDL_TRUE to enable capturing, SDL_FALSE to disable.
  241. * \returns 0 on success or -1 if not supported; call SDL_GetError() for more
  242. * information.
  243. *
  244. * \since This function is available since SDL 2.0.4.
  245. *
  246. * \sa SDL_GetGlobalMouseState
  247. */
  248. extern DECLSPEC int SDLCALL SDL_CaptureMouse(SDL_bool enabled);
  249. /**
  250. * Query whether relative mouse mode is enabled.
  251. *
  252. * \returns SDL_TRUE if relative mode is enabled or SDL_FALSE otherwise.
  253. *
  254. * \since This function is available since SDL 2.0.0.
  255. *
  256. * \sa SDL_SetRelativeMouseMode
  257. */
  258. extern DECLSPEC SDL_bool SDLCALL SDL_GetRelativeMouseMode(void);
  259. /**
  260. * Create a cursor using the specified bitmap data and mask (in MSB format).
  261. *
  262. * `mask` has to be in MSB (Most Significant Bit) format.
  263. *
  264. * The cursor width (`w`) must be a multiple of 8 bits.
  265. *
  266. * The cursor is created in black and white according to the following:
  267. *
  268. * - data=0, mask=1: white
  269. * - data=1, mask=1: black
  270. * - data=0, mask=0: transparent
  271. * - data=1, mask=0: inverted color if possible, black if not.
  272. *
  273. * Cursors created with this function must be freed with SDL_FreeCursor().
  274. *
  275. * If you want to have a color cursor, or create your cursor from an
  276. * SDL_Surface, you should use SDL_CreateColorCursor(). Alternately, you can
  277. * hide the cursor and draw your own as part of your game's rendering, but it
  278. * will be bound to the framerate.
  279. *
  280. * Also, since SDL 2.0.0, SDL_CreateSystemCursor() is available, which
  281. * provides twelve readily available system cursors to pick from.
  282. *
  283. * \param data the color value for each pixel of the cursor
  284. * \param mask the mask value for each pixel of the cursor
  285. * \param w the width of the cursor
  286. * \param h the height of the cursor
  287. * \param hot_x the X-axis location of the upper left corner of the cursor
  288. * relative to the actual mouse position
  289. * \param hot_y the Y-axis location of the upper left corner of the cursor
  290. * relative to the actual mouse position
  291. * \returns a new cursor with the specified parameters on success or NULL on
  292. * failure; call SDL_GetError() for more information.
  293. *
  294. * \since This function is available since SDL 2.0.0.
  295. *
  296. * \sa SDL_FreeCursor
  297. * \sa SDL_SetCursor
  298. * \sa SDL_ShowCursor
  299. */
  300. extern DECLSPEC SDL_Cursor *SDLCALL SDL_CreateCursor(const Uint8 * data,
  301. const Uint8 * mask,
  302. int w, int h, int hot_x,
  303. int hot_y);
  304. /**
  305. * Create a color cursor.
  306. *
  307. * \param surface an SDL_Surface structure representing the cursor image
  308. * \param hot_x the x position of the cursor hot spot
  309. * \param hot_y the y position of the cursor hot spot
  310. * \returns the new cursor on success or NULL on failure; call SDL_GetError()
  311. * for more information.
  312. *
  313. * \since This function is available since SDL 2.0.0.
  314. *
  315. * \sa SDL_CreateCursor
  316. * \sa SDL_FreeCursor
  317. */
  318. extern DECLSPEC SDL_Cursor *SDLCALL SDL_CreateColorCursor(SDL_Surface *surface,
  319. int hot_x,
  320. int hot_y);
  321. /**
  322. * Create a system cursor.
  323. *
  324. * \param id an SDL_SystemCursor enum value
  325. * \returns a cursor on success or NULL on failure; call SDL_GetError() for
  326. * more information.
  327. *
  328. * \since This function is available since SDL 2.0.0.
  329. *
  330. * \sa SDL_FreeCursor
  331. */
  332. extern DECLSPEC SDL_Cursor *SDLCALL SDL_CreateSystemCursor(SDL_SystemCursor id);
  333. /**
  334. * Set the active cursor.
  335. *
  336. * This function sets the currently active cursor to the specified one. If the
  337. * cursor is currently visible, the change will be immediately represented on
  338. * the display. SDL_SetCursor(NULL) can be used to force cursor redraw, if
  339. * this is desired for any reason.
  340. *
  341. * \param cursor a cursor to make active
  342. *
  343. * \since This function is available since SDL 2.0.0.
  344. *
  345. * \sa SDL_CreateCursor
  346. * \sa SDL_GetCursor
  347. * \sa SDL_ShowCursor
  348. */
  349. extern DECLSPEC void SDLCALL SDL_SetCursor(SDL_Cursor * cursor);
  350. /**
  351. * Get the active cursor.
  352. *
  353. * This function returns a pointer to the current cursor which is owned by the
  354. * library. It is not necessary to free the cursor with SDL_FreeCursor().
  355. *
  356. * \returns the active cursor or NULL if there is no mouse.
  357. *
  358. * \since This function is available since SDL 2.0.0.
  359. *
  360. * \sa SDL_SetCursor
  361. */
  362. extern DECLSPEC SDL_Cursor *SDLCALL SDL_GetCursor(void);
  363. /**
  364. * Get the default cursor.
  365. *
  366. * \returns the default cursor on success or NULL on failure.
  367. *
  368. * \since This function is available since SDL 2.0.0.
  369. *
  370. * \sa SDL_CreateSystemCursor
  371. */
  372. extern DECLSPEC SDL_Cursor *SDLCALL SDL_GetDefaultCursor(void);
  373. /**
  374. * Free a previously-created cursor.
  375. *
  376. * Use this function to free cursor resources created with SDL_CreateCursor(),
  377. * SDL_CreateColorCursor() or SDL_CreateSystemCursor().
  378. *
  379. * \param cursor the cursor to free
  380. *
  381. * \since This function is available since SDL 2.0.0.
  382. *
  383. * \sa SDL_CreateColorCursor
  384. * \sa SDL_CreateCursor
  385. * \sa SDL_CreateSystemCursor
  386. */
  387. extern DECLSPEC void SDLCALL SDL_FreeCursor(SDL_Cursor * cursor);
  388. /**
  389. * Toggle whether or not the cursor is shown.
  390. *
  391. * The cursor starts off displayed but can be turned off. Passing `SDL_ENABLE`
  392. * displays the cursor and passing `SDL_DISABLE` hides it.
  393. *
  394. * The current state of the mouse cursor can be queried by passing
  395. * `SDL_QUERY`; either `SDL_DISABLE` or `SDL_ENABLE` will be returned.
  396. *
  397. * \param toggle `SDL_ENABLE` to show the cursor, `SDL_DISABLE` to hide it,
  398. * `SDL_QUERY` to query the current state without changing it.
  399. * \returns `SDL_ENABLE` if the cursor is shown, or `SDL_DISABLE` if the
  400. * cursor is hidden, or a negative error code on failure; call
  401. * SDL_GetError() for more information.
  402. *
  403. * \since This function is available since SDL 2.0.0.
  404. *
  405. * \sa SDL_CreateCursor
  406. * \sa SDL_SetCursor
  407. */
  408. extern DECLSPEC int SDLCALL SDL_ShowCursor(int toggle);
  409. /**
  410. * Used as a mask when testing buttons in buttonstate.
  411. *
  412. * - Button 1: Left mouse button
  413. * - Button 2: Middle mouse button
  414. * - Button 3: Right mouse button
  415. */
  416. #define SDL_BUTTON(X) (1 << ((X)-1))
  417. #define SDL_BUTTON_LEFT 1
  418. #define SDL_BUTTON_MIDDLE 2
  419. #define SDL_BUTTON_RIGHT 3
  420. #define SDL_BUTTON_X1 4
  421. #define SDL_BUTTON_X2 5
  422. #define SDL_BUTTON_LMASK SDL_BUTTON(SDL_BUTTON_LEFT)
  423. #define SDL_BUTTON_MMASK SDL_BUTTON(SDL_BUTTON_MIDDLE)
  424. #define SDL_BUTTON_RMASK SDL_BUTTON(SDL_BUTTON_RIGHT)
  425. #define SDL_BUTTON_X1MASK SDL_BUTTON(SDL_BUTTON_X1)
  426. #define SDL_BUTTON_X2MASK SDL_BUTTON(SDL_BUTTON_X2)
  427. /* Ends C function definitions when using C++ */
  428. #ifdef __cplusplus
  429. }
  430. #endif
  431. #include "close_code.h"
  432. #endif /* SDL_mouse_h_ */
  433. /* vi: set ts=4 sw=4 expandtab: */