1/*
2 Simple DirectMedia Layer
3 Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
4
5 This software is provided 'as-is', without any express or implied
6 warranty. In no event will the authors be held liable for any damages
7 arising from the use of this software.
8
9 Permission is granted to anyone to use this software for any purpose,
10 including commercial applications, and to alter it and redistribute it
11 freely, subject to the following restrictions:
12
13 1. The origin of this software must not be misrepresented; you must not
14 claim that you wrote the original software. If you use this software
15 in a product, an acknowledgment in the product documentation would be
16 appreciated but is not required.
17 2. Altered source versions must be plainly marked as such, and must not be
18 misrepresented as being the original software.
19 3. This notice may not be removed or altered from any source distribution.
20*/
21
22/**
23 * \file SDL_mouse.h
24 *
25 * Include file for SDL mouse event handling.
26 */
27
28#ifndef SDL_mouse_h_
29#define SDL_mouse_h_
30
31#include "SDL_stdinc.h"
32#include "SDL_error.h"
33#include "SDL_video.h"
34
35#include "begin_code.h"
36/* Set up for C function definitions, even when using C++ */
37#ifdef __cplusplus
38extern "C" {
39#endif
40
41typedef struct SDL_Cursor SDL_Cursor; /**< Implementation dependent */
42
43/**
44 * \brief Cursor types for SDL_CreateSystemCursor().
45 */
46typedef enum
47{
48 SDL_SYSTEM_CURSOR_ARROW, /**< Arrow */
49 SDL_SYSTEM_CURSOR_IBEAM, /**< I-beam */
50 SDL_SYSTEM_CURSOR_WAIT, /**< Wait */
51 SDL_SYSTEM_CURSOR_CROSSHAIR, /**< Crosshair */
52 SDL_SYSTEM_CURSOR_WAITARROW, /**< Small wait cursor (or Wait if not available) */
53 SDL_SYSTEM_CURSOR_SIZENWSE, /**< Double arrow pointing northwest and southeast */
54 SDL_SYSTEM_CURSOR_SIZENESW, /**< Double arrow pointing northeast and southwest */
55 SDL_SYSTEM_CURSOR_SIZEWE, /**< Double arrow pointing west and east */
56 SDL_SYSTEM_CURSOR_SIZENS, /**< Double arrow pointing north and south */
57 SDL_SYSTEM_CURSOR_SIZEALL, /**< Four pointed arrow pointing north, south, east, and west */
58 SDL_SYSTEM_CURSOR_NO, /**< Slashed circle or crossbones */
59 SDL_SYSTEM_CURSOR_HAND, /**< Hand */
60 SDL_NUM_SYSTEM_CURSORS
61} SDL_SystemCursor;
62
63/**
64 * \brief Scroll direction types for the Scroll event
65 */
66typedef enum
67{
68 SDL_MOUSEWHEEL_NORMAL, /**< The scroll direction is normal */
69 SDL_MOUSEWHEEL_FLIPPED /**< The scroll direction is flipped / natural */
70} SDL_MouseWheelDirection;
71
72/* Function prototypes */
73
74/**
75 * \brief Get the window which currently has mouse focus.
76 */
77extern DECLSPEC SDL_Window * SDLCALL SDL_GetMouseFocus(void);
78
79/**
80 * \brief Retrieve the current state of the mouse.
81 *
82 * The current button state is returned as a button bitmask, which can
83 * be tested using the SDL_BUTTON(X) macros, and x and y are set to the
84 * mouse cursor position relative to the focus window for the currently
85 * selected mouse. You can pass NULL for either x or y.
86 */
87extern DECLSPEC Uint32 SDLCALL SDL_GetMouseState(int *x, int *y);
88
89/**
90 * \brief Get the current state of the mouse, in relation to the desktop
91 *
92 * This works just like SDL_GetMouseState(), but the coordinates will be
93 * reported relative to the top-left of the desktop. This can be useful if
94 * you need to track the mouse outside of a specific window and
95 * SDL_CaptureMouse() doesn't fit your needs. For example, it could be
96 * useful if you need to track the mouse while dragging a window, where
97 * coordinates relative to a window might not be in sync at all times.
98 *
99 * \note SDL_GetMouseState() returns the mouse position as SDL understands
100 * it from the last pump of the event queue. This function, however,
101 * queries the OS for the current mouse position, and as such, might
102 * be a slightly less efficient function. Unless you know what you're
103 * doing and have a good reason to use this function, you probably want
104 * SDL_GetMouseState() instead.
105 *
106 * \param x Returns the current X coord, relative to the desktop. Can be NULL.
107 * \param y Returns the current Y coord, relative to the desktop. Can be NULL.
108 * \return The current button state as a bitmask, which can be tested using the SDL_BUTTON(X) macros.
109 *
110 * \sa SDL_GetMouseState
111 */
112extern DECLSPEC Uint32 SDLCALL SDL_GetGlobalMouseState(int *x, int *y);
113
114/**
115 * \brief Retrieve the relative state of the mouse.
116 *
117 * The current button state is returned as a button bitmask, which can
118 * be tested using the SDL_BUTTON(X) macros, and x and y are set to the
119 * mouse deltas since the last call to SDL_GetRelativeMouseState().
120 */
121extern DECLSPEC Uint32 SDLCALL SDL_GetRelativeMouseState(int *x, int *y);
122
123/**
124 * \brief Moves the mouse to the given position within the window.
125 *
126 * \param window The window to move the mouse into, or NULL for the current mouse focus
127 * \param x The x coordinate within the window
128 * \param y The y coordinate within the window
129 *
130 * \note This function generates a mouse motion event
131 */
132extern DECLSPEC void SDLCALL SDL_WarpMouseInWindow(SDL_Window * window,
133 int x, int y);
134
135/**
136 * \brief Moves the mouse to the given position in global screen space.
137 *
138 * \param x The x coordinate
139 * \param y The y coordinate
140 * \return 0 on success, -1 on error (usually: unsupported by a platform).
141 *
142 * \note This function generates a mouse motion event
143 */
144extern DECLSPEC int SDLCALL SDL_WarpMouseGlobal(int x, int y);
145
146/**
147 * \brief Set relative mouse mode.
148 *
149 * \param enabled Whether or not to enable relative mode
150 *
151 * \return 0 on success, or -1 if relative mode is not supported.
152 *
153 * While the mouse is in relative mode, the cursor is hidden, and the
154 * driver will try to report continuous motion in the current window.
155 * Only relative motion events will be delivered, the mouse position
156 * will not change.
157 *
158 * \note This function will flush any pending mouse motion.
159 *
160 * \sa SDL_GetRelativeMouseMode()
161 */
162extern DECLSPEC int SDLCALL SDL_SetRelativeMouseMode(SDL_bool enabled);
163
164/**
165 * \brief Capture the mouse, to track input outside an SDL window.
166 *
167 * \param enabled Whether or not to enable capturing
168 *
169 * Capturing enables your app to obtain mouse events globally, instead of
170 * just within your window. Not all video targets support this function.
171 * When capturing is enabled, the current window will get all mouse events,
172 * but unlike relative mode, no change is made to the cursor and it is
173 * not restrained to your window.
174 *
175 * This function may also deny mouse input to other windows--both those in
176 * your application and others on the system--so you should use this
177 * function sparingly, and in small bursts. For example, you might want to
178 * track the mouse while the user is dragging something, until the user
179 * releases a mouse button. It is not recommended that you capture the mouse
180 * for long periods of time, such as the entire time your app is running.
181 *
182 * While captured, mouse events still report coordinates relative to the
183 * current (foreground) window, but those coordinates may be outside the
184 * bounds of the window (including negative values). Capturing is only
185 * allowed for the foreground window. If the window loses focus while
186 * capturing, the capture will be disabled automatically.
187 *
188 * While capturing is enabled, the current window will have the
189 * SDL_WINDOW_MOUSE_CAPTURE flag set.
190 *
191 * \return 0 on success, or -1 if not supported.
192 */
193extern DECLSPEC int SDLCALL SDL_CaptureMouse(SDL_bool enabled);
194
195/**
196 * \brief Query whether relative mouse mode is enabled.
197 *
198 * \sa SDL_SetRelativeMouseMode()
199 */
200extern DECLSPEC SDL_bool SDLCALL SDL_GetRelativeMouseMode(void);
201
202/**
203 * \brief Create a cursor, using the specified bitmap data and
204 * mask (in MSB format).
205 *
206 * The cursor width must be a multiple of 8 bits.
207 *
208 * The cursor is created in black and white according to the following:
209 * <table>
210 * <tr><td> data </td><td> mask </td><td> resulting pixel on screen </td></tr>
211 * <tr><td> 0 </td><td> 1 </td><td> White </td></tr>
212 * <tr><td> 1 </td><td> 1 </td><td> Black </td></tr>
213 * <tr><td> 0 </td><td> 0 </td><td> Transparent </td></tr>
214 * <tr><td> 1 </td><td> 0 </td><td> Inverted color if possible, black
215 * if not. </td></tr>
216 * </table>
217 *
218 * \sa SDL_FreeCursor()
219 */
220extern DECLSPEC SDL_Cursor *SDLCALL SDL_CreateCursor(const Uint8 * data,
221 const Uint8 * mask,
222 int w, int h, int hot_x,
223 int hot_y);
224
225/**
226 * \brief Create a color cursor.
227 *
228 * \sa SDL_FreeCursor()
229 */
230extern DECLSPEC SDL_Cursor *SDLCALL SDL_CreateColorCursor(SDL_Surface *surface,
231 int hot_x,
232 int hot_y);
233
234/**
235 * \brief Create a system cursor.
236 *
237 * \sa SDL_FreeCursor()
238 */
239extern DECLSPEC SDL_Cursor *SDLCALL SDL_CreateSystemCursor(SDL_SystemCursor id);
240
241/**
242 * \brief Set the active cursor.
243 */
244extern DECLSPEC void SDLCALL SDL_SetCursor(SDL_Cursor * cursor);
245
246/**
247 * \brief Return the active cursor.
248 */
249extern DECLSPEC SDL_Cursor *SDLCALL SDL_GetCursor(void);
250
251/**
252 * \brief Return the default cursor.
253 */
254extern DECLSPEC SDL_Cursor *SDLCALL SDL_GetDefaultCursor(void);
255
256/**
257 * \brief Frees a cursor created with SDL_CreateCursor() or similar functions.
258 *
259 * \sa SDL_CreateCursor()
260 * \sa SDL_CreateColorCursor()
261 * \sa SDL_CreateSystemCursor()
262 */
263extern DECLSPEC void SDLCALL SDL_FreeCursor(SDL_Cursor * cursor);
264
265/**
266 * \brief Toggle whether or not the cursor is shown.
267 *
268 * \param toggle 1 to show the cursor, 0 to hide it, -1 to query the current
269 * state.
270 *
271 * \return 1 if the cursor is shown, or 0 if the cursor is hidden.
272 */
273extern DECLSPEC int SDLCALL SDL_ShowCursor(int toggle);
274
275/**
276 * Used as a mask when testing buttons in buttonstate.
277 * - Button 1: Left mouse button
278 * - Button 2: Middle mouse button
279 * - Button 3: Right mouse button
280 */
281#define SDL_BUTTON(X) (1 << ((X)-1))
282#define SDL_BUTTON_LEFT 1
283#define SDL_BUTTON_MIDDLE 2
284#define SDL_BUTTON_RIGHT 3
285#define SDL_BUTTON_X1 4
286#define SDL_BUTTON_X2 5
287#define SDL_BUTTON_LMASK SDL_BUTTON(SDL_BUTTON_LEFT)
288#define SDL_BUTTON_MMASK SDL_BUTTON(SDL_BUTTON_MIDDLE)
289#define SDL_BUTTON_RMASK SDL_BUTTON(SDL_BUTTON_RIGHT)
290#define SDL_BUTTON_X1MASK SDL_BUTTON(SDL_BUTTON_X1)
291#define SDL_BUTTON_X2MASK SDL_BUTTON(SDL_BUTTON_X2)
292
293
294/* Ends C function definitions when using C++ */
295#ifdef __cplusplus
296}
297#endif
298#include "close_code.h"
299
300#endif /* SDL_mouse_h_ */
301
302/* vi: set ts=4 sw=4 expandtab: */
303