SDL  2.0
SDL_mouse.h
Go to the documentation of this file.
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
38 extern "C" {
39 #endif
40 
41 typedef struct SDL_Cursor SDL_Cursor; /**< Implementation dependent */
42 
43 /**
44  * \brief Cursor types for SDL_CreateSystemCursor().
45  */
46 typedef 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 */
62 
63 /**
64  * \brief Scroll direction types for the Scroll event
65  */
66 typedef enum
67 {
68  SDL_MOUSEWHEEL_NORMAL, /**< The scroll direction is normal */
69  SDL_MOUSEWHEEL_FLIPPED /**< The scroll direction is flipped / natural */
71 
72 /* Function prototypes */
73 
74 /**
75  * \brief Get the window which currently has mouse focus.
76  */
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  */
87 extern 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  */
112 extern 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  */
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  */
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  */
144 extern 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  */
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  */
194 
195 /**
196  * \brief Query whether relative mouse mode is enabled.
197  *
198  * \sa SDL_SetRelativeMouseMode()
199  */
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  */
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  */
231  int hot_x,
232  int hot_y);
233 
234 /**
235  * \brief Create a system cursor.
236  *
237  * \sa SDL_FreeCursor()
238  */
240 
241 /**
242  * \brief Set the active cursor.
243  */
245 
246 /**
247  * \brief Return the active cursor.
248  */
250 
251 /**
252  * \brief Return the default cursor.
253  */
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  */
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  */
273 extern 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: */
Uint8
uint8_t Uint8
Definition: SDL_stdinc.h:179
SDL_GetRelativeMouseMode
SDL_bool SDL_GetRelativeMouseMode(void)
Query whether relative mouse mode is enabled.
Definition: SDL_dynapi_procs.h:281
DECLSPEC
#define DECLSPEC
Definition: SDL_internal.h:44
SDL_CreateColorCursor
SDL_Cursor * SDL_CreateColorCursor(SDL_Surface *surface, int hot_x, int hot_y)
Create a color cursor.
Definition: SDL_mouse.c:871
SDL_SYSTEM_CURSOR_HAND
@ SDL_SYSTEM_CURSOR_HAND
Definition: SDL_mouse.h:59
SDL_NUM_SYSTEM_CURSORS
@ SDL_NUM_SYSTEM_CURSORS
Definition: SDL_mouse.h:60
mask
GLenum GLint GLuint mask
Definition: SDL_opengl_glext.h:657
SDL_GetCursor
SDL_Cursor * SDL_GetCursor(void)
Return the active cursor.
Definition: SDL_mouse.c:978
SDL_Surface
A collection of pixels used in software blitting.
Definition: SDL_surface.h:70
SDL_Cursor
Definition: SDL_mouse_c.h:31
SDL_SYSTEM_CURSOR_WAITARROW
@ SDL_SYSTEM_CURSOR_WAITARROW
Definition: SDL_mouse.h:52
surface
EGLSurface surface
Definition: eglext.h:248
SDL_SYSTEM_CURSOR_CROSSHAIR
@ SDL_SYSTEM_CURSOR_CROSSHAIR
Definition: SDL_mouse.h:51
SDL_SYSTEM_CURSOR_SIZENESW
@ SDL_SYSTEM_CURSOR_SIZENESW
Definition: SDL_mouse.h:54
SDL_error.h
SDLCALL
#define SDLCALL
Definition: SDL_internal.h:45
SDL_GetMouseFocus
SDL_Window * SDL_GetMouseFocus(void)
Get the window which currently has mouse focus.
Definition: SDL_mouse.c:150
Uint32
uint32_t Uint32
Definition: SDL_stdinc.h:203
SDL_WarpMouseInWindow
void SDL_WarpMouseInWindow(SDL_Window *window, int x, int y)
Moves the mouse to the given position within the window.
Definition: SDL_mouse.c:682
h
GLfloat GLfloat GLfloat GLfloat h
Definition: SDL_opengl_glext.h:1946
close_code.h
data
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: SDL_opengl.h:1974
SDL_Window
The type used to identify a window.
Definition: SDL_sysvideo.h:74
begin_code.h
x
GLint GLint GLint GLint GLint x
Definition: SDL_opengl.h:1574
window
EGLSurface EGLNativeWindowType * window
Definition: eglext.h:1025
SDL_CaptureMouse
int SDL_CaptureMouse(SDL_bool enabled)
Capture the mouse, to track input outside an SDL window.
Definition: SDL_mouse.c:787
SDL_WarpMouseGlobal
int SDL_WarpMouseGlobal(int x, int y)
Moves the mouse to the given position in global screen space.
Definition: SDL_mouse.c:702
SDL_CreateSystemCursor
SDL_Cursor * SDL_CreateSystemCursor(SDL_SystemCursor id)
Create a system cursor.
Definition: SDL_mouse.c:914
SDL_CreateCursor
SDL_Cursor * SDL_CreateCursor(const Uint8 *data, const Uint8 *mask, int w, int h, int hot_x, int hot_y)
Create a cursor, using the specified bitmap data and mask (in MSB format).
Definition: SDL_mouse.c:822
SDL_GetRelativeMouseState
Uint32 SDL_GetRelativeMouseState(int *x, int *y)
Retrieve the relative state of the mouse.
Definition: SDL_mouse.c:643
SDL_SYSTEM_CURSOR_SIZEALL
@ SDL_SYSTEM_CURSOR_SIZEALL
Definition: SDL_mouse.h:57
SDL_SystemCursor
SDL_SystemCursor
Cursor types for SDL_CreateSystemCursor().
Definition: SDL_mouse.h:47
SDL_SYSTEM_CURSOR_IBEAM
@ SDL_SYSTEM_CURSOR_IBEAM
Definition: SDL_mouse.h:49
SDL_GetDefaultCursor
SDL_Cursor * SDL_GetDefaultCursor(void)
Return the default cursor.
Definition: SDL_dynapi_procs.h:287
hot_x
int uint32_t uint32_t uint32_t uint32_t uint32_t int drmModeModeInfoPtr mode int uint32_t uint32_t uint32_t uint32_t int32_t hot_x
Definition: SDL_kmsdrmsym.h:57
SDL_MOUSEWHEEL_FLIPPED
@ SDL_MOUSEWHEEL_FLIPPED
Definition: SDL_mouse.h:69
SDL_SetCursor
void SDL_SetCursor(SDL_Cursor *cursor)
Set the active cursor.
Definition: SDL_mouse.c:938
cursor
SDL_Cursor * cursor
Definition: testwm2.c:40
y
GLint GLint GLint GLint GLint GLint y
Definition: SDL_opengl.h:1574
SDL_SYSTEM_CURSOR_NO
@ SDL_SYSTEM_CURSOR_NO
Definition: SDL_mouse.h:58
SDL_FreeCursor
void SDL_FreeCursor(SDL_Cursor *cursor)
Frees a cursor created with SDL_CreateCursor() or similar functions.
Definition: SDL_mouse.c:1000
SDL_SYSTEM_CURSOR_WAIT
@ SDL_SYSTEM_CURSOR_WAIT
Definition: SDL_mouse.h:50
SDL_stdinc.h
SDL_GetMouseState
Uint32 SDL_GetMouseState(int *x, int *y)
Retrieve the current state of the mouse.
Definition: SDL_mouse.c:629
SDL_SYSTEM_CURSOR_SIZEWE
@ SDL_SYSTEM_CURSOR_SIZEWE
Definition: SDL_mouse.h:55
enabled
GLenum GLenum GLsizei const GLuint GLboolean enabled
Definition: SDL_opengl_glext.h:2479
SDL_bool
SDL_bool
Definition: SDL_stdinc.h:162
SDL_MOUSEWHEEL_NORMAL
@ SDL_MOUSEWHEEL_NORMAL
Definition: SDL_mouse.h:68
SDL_video.h
SDL_SYSTEM_CURSOR_SIZENWSE
@ SDL_SYSTEM_CURSOR_SIZENWSE
Definition: SDL_mouse.h:53
SDL_MouseWheelDirection
SDL_MouseWheelDirection
Scroll direction types for the Scroll event.
Definition: SDL_mouse.h:67
SDL_SYSTEM_CURSOR_ARROW
@ SDL_SYSTEM_CURSOR_ARROW
Definition: SDL_mouse.h:48
SDL_SYSTEM_CURSOR_SIZENS
@ SDL_SYSTEM_CURSOR_SIZENS
Definition: SDL_mouse.h:56
SDL_ShowCursor
int SDL_ShowCursor(int toggle)
Toggle whether or not the cursor is shown.
Definition: SDL_mouse.c:1034
SDL_SetRelativeMouseMode
int SDL_SetRelativeMouseMode(SDL_bool enabled)
Set relative mouse mode.
Definition: SDL_mouse.c:725
w
GLubyte GLubyte GLubyte GLubyte w
Definition: SDL_opengl_glext.h:731
SDL_GetGlobalMouseState
Uint32 SDL_GetGlobalMouseState(int *x, int *y)
Get the current state of the mouse, in relation to the desktop.
Definition: SDL_mouse.c:659