🛠️🐜 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.

302 lines
11 KiB

  1. /*
  2. Simple DirectMedia Layer
  3. Copyright (C) 1997-2020 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. * \brief Get the window which currently has mouse focus.
  64. */
  65. extern DECLSPEC SDL_Window * SDLCALL SDL_GetMouseFocus(void);
  66. /**
  67. * \brief Retrieve the current state of the mouse.
  68. *
  69. * The current button state is returned as a button bitmask, which can
  70. * be tested using the SDL_BUTTON(X) macros, and x and y are set to the
  71. * mouse cursor position relative to the focus window for the currently
  72. * selected mouse. You can pass NULL for either x or y.
  73. */
  74. extern DECLSPEC Uint32 SDLCALL SDL_GetMouseState(int *x, int *y);
  75. /**
  76. * \brief Get the current state of the mouse, in relation to the desktop
  77. *
  78. * This works just like SDL_GetMouseState(), but the coordinates will be
  79. * reported relative to the top-left of the desktop. This can be useful if
  80. * you need to track the mouse outside of a specific window and
  81. * SDL_CaptureMouse() doesn't fit your needs. For example, it could be
  82. * useful if you need to track the mouse while dragging a window, where
  83. * coordinates relative to a window might not be in sync at all times.
  84. *
  85. * \note SDL_GetMouseState() returns the mouse position as SDL understands
  86. * it from the last pump of the event queue. This function, however,
  87. * queries the OS for the current mouse position, and as such, might
  88. * be a slightly less efficient function. Unless you know what you're
  89. * doing and have a good reason to use this function, you probably want
  90. * SDL_GetMouseState() instead.
  91. *
  92. * \param x Returns the current X coord, relative to the desktop. Can be NULL.
  93. * \param y Returns the current Y coord, relative to the desktop. Can be NULL.
  94. * \return The current button state as a bitmask, which can be tested using the SDL_BUTTON(X) macros.
  95. *
  96. * \sa SDL_GetMouseState
  97. */
  98. extern DECLSPEC Uint32 SDLCALL SDL_GetGlobalMouseState(int *x, int *y);
  99. /**
  100. * \brief Retrieve the relative state of the mouse.
  101. *
  102. * The current button state is returned as a button bitmask, which can
  103. * be tested using the SDL_BUTTON(X) macros, and x and y are set to the
  104. * mouse deltas since the last call to SDL_GetRelativeMouseState().
  105. */
  106. extern DECLSPEC Uint32 SDLCALL SDL_GetRelativeMouseState(int *x, int *y);
  107. /**
  108. * \brief Moves the mouse to the given position within the window.
  109. *
  110. * \param window The window to move the mouse into, or NULL for the current mouse focus
  111. * \param x The x coordinate within the window
  112. * \param y The y coordinate within the window
  113. *
  114. * \note This function generates a mouse motion event
  115. */
  116. extern DECLSPEC void SDLCALL SDL_WarpMouseInWindow(SDL_Window * window,
  117. int x, int y);
  118. /**
  119. * \brief Moves the mouse to the given position in global screen space.
  120. *
  121. * \param x The x coordinate
  122. * \param y The y coordinate
  123. * \return 0 on success, -1 on error (usually: unsupported by a platform).
  124. *
  125. * \note This function generates a mouse motion event
  126. */
  127. extern DECLSPEC int SDLCALL SDL_WarpMouseGlobal(int x, int y);
  128. /**
  129. * \brief Set relative mouse mode.
  130. *
  131. * \param enabled Whether or not to enable relative mode
  132. *
  133. * \return 0 on success, or -1 if relative mode is not supported.
  134. *
  135. * While the mouse is in relative mode, the cursor is hidden, and the
  136. * driver will try to report continuous motion in the current window.
  137. * Only relative motion events will be delivered, the mouse position
  138. * will not change.
  139. *
  140. * \note This function will flush any pending mouse motion.
  141. *
  142. * \sa SDL_GetRelativeMouseMode()
  143. */
  144. extern DECLSPEC int SDLCALL SDL_SetRelativeMouseMode(SDL_bool enabled);
  145. /**
  146. * \brief Capture the mouse, to track input outside an SDL window.
  147. *
  148. * \param enabled Whether or not to enable capturing
  149. *
  150. * Capturing enables your app to obtain mouse events globally, instead of
  151. * just within your window. Not all video targets support this function.
  152. * When capturing is enabled, the current window will get all mouse events,
  153. * but unlike relative mode, no change is made to the cursor and it is
  154. * not restrained to your window.
  155. *
  156. * This function may also deny mouse input to other windows--both those in
  157. * your application and others on the system--so you should use this
  158. * function sparingly, and in small bursts. For example, you might want to
  159. * track the mouse while the user is dragging something, until the user
  160. * releases a mouse button. It is not recommended that you capture the mouse
  161. * for long periods of time, such as the entire time your app is running.
  162. *
  163. * While captured, mouse events still report coordinates relative to the
  164. * current (foreground) window, but those coordinates may be outside the
  165. * bounds of the window (including negative values). Capturing is only
  166. * allowed for the foreground window. If the window loses focus while
  167. * capturing, the capture will be disabled automatically.
  168. *
  169. * While capturing is enabled, the current window will have the
  170. * SDL_WINDOW_MOUSE_CAPTURE flag set.
  171. *
  172. * \return 0 on success, or -1 if not supported.
  173. */
  174. extern DECLSPEC int SDLCALL SDL_CaptureMouse(SDL_bool enabled);
  175. /**
  176. * \brief Query whether relative mouse mode is enabled.
  177. *
  178. * \sa SDL_SetRelativeMouseMode()
  179. */
  180. extern DECLSPEC SDL_bool SDLCALL SDL_GetRelativeMouseMode(void);
  181. /**
  182. * \brief Create a cursor, using the specified bitmap data and
  183. * mask (in MSB format).
  184. *
  185. * The cursor width must be a multiple of 8 bits.
  186. *
  187. * The cursor is created in black and white according to the following:
  188. * <table>
  189. * <tr><td> data </td><td> mask </td><td> resulting pixel on screen </td></tr>
  190. * <tr><td> 0 </td><td> 1 </td><td> White </td></tr>
  191. * <tr><td> 1 </td><td> 1 </td><td> Black </td></tr>
  192. * <tr><td> 0 </td><td> 0 </td><td> Transparent </td></tr>
  193. * <tr><td> 1 </td><td> 0 </td><td> Inverted color if possible, black
  194. * if not. </td></tr>
  195. * </table>
  196. *
  197. * \sa SDL_FreeCursor()
  198. */
  199. extern DECLSPEC SDL_Cursor *SDLCALL SDL_CreateCursor(const Uint8 * data,
  200. const Uint8 * mask,
  201. int w, int h, int hot_x,
  202. int hot_y);
  203. /**
  204. * \brief Create a color cursor.
  205. *
  206. * \sa SDL_FreeCursor()
  207. */
  208. extern DECLSPEC SDL_Cursor *SDLCALL SDL_CreateColorCursor(SDL_Surface *surface,
  209. int hot_x,
  210. int hot_y);
  211. /**
  212. * \brief Create a system cursor.
  213. *
  214. * \sa SDL_FreeCursor()
  215. */
  216. extern DECLSPEC SDL_Cursor *SDLCALL SDL_CreateSystemCursor(SDL_SystemCursor id);
  217. /**
  218. * \brief Set the active cursor.
  219. */
  220. extern DECLSPEC void SDLCALL SDL_SetCursor(SDL_Cursor * cursor);
  221. /**
  222. * \brief Return the active cursor.
  223. */
  224. extern DECLSPEC SDL_Cursor *SDLCALL SDL_GetCursor(void);
  225. /**
  226. * \brief Return the default cursor.
  227. */
  228. extern DECLSPEC SDL_Cursor *SDLCALL SDL_GetDefaultCursor(void);
  229. /**
  230. * \brief Frees a cursor created with SDL_CreateCursor() or similar functions.
  231. *
  232. * \sa SDL_CreateCursor()
  233. * \sa SDL_CreateColorCursor()
  234. * \sa SDL_CreateSystemCursor()
  235. */
  236. extern DECLSPEC void SDLCALL SDL_FreeCursor(SDL_Cursor * cursor);
  237. /**
  238. * \brief Toggle whether or not the cursor is shown.
  239. *
  240. * \param toggle 1 to show the cursor, 0 to hide it, -1 to query the current
  241. * state.
  242. *
  243. * \return 1 if the cursor is shown, or 0 if the cursor is hidden.
  244. */
  245. extern DECLSPEC int SDLCALL SDL_ShowCursor(int toggle);
  246. /**
  247. * Used as a mask when testing buttons in buttonstate.
  248. * - Button 1: Left mouse button
  249. * - Button 2: Middle mouse button
  250. * - Button 3: Right mouse button
  251. */
  252. #define SDL_BUTTON(X) (1 << ((X)-1))
  253. #define SDL_BUTTON_LEFT 1
  254. #define SDL_BUTTON_MIDDLE 2
  255. #define SDL_BUTTON_RIGHT 3
  256. #define SDL_BUTTON_X1 4
  257. #define SDL_BUTTON_X2 5
  258. #define SDL_BUTTON_LMASK SDL_BUTTON(SDL_BUTTON_LEFT)
  259. #define SDL_BUTTON_MMASK SDL_BUTTON(SDL_BUTTON_MIDDLE)
  260. #define SDL_BUTTON_RMASK SDL_BUTTON(SDL_BUTTON_RIGHT)
  261. #define SDL_BUTTON_X1MASK SDL_BUTTON(SDL_BUTTON_X1)
  262. #define SDL_BUTTON_X2MASK SDL_BUTTON(SDL_BUTTON_X2)
  263. /* Ends C function definitions when using C++ */
  264. #ifdef __cplusplus
  265. }
  266. #endif
  267. #include "close_code.h"
  268. #endif /* SDL_mouse_h_ */
  269. /* vi: set ts=4 sw=4 expandtab: */