SDL  2.0
SDL_mouse_c.h File Reference
#include "../SDL_internal.h"
#include "SDL_mouse.h"
+ Include dependency graph for SDL_mouse_c.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  SDL_Cursor
 
struct  SDL_MouseClickState
 
struct  SDL_Mouse
 

Typedefs

typedef Uint32 SDL_MouseID
 

Functions

int SDL_MouseInit (void)
 
SDL_MouseSDL_GetMouse (void)
 
void SDL_SetDefaultCursor (SDL_Cursor *cursor)
 
void SDL_SetMouseFocus (SDL_Window *window)
 
int SDL_SendMouseMotion (SDL_Window *window, SDL_MouseID mouseID, int relative, int x, int y)
 
int SDL_SendMouseButton (SDL_Window *window, SDL_MouseID mouseID, Uint8 state, Uint8 button)
 
int SDL_SendMouseButtonClicks (SDL_Window *window, SDL_MouseID mouseID, Uint8 state, Uint8 button, int clicks)
 
int SDL_SendMouseWheel (SDL_Window *window, SDL_MouseID mouseID, float x, float y, SDL_MouseWheelDirection direction)
 
void SDL_MouseQuit (void)
 

Typedef Documentation

◆ SDL_MouseID

Definition at line 28 of file SDL_mouse_c.h.

Function Documentation

◆ SDL_GetMouse()

◆ SDL_MouseInit()

◆ SDL_MouseQuit()

◆ SDL_SendMouseButton()

int SDL_SendMouseButton ( SDL_Window window,
SDL_MouseID  mouseID,
Uint8  state,
Uint8  button 
)

Definition at line 532 of file SDL_mouse.c.

533 {
534  return SDL_PrivateSendMouseButton(window, mouseID, state, button, -1);
535 }

References button, SDL_PrivateSendMouseButton(), and state.

Referenced by SDL_BApp::_HandleMouseButton().

◆ SDL_SendMouseButtonClicks()

int SDL_SendMouseButtonClicks ( SDL_Window window,
SDL_MouseID  mouseID,
Uint8  state,
Uint8  button,
int  clicks 
)

Definition at line 525 of file SDL_mouse.c.

526 {
527  clicks = SDL_max(clicks, 0);
528  return SDL_PrivateSendMouseButton(window, mouseID, state, button, clicks);
529 }

References button, SDL_max, SDL_PrivateSendMouseButton(), and state.

◆ SDL_SendMouseMotion()

int SDL_SendMouseMotion ( SDL_Window window,
SDL_MouseID  mouseID,
int  relative,
int  x,
int  y 
)

Definition at line 263 of file SDL_mouse.c.

264 {
265  if (window && !relative) {
266  SDL_Mouse *mouse = SDL_GetMouse();
267  if (!SDL_UpdateMouseFocus(window, x, y, mouse->buttonstate)) {
268  return 0;
269  }
270  }
271 
272  return SDL_PrivateSendMouseMotion(window, mouseID, relative, x, y);
273 }

References SDL_Mouse::buttonstate, SDL_GetMouse(), SDL_PrivateSendMouseMotion(), and SDL_UpdateMouseFocus().

Referenced by SDL_BApp::_HandleMouseMove(), and SDL_WarpMouseInWindow().

◆ SDL_SendMouseWheel()

int SDL_SendMouseWheel ( SDL_Window window,
SDL_MouseID  mouseID,
float  x,
float  y,
SDL_MouseWheelDirection  direction 
)

Definition at line 538 of file SDL_mouse.c.

539 {
540  SDL_Mouse *mouse = SDL_GetMouse();
541  int posted;
542  int integral_x, integral_y;
543 
544  if (window) {
546  }
547 
548  if (!x && !y) {
549  return 0;
550  }
551 
552  mouse->accumulated_wheel_x += x;
553  if (mouse->accumulated_wheel_x > 0) {
554  integral_x = (int)SDL_floor(mouse->accumulated_wheel_x);
555  } else if (mouse->accumulated_wheel_x < 0) {
556  integral_x = (int)SDL_ceil(mouse->accumulated_wheel_x);
557  } else {
558  integral_x = 0;
559  }
560  mouse->accumulated_wheel_x -= integral_x;
561 
562  mouse->accumulated_wheel_y += y;
563  if (mouse->accumulated_wheel_y > 0) {
564  integral_y = (int)SDL_floor(mouse->accumulated_wheel_y);
565  } else if (mouse->accumulated_wheel_y < 0) {
566  integral_y = (int)SDL_ceil(mouse->accumulated_wheel_y);
567  } else {
568  integral_y = 0;
569  }
570  mouse->accumulated_wheel_y -= integral_y;
571 
572  /* Post the event, if desired */
573  posted = 0;
576  event.type = SDL_MOUSEWHEEL;
577  event.wheel.windowID = mouse->focus ? mouse->focus->id : 0;
578  event.wheel.which = mouseID;
579 #if 0 /* Uncomment this when it goes in for SDL 2.1 */
580  event.wheel.preciseX = x;
581  event.wheel.preciseY = y;
582 #endif
583  event.wheel.x = integral_x;
584  event.wheel.y = integral_y;
585  event.wheel.direction = (Uint32)direction;
586  posted = (SDL_PushEvent(&event) > 0);
587  }
588  return posted;
589 }

References SDL_Mouse::accumulated_wheel_x, SDL_Mouse::accumulated_wheel_y, SDL_Mouse::focus, SDL_Window::id, SDL_ceil, SDL_ENABLE, SDL_floor, SDL_GetEventState, SDL_GetMouse(), SDL_MOUSEWHEEL, SDL_PushEvent, and SDL_SetMouseFocus().

Referenced by SDL_BApp::_HandleMouseWheel().

◆ SDL_SetDefaultCursor()

void SDL_SetDefaultCursor ( SDL_Cursor cursor)

Definition at line 133 of file SDL_mouse.c.

134 {
135  SDL_Mouse *mouse = SDL_GetMouse();
136 
137  mouse->def_cursor = cursor;
138  if (!mouse->cur_cursor) {
140  }
141 }

References SDL_Mouse::cur_cursor, cursor, SDL_Mouse::def_cursor, SDL_GetMouse(), and SDL_SetCursor().

◆ SDL_SetMouseFocus()

void SDL_SetMouseFocus ( SDL_Window window)

Definition at line 177 of file SDL_mouse.c.

178 {
179  SDL_Mouse *mouse = SDL_GetMouse();
180 
181  if (mouse->focus == window) {
182  return;
183  }
184 
185  /* Actually, this ends up being a bad idea, because most operating
186  systems have an implicit grab when you press the mouse button down
187  so you can drag things out of the window and then get the mouse up
188  when it happens. So, #if 0...
189  */
190 #if 0
191  if (mouse->focus && !window) {
192  /* We won't get anymore mouse messages, so reset mouse state */
193  SDL_ResetMouse();
194  }
195 #endif
196 
197  /* See if the current window has lost focus */
198  if (mouse->focus) {
200  }
201 
202  mouse->focus = window;
203  mouse->has_position = SDL_FALSE;
204 
205  if (mouse->focus) {
207  }
208 
209  /* Update cursor visibility */
211 }

References SDL_Mouse::focus, SDL_Mouse::has_position, NULL, SDL_FALSE, SDL_GetMouse(), SDL_SendWindowEvent(), SDL_SetCursor(), SDL_WINDOWEVENT_ENTER, and SDL_WINDOWEVENT_LEAVE.

Referenced by SDL_BApp::_HandleMouseFocus(), SDL_DestroyWindow(), SDL_OnWindowFocusGained(), SDL_SendMouseWheel(), SDL_SetRelativeMouseMode(), and SDL_UpdateMouseFocus().

SDL_GetMouse
SDL_Mouse * SDL_GetMouse(void)
Definition: SDL_mouse.c:144
SDL_Mouse::CaptureMouse
int(* CaptureMouse)(SDL_Window *window)
Definition: SDL_mouse_c.h:70
SDL_Mouse::buttonstate
Uint32 buttonstate
Definition: SDL_mouse_c.h:85
SDL_Cursor
Definition: SDL_mouse_c.h:31
SDL_HINT_TOUCH_MOUSE_EVENTS
#define SDL_HINT_TOUCH_MOUSE_EVENTS
A variable controlling whether touch events should generate synthetic mouse events.
Definition: SDL_hints.h:316
SDL_Mouse::cursors
SDL_Cursor * cursors
Definition: SDL_mouse_c.h:101
SDL_ceil
#define SDL_ceil
Definition: SDL_dynapi_overrides.h:426
NULL
#define NULL
Definition: begin_code.h:164
SDL_TouchMouseEventsChanged
static void SDL_TouchMouseEventsChanged(void *userdata, const char *name, const char *oldValue, const char *hint)
Definition: SDL_mouse.c:93
SDL_PrivateSendMouseMotion
static int SDL_PrivateSendMouseMotion(SDL_Window *window, SDL_MouseID mouseID, int relative, int x, int y)
Definition: SDL_mouse.c:291
SDL_zerop
#define SDL_zerop(x)
Definition: SDL_stdinc.h:417
SDL_MouseDoubleClickTimeChanged
static void SDL_MouseDoubleClickTimeChanged(void *userdata, const char *name, const char *oldValue, const char *hint)
Definition: SDL_mouse.c:41
SDL_WINDOWEVENT_ENTER
@ SDL_WINDOWEVENT_ENTER
Definition: SDL_video.h:163
SDL_MouseNormalSpeedScaleChanged
static void SDL_MouseNormalSpeedScaleChanged(void *userdata, const char *name, const char *oldValue, const char *hint)
Definition: SDL_mouse.c:69
SDL_Mouse::accumulated_wheel_x
float accumulated_wheel_x
Definition: SDL_mouse_c.h:83
SDL_HINT_MOUSE_DOUBLE_CLICK_RADIUS
#define SDL_HINT_MOUSE_DOUBLE_CLICK_RADIUS
A variable setting the double click radius, in pixels.
Definition: SDL_hints.h:273
SDL_SetCursor
void SDL_SetCursor(SDL_Cursor *cursor)
Set the active cursor.
Definition: SDL_mouse.c:938
SDL_floor
#define SDL_floor
Definition: SDL_dynapi_overrides.h:431
Uint32
uint32_t Uint32
Definition: SDL_stdinc.h:203
SDL_ENABLE
#define SDL_ENABLE
Definition: SDL_events.h:756
SDL_SetMouseFocus
void SDL_SetMouseFocus(SDL_Window *window)
Definition: SDL_mouse.c:177
SDL_ShowCursor
int SDL_ShowCursor(int toggle)
Toggle whether or not the cursor is shown.
Definition: SDL_mouse.c:1034
SDL_CaptureMouse
int SDL_CaptureMouse(SDL_bool enabled)
Capture the mouse, to track input outside an SDL window.
Definition: SDL_mouse.c:787
event
struct _cl_event * event
Definition: SDL_opengl_glext.h:2649
x
GLint GLint GLint GLint GLint x
Definition: SDL_opengl.h:1574
SDL_GetEventState
#define SDL_GetEventState(type)
Definition: SDL_events.h:769
window
EGLSurface EGLNativeWindowType * window
Definition: eglext.h:1025
SDL_free
#define SDL_free
Definition: SDL_dynapi_overrides.h:377
SDL_PushEvent
#define SDL_PushEvent
Definition: SDL_dynapi_overrides.h:125
SDL_max
#define SDL_max(x, y)
Definition: SDL_stdinc.h:407
SDL_mouse
static SDL_Mouse SDL_mouse
Definition: SDL_mouse.c:35
SDL_Mouse::def_cursor
SDL_Cursor * def_cursor
Definition: SDL_mouse_c.h:102
SDL_MOUSEWHEEL
@ SDL_MOUSEWHEEL
Definition: SDL_events.h:108
SDL_Cursor::next
struct SDL_Cursor * next
Definition: SDL_mouse_c.h:32
SDL_Mouse
Definition: SDL_mouse_c.h:44
SDL_TRUE
@ SDL_TRUE
Definition: SDL_stdinc.h:164
SDL_UpdateMouseFocus
static SDL_bool SDL_UpdateMouseFocus(SDL_Window *window, int x, int y, Uint32 buttonstate)
Definition: SDL_mouse.c:215
SDL_MouseDoubleClickRadiusChanged
static void SDL_MouseDoubleClickRadiusChanged(void *userdata, const char *name, const char *oldValue, const char *hint)
Definition: SDL_mouse.c:57
SDL_Mouse::focus
SDL_Window * focus
Definition: SDL_mouse_c.h:77
SDL_Mouse::accumulated_wheel_y
float accumulated_wheel_y
Definition: SDL_mouse_c.h:84
cursor
SDL_Cursor * cursor
Definition: testwm2.c:40
y
GLint GLint GLint GLint GLint GLint y
Definition: SDL_opengl.h:1574
SDL_SetRelativeMouseMode
int SDL_SetRelativeMouseMode(SDL_bool enabled)
Set relative mouse mode.
Definition: SDL_mouse.c:725
SDL_HINT_MOUSE_DOUBLE_CLICK_TIME
#define SDL_HINT_MOUSE_DOUBLE_CLICK_TIME
A variable setting the double click time, in milliseconds.
Definition: SDL_hints.h:268
SDL_MouseRelativeSpeedScaleChanged
static void SDL_MouseRelativeSpeedScaleChanged(void *userdata, const char *name, const char *oldValue, const char *hint)
Definition: SDL_mouse.c:81
SDL_AddHintCallback
#define SDL_AddHintCallback
Definition: SDL_dynapi_overrides.h:192
SDL_Mouse::clickstate
SDL_MouseClickState * clickstate
Definition: SDL_mouse_c.h:99
SDL_Window::id
Uint32 id
Definition: SDL_sysvideo.h:76
SDL_Mouse::has_position
SDL_bool has_position
Definition: SDL_mouse_c.h:86
SDL_Mouse::FreeCursor
void(* FreeCursor)(SDL_Cursor *cursor)
Definition: SDL_mouse_c.h:58
SDL_HINT_MOUSE_NORMAL_SPEED_SCALE
#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...
Definition: SDL_hints.h:278
SDL_SendWindowEvent
int SDL_SendWindowEvent(SDL_Window *window, Uint8 windowevent, int data1, int data2)
Definition: SDL_windowevents.c:74
SDL_FreeCursor
void SDL_FreeCursor(SDL_Cursor *cursor)
Frees a cursor created with SDL_CreateCursor() or similar functions.
Definition: SDL_mouse.c:1000
SDL_Event
General event structure.
Definition: SDL_events.h:558
SDL_DelHintCallback
#define SDL_DelHintCallback
Definition: SDL_dynapi_overrides.h:193
SDL_FALSE
@ SDL_FALSE
Definition: SDL_stdinc.h:163
state
struct xkb_state * state
Definition: SDL_waylandsym.h:113
button
SDL_Texture * button
Definition: testgamecontroller.c:67
SDL_Mouse::cur_cursor
SDL_Cursor * cur_cursor
Definition: SDL_mouse_c.h:103
SDL_HINT_MOUSE_RELATIVE_SPEED_SCALE
#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.
Definition: SDL_hints.h:283
SDL_WINDOWEVENT_LEAVE
@ SDL_WINDOWEVENT_LEAVE
Definition: SDL_video.h:164
SDL_Mouse::cursor_shown
SDL_bool cursor_shown
Definition: SDL_mouse_c.h:104
SDL_PrivateSendMouseButton
static int SDL_PrivateSendMouseButton(SDL_Window *window, SDL_MouseID mouseID, Uint8 state, Uint8 button, int clicks)
Definition: SDL_mouse.c:440