Go to the documentation of this file.
21 #include "../SDL_internal.h"
30 #include "../SDL_hints_c.h"
31 #include "../video/SDL_sysvideo.h"
33 #include "../core/windows/SDL_windows.h"
113 #if defined(__ANDROID__) || (defined(__IPHONEOS__) && !defined(__TVOS__))
191 printf(
"Resetting mouse\n");
263 #ifdef SUPPORT_DRAG_OUTSIDE_WINDOW
264 if (!inWindow && !buttonstate) {
270 printf(
"Mouse left window, synthesizing move & focus lost event\n");
272 if (send_mouse_motion) {
282 printf(
"Mouse entered window, synthesizing focus gain & move event\n");
285 if (send_mouse_motion) {
295 if (
window && !relative) {
310 if (*accum >= 0.0
f) {
332 float fx = (float)
x / (
float)
window->w;
333 float fy = (float)
y / (
float)
window->h;
347 int center_x = 0, center_y = 0;
351 if (
x == center_x &&
y == center_y) {
381 }
else if (!xrel && !yrel) {
383 printf(
"Mouse event didn't change state - dropped!\n");
406 int x_max = 0, y_max = 0;
413 if (mouse->
x > x_max) {
420 if (mouse->
y > y_max) {
442 event.motion.windowID = mouse->
focus ? mouse->
focus->
id : 0;
443 event.motion.which = mouseID;
447 event.motion.x = mouse->
x;
448 event.motion.y = mouse->
y;
449 event.motion.xrel = xrel;
450 event.motion.yrel = yrel;
499 float fx = (float)mouse->
x / (
float)
window->w;
500 float fy = (float)mouse->
y / (
float)
window->h;
568 event.button.windowID = mouse->
focus ? mouse->
focus->
id : 0;
569 event.button.which = mouseID;
570 event.button.state =
state;
571 event.button.button =
button;
573 event.button.x = mouse->
x;
574 event.button.y = mouse->
y;
604 int integral_x, integral_y;
610 if (
x == 0.0
f &&
y == 0.0
f) {
639 event.wheel.windowID = mouse->
focus ? mouse->
focus->
id : 0;
640 event.wheel.which = mouseID;
642 event.wheel.preciseX =
x;
643 event.wheel.preciseY =
y;
645 event.wheel.x = integral_x;
646 event.wheel.y = integral_y;
647 event.wheel.direction = (
Uint32)direction;
806 return SDL_SetError(
"No relative mode implementation available");
886 int w,
int h,
int hot_x,
int hot_y)
892 Uint8 datab = 0, maskb = 0;
893 const Uint32 black = 0xFF000000;
894 const Uint32 white = 0xFFFFFFFF;
895 const Uint32 transparent = 0x00000000;
909 for (
y = 0;
y <
h; ++
y) {
911 for (
x = 0;
x <
w; ++
x) {
917 *pixel++ = (datab & 0x80) ? black : white;
919 *pixel++ = (datab & 0x80) ? black : transparent;
951 if ((
hot_x < 0) || (hot_y < 0) ||
953 SDL_SetError(
"Cursor hot spot doesn't lie within cursor");
983 SDL_SetError(
"CreateSystemCursor is not currently supported");
1010 for (found = mouse->
cursors; found; found = found->
next) {
1016 SDL_SetError(
"Cursor not associated with the current mouse");
1080 prev = curr, curr = curr->
next) {
SDL_Mouse * SDL_GetMouse(void)
@ SDL_WINDOW_MOUSE_CAPTURE
static SDL_bool ShouldUseRelativeModeWarp(SDL_Mouse *mouse)
@ SDL_TOUCH_DEVICE_DIRECT
int(* WarpMouseGlobal)(int x, int y)
Uint32 SDL_GetGlobalMouseState(int *x, int *y)
Get the current state of the mouse, in relation to the desktop.
int(* CaptureMouse)(SDL_Window *window)
GLenum GLenum GLenum GLenum GLenum scale
A collection of pixels used in software blitting.
#define SDL_ConvertSurfaceFormat
#define SDL_HINT_TOUCH_MOUSE_EVENTS
A variable controlling whether touch events should generate synthetic mouse events.
SDL_Cursor * SDL_GetCursor(void)
Return the active cursor.
static void SDL_TouchMouseEventsChanged(void *userdata, const char *name, const char *oldValue, const char *hint)
static int SDL_PrivateSendMouseMotion(SDL_Window *window, SDL_MouseID mouseID, int relative, int x, int y)
static void SDL_MouseDoubleClickTimeChanged(void *userdata, const char *name, const char *oldValue, const char *hint)
SDL_Cursor * SDL_CreateColorCursor(SDL_Surface *surface, int hot_x, int hot_y)
Create a color cursor.
SDL_bool touch_mouse_events
GLuint GLuint GLsizei count
int SDL_SendTouch(SDL_TouchID id, SDL_FingerID fingerid, SDL_Window *window, SDL_bool down, float x, float y, float pressure)
static void SDL_MouseNormalSpeedScaleChanged(void *userdata, const char *name, const char *oldValue, const char *hint)
float accumulated_wheel_x
#define SDL_HINT_MOUSE_DOUBLE_CLICK_RADIUS
A variable setting the double click radius, in pixels.
void SDL_SetCursor(SDL_Cursor *cursor)
Set the active cursor.
Uint32 SDL_GetMouseState(int *x, int *y)
Retrieve the current state of the mouse.
int SDL_SendMouseButtonClicks(SDL_Window *window, SDL_MouseID mouseID, Uint8 state, Uint8 button, int clicks)
int(* SetRelativeMouseMode)(SDL_bool enabled)
GLfloat GLfloat GLfloat GLfloat h
void SDL_SetMouseFocus(SDL_Window *window)
void SDL_WarpMouseInWindow(SDL_Window *window, int x, int y)
Moves the mouse to the given position within the window.
int SDL_WarpMouseGlobal(int x, int y)
Moves the mouse to the given position in global screen space.
int SDL_ShowCursor(int toggle)
Toggle whether or not the cursor is shown.
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
The type used to identify a window.
#define SDL_GetKeyboardFocus
static void SDL_MouseTouchEventsChanged(void *userdata, const char *name, const char *oldValue, const char *hint)
#define SDL_TOUCH_MOUSEID
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).
SDL_Cursor * SDL_GetDefaultCursor(void)
Return the default cursor.
#define SDL_GetWindowSize
SDL_bool mouse_touch_events
SDL_bool was_touch_mouse_events
int SDL_CaptureMouse(SDL_bool enabled)
Capture the mouse, to track input outside an SDL window.
#define SDL_GetHintBoolean
void(* MoveCursor)(SDL_Cursor *cursor)
int SDL_AddTouch(SDL_TouchID touchID, SDL_TouchDeviceType type, const char *name)
GLint GLint GLint GLint GLint x
void(* WarpMouse)(SDL_Window *window, int x, int y)
static SDL_bool SDL_UpdateMouseFocus(SDL_Window *window, int x, int y, Uint32 buttonstate, SDL_bool send_mouse_motion)
#define SDL_GetEventState(type)
EGLSurface EGLNativeWindowType * window
static SDL_Mouse SDL_mouse
static SDL_MouseClickState * GetMouseClickState(SDL_Mouse *mouse, Uint8 button)
SDL_bool SDL_GetRelativeMouseMode()
Query whether relative mouse mode is enabled.
GLuint const GLchar * name
float relative_speed_scale
int SDL_SendMouseMotion(SDL_Window *window, SDL_MouseID mouseID, int relative, int x, int y)
SDL_Cursor * SDL_CreateSystemCursor(SDL_SystemCursor id)
Create a system cursor.
static int GetScaledMouseDelta(float scale, int value, float *accum)
SDL_SystemCursor
Cursor types for SDL_CreateSystemCursor().
Uint32 SDL_GetTicks(void)
Get the number of milliseconds since the SDL library initialization.
void SDL_UpdateWindowGrab(SDL_Window *window)
SDL_Cursor *(* CreateSystemCursor)(SDL_SystemCursor id)
@ SDL_PIXELFORMAT_ARGB8888
SDL_bool relative_mode_warp
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
#define SDL_assert(condition)
static void SDL_MouseDoubleClickRadiusChanged(void *userdata, const char *name, const char *oldValue, const char *hint)
float accumulated_wheel_y
int(* ShowCursor)(SDL_Cursor *cursor)
GLint GLint GLint GLint GLint GLint y
int SDL_SendMouseWheel(SDL_Window *window, SDL_MouseID mouseID, float x, float y, SDL_MouseWheelDirection direction)
#define SDL_MOUSE_TOUCHID
#define SDL_CreateRGBSurface
void SDL_SetDefaultCursor(SDL_Cursor *cursor)
int SDL_SetRelativeMouseMode(SDL_bool enabled)
Set relative mouse mode.
#define SDL_HINT_MOUSE_DOUBLE_CLICK_TIME
A variable setting the double click time, in milliseconds.
static void SDL_MouseRelativeSpeedScaleChanged(void *userdata, const char *name, const char *oldValue, const char *hint)
#define SDL_AddHintCallback
GLsizei const GLfloat * value
SDL_MouseClickState * clickstate
#define SDL_HINT_MOUSE_TOUCH_EVENTS
A variable controlling whether mouse events should generate synthetic touch events.
int SDL_SendTouchMotion(SDL_TouchID id, SDL_FingerID fingerid, SDL_Window *window, float x, float y, float pressure)
void(* FreeCursor)(SDL_Cursor *cursor)
#define SDL_HINT_MOUSE_NORMAL_SPEED_SCALE
A variable setting the speed scale for mouse motion, in floating point, when the mouse is not in rela...
SDL_Cursor *(* CreateCursor)(SDL_Surface *surface, int hot_x, int hot_y)
int SDL_SendWindowEvent(SDL_Window *window, Uint8 windowevent, int data1, int data2)
Uint32(* GetGlobalMouseState)(int *x, int *y)
GLenum GLenum GLsizei const GLuint GLboolean enabled
SDL_bool SDL_GetStringBoolean(const char *value, SDL_bool default_value)
#define SDL_TICKS_PASSED(A, B)
Compare SDL ticks values, and return true if A has passed B.
void SDL_FreeCursor(SDL_Cursor *cursor)
Frees a cursor created with SDL_CreateCursor() or similar functions.
SDL_Window * SDL_GetMouseFocus(void)
Get the window which currently has mouse focus.
#define SDL_DelHintCallback
#define SDL_Unsupported()
static SDL_bool track_mouse_down
SDL_MouseWheelDirection
Scroll direction types for the Scroll event.
#define SDL_HINT_MOUSE_RELATIVE_MODE_WARP
A variable controlling whether relative mouse mode is implemented using mouse warping.
Uint32 SDL_GetRelativeMouseState(int *x, int *y)
Retrieve the relative state of the mouse.
GLuint GLuint GLsizei GLenum type
return Display return Display Bool Bool int int int return Display XEvent Bool(*) XPointer return Display return Display Drawable _Xconst char unsigned int unsigned int return Display Pixmap Pixmap XColor XColor unsigned int unsigned int return Display _Xconst char char int char return Display Visual unsigned int int int char unsigned int unsigned int in i)
int SDL_SendMouseButton(SDL_Window *window, SDL_MouseID mouseID, Uint8 state, Uint8 button)
#define SDL_HINT_MOUSE_RELATIVE_SPEED_SCALE
A variable setting the scale for mouse motion, in floating point, when the mouse is in relative mode.
GLubyte GLubyte GLubyte GLubyte w
static int SDL_PrivateSendMouseButton(SDL_Window *window, SDL_MouseID mouseID, Uint8 state, Uint8 button, int clicks)