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()

int SDL_MouseInit ( void  )

Definition at line 135 of file SDL_mouse.c.

References SDL_Mouse::cursor_shown, SDL_AddHintCallback, SDL_FALSE, SDL_GetMouse(), SDL_HINT_MOUSE_DOUBLE_CLICK_RADIUS, SDL_HINT_MOUSE_DOUBLE_CLICK_TIME, SDL_HINT_MOUSE_NORMAL_SPEED_SCALE, SDL_HINT_MOUSE_RELATIVE_SPEED_SCALE, SDL_HINT_MOUSE_TOUCH_EVENTS, SDL_HINT_TOUCH_MOUSE_EVENTS, SDL_MouseDoubleClickRadiusChanged(), SDL_MouseDoubleClickTimeChanged(), SDL_MouseNormalSpeedScaleChanged(), SDL_MouseRelativeSpeedScaleChanged(), SDL_MouseTouchEventsChanged(), SDL_TouchMouseEventsChanged(), SDL_TRUE, SDL_zerop, and SDL_Mouse::was_touch_mouse_events.

Referenced by SDL_VideoInit().

136 {
137  SDL_Mouse *mouse = SDL_GetMouse();
138 
139  SDL_zerop(mouse);
140 
143 
146 
149 
152 
155 
158 
159  mouse->was_touch_mouse_events = SDL_FALSE; /* no touch to mouse movement event pending */
160 
161  mouse->cursor_shown = SDL_TRUE;
162 
163  return (0);
164 }
#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_Mouse * SDL_GetMouse(void)
Definition: SDL_mouse.c:178
#define SDL_HINT_TOUCH_MOUSE_EVENTS
A variable controlling whether touch events should generate synthetic mouse events.
Definition: SDL_hints.h:316
static void SDL_MouseDoubleClickTimeChanged(void *userdata, const char *name, const char *oldValue, const char *hint)
Definition: SDL_mouse.c:47
#define SDL_HINT_MOUSE_DOUBLE_CLICK_RADIUS
A variable setting the double click radius, in pixels.
Definition: SDL_hints.h:273
static void SDL_TouchMouseEventsChanged(void *userdata, const char *name, const char *oldValue, const char *hint)
Definition: SDL_mouse.c:99
static void SDL_MouseNormalSpeedScaleChanged(void *userdata, const char *name, const char *oldValue, const char *hint)
Definition: SDL_mouse.c:75
#define SDL_zerop(x)
Definition: SDL_stdinc.h:417
static void SDL_MouseTouchEventsChanged(void *userdata, const char *name, const char *oldValue, const char *hint)
Definition: SDL_mouse.c:111
SDL_bool cursor_shown
Definition: SDL_mouse_c.h:106
static void SDL_MouseDoubleClickRadiusChanged(void *userdata, const char *name, const char *oldValue, const char *hint)
Definition: SDL_mouse.c:63
static void SDL_MouseRelativeSpeedScaleChanged(void *userdata, const char *name, const char *oldValue, const char *hint)
Definition: SDL_mouse.c:87
#define SDL_HINT_MOUSE_DOUBLE_CLICK_TIME
A variable setting the double click time, in milliseconds.
Definition: SDL_hints.h:268
#define SDL_HINT_MOUSE_TOUCH_EVENTS
A variable controlling whether mouse events should generate synthetic touch events.
Definition: SDL_hints.h:326
#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
#define SDL_AddHintCallback
SDL_bool was_touch_mouse_events
Definition: SDL_mouse_c.h:97

◆ SDL_MouseQuit()

void SDL_MouseQuit ( void  )

Definition at line 665 of file SDL_mouse.c.

References SDL_Mouse::CaptureMouse, SDL_Mouse::clickstate, SDL_Mouse::cur_cursor, cursor, SDL_Mouse::cursors, SDL_Mouse::def_cursor, SDL_Mouse::FreeCursor, SDL_Cursor::next, NULL, SDL_CaptureMouse(), SDL_DelHintCallback, SDL_FALSE, SDL_free, SDL_FreeCursor(), SDL_GetMouse(), SDL_HINT_MOUSE_NORMAL_SPEED_SCALE, SDL_HINT_MOUSE_RELATIVE_SPEED_SCALE, SDL_MouseNormalSpeedScaleChanged(), SDL_MouseRelativeSpeedScaleChanged(), SDL_SetRelativeMouseMode(), and SDL_ShowCursor().

Referenced by SDL_VideoQuit().

666 {
667  SDL_Cursor *cursor, *next;
668  SDL_Mouse *mouse = SDL_GetMouse();
669 
670  if (mouse->CaptureMouse) {
672  }
674  SDL_ShowCursor(1);
675 
676  cursor = mouse->cursors;
677  while (cursor) {
678  next = cursor->next;
679  SDL_FreeCursor(cursor);
680  cursor = next;
681  }
682  mouse->cursors = NULL;
683  mouse->cur_cursor = NULL;
684 
685  if (mouse->def_cursor && mouse->FreeCursor) {
686  mouse->FreeCursor(mouse->def_cursor);
687  mouse->def_cursor = NULL;
688  }
689 
690  if (mouse->clickstate) {
691  SDL_free(mouse->clickstate);
692  mouse->clickstate = NULL;
693  }
694 
697 
700 }
#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_Mouse * SDL_GetMouse(void)
Definition: SDL_mouse.c:178
SDL_MouseClickState * clickstate
Definition: SDL_mouse_c.h:101
static void SDL_MouseNormalSpeedScaleChanged(void *userdata, const char *name, const char *oldValue, const char *hint)
Definition: SDL_mouse.c:75
int SDL_ShowCursor(int toggle)
Toggle whether or not the cursor is shown.
Definition: SDL_mouse.c:1108
SDL_Cursor * cursors
Definition: SDL_mouse_c.h:103
int SDL_CaptureMouse(SDL_bool enabled)
Capture the mouse, to track input outside an SDL window.
Definition: SDL_mouse.c:861
int(* CaptureMouse)(SDL_Window *window)
Definition: SDL_mouse_c.h:70
#define SDL_free
SDL_Cursor * cursor
Definition: testwm2.c:40
static void SDL_MouseRelativeSpeedScaleChanged(void *userdata, const char *name, const char *oldValue, const char *hint)
Definition: SDL_mouse.c:87
void(* FreeCursor)(SDL_Cursor *cursor)
Definition: SDL_mouse_c.h:58
#define NULL
Definition: begin_code.h:167
struct SDL_Cursor * next
Definition: SDL_mouse_c.h:32
#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
int SDL_SetRelativeMouseMode(SDL_bool enabled)
Set relative mouse mode.
Definition: SDL_mouse.c:799
#define SDL_DelHintCallback
SDL_Cursor * cur_cursor
Definition: SDL_mouse_c.h:105
void SDL_FreeCursor(SDL_Cursor *cursor)
Frees a cursor created with SDL_CreateCursor() or similar functions.
Definition: SDL_mouse.c:1074
SDL_Cursor * def_cursor
Definition: SDL_mouse_c.h:104

◆ SDL_SendMouseButton()

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

Definition at line 605 of file SDL_mouse.c.

References SDL_PrivateSendMouseButton().

Referenced by SDL_BApp::_HandleMouseButton(), SDL_GetMouseFocus(), and SDL_SendTouch().

606 {
607  return SDL_PrivateSendMouseButton(window, mouseID, state, button, -1);
608 }
static int SDL_PrivateSendMouseButton(SDL_Window *window, SDL_MouseID mouseID, Uint8 state, Uint8 button, int clicks)
Definition: SDL_mouse.c:494
SDL_Texture * button
struct xkb_state * state

◆ SDL_SendMouseButtonClicks()

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

Definition at line 598 of file SDL_mouse.c.

References SDL_max, and SDL_PrivateSendMouseButton().

599 {
600  clicks = SDL_max(clicks, 0);
601  return SDL_PrivateSendMouseButton(window, mouseID, state, button, clicks);
602 }
static int SDL_PrivateSendMouseButton(SDL_Window *window, SDL_MouseID mouseID, Uint8 state, Uint8 button, int clicks)
Definition: SDL_mouse.c:494
SDL_Texture * button
struct xkb_state * state
#define SDL_max(x, y)
Definition: SDL_stdinc.h:407

◆ SDL_SendMouseMotion()

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

Definition at line 301 of file SDL_mouse.c.

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

Referenced by SDL_BApp::_HandleMouseMove(), IsSDLWindowEventPending(), SDL_SendTouch(), SDL_SendTouchMotion(), and SDL_WarpMouseInWindow().

302 {
303  if (window && !relative) {
304  SDL_Mouse *mouse = SDL_GetMouse();
305  if (!SDL_UpdateMouseFocus(window, x, y, mouse->buttonstate, (mouseID == SDL_TOUCH_MOUSEID) ? SDL_FALSE : SDL_TRUE)) {
306  return 0;
307  }
308  }
309 
310  return SDL_PrivateSendMouseMotion(window, mouseID, relative, x, y);
311 }
SDL_Mouse * SDL_GetMouse(void)
Definition: SDL_mouse.c:178
static int SDL_PrivateSendMouseMotion(SDL_Window *window, SDL_MouseID mouseID, int relative, int x, int y)
Definition: SDL_mouse.c:329
GLint GLint GLint GLint GLint x
Definition: SDL_opengl.h:1574
Uint32 buttonstate
Definition: SDL_mouse_c.h:85
#define SDL_TOUCH_MOUSEID
Definition: SDL_touch.h:61
static SDL_bool SDL_UpdateMouseFocus(SDL_Window *window, int x, int y, Uint32 buttonstate, SDL_bool send_mouse_motion)
Definition: SDL_mouse.c:249
GLint GLint GLint GLint GLint GLint y
Definition: SDL_opengl.h:1574

◆ SDL_SendMouseWheel()

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

Definition at line 611 of file SDL_mouse.c.

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().

612 {
613  SDL_Mouse *mouse = SDL_GetMouse();
614  int posted;
615  int integral_x, integral_y;
616 
617  if (window) {
618  SDL_SetMouseFocus(window);
619  }
620 
621  if (x == 0.0f && y == 0.0f) {
622  return 0;
623  }
624 
625  mouse->accumulated_wheel_x += x;
626  if (mouse->accumulated_wheel_x > 0) {
627  integral_x = (int)SDL_floor(mouse->accumulated_wheel_x);
628  } else if (mouse->accumulated_wheel_x < 0) {
629  integral_x = (int)SDL_ceil(mouse->accumulated_wheel_x);
630  } else {
631  integral_x = 0;
632  }
633  mouse->accumulated_wheel_x -= integral_x;
634 
635  mouse->accumulated_wheel_y += y;
636  if (mouse->accumulated_wheel_y > 0) {
637  integral_y = (int)SDL_floor(mouse->accumulated_wheel_y);
638  } else if (mouse->accumulated_wheel_y < 0) {
639  integral_y = (int)SDL_ceil(mouse->accumulated_wheel_y);
640  } else {
641  integral_y = 0;
642  }
643  mouse->accumulated_wheel_y -= integral_y;
644 
645  /* Post the event, if desired */
646  posted = 0;
649  event.type = SDL_MOUSEWHEEL;
650  event.wheel.windowID = mouse->focus ? mouse->focus->id : 0;
651  event.wheel.which = mouseID;
652 #if 0 /* Uncomment this when it goes in for SDL 2.1 */
653  event.wheel.preciseX = x;
654  event.wheel.preciseY = y;
655 #endif
656  event.wheel.x = integral_x;
657  event.wheel.y = integral_y;
658  event.wheel.direction = (Uint32)direction;
659  posted = (SDL_PushEvent(&event) > 0);
660  }
661  return posted;
662 }
SDL_Mouse * SDL_GetMouse(void)
Definition: SDL_mouse.c:178
#define SDL_ceil
GLint GLint GLint GLint GLint x
Definition: SDL_opengl.h:1574
SDL_Window * focus
Definition: SDL_mouse_c.h:77
#define SDL_ENABLE
Definition: SDL_events.h:759
GLfloat f
void SDL_SetMouseFocus(SDL_Window *window)
Definition: SDL_mouse.c:211
#define SDL_floor
#define SDL_GetEventState(type)
Definition: SDL_events.h:772
struct _cl_event * event
float accumulated_wheel_y
Definition: SDL_mouse_c.h:84
#define SDL_PushEvent
GLint GLint GLint GLint GLint GLint y
Definition: SDL_opengl.h:1574
uint32_t Uint32
Definition: SDL_stdinc.h:203
Uint32 id
Definition: SDL_sysvideo.h:76
General event structure.
Definition: SDL_events.h:557
float accumulated_wheel_x
Definition: SDL_mouse_c.h:83

◆ SDL_SetDefaultCursor()

void SDL_SetDefaultCursor ( SDL_Cursor cursor)

Definition at line 167 of file SDL_mouse.c.

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

168 {
169  SDL_Mouse *mouse = SDL_GetMouse();
170 
171  mouse->def_cursor = cursor;
172  if (!mouse->cur_cursor) {
173  SDL_SetCursor(cursor);
174  }
175 }
SDL_Mouse * SDL_GetMouse(void)
Definition: SDL_mouse.c:178
void SDL_SetCursor(SDL_Cursor *cursor)
Set the active cursor.
Definition: SDL_mouse.c:1012
SDL_Cursor * cursor
Definition: testwm2.c:40
SDL_Cursor * cur_cursor
Definition: SDL_mouse_c.h:105
SDL_Cursor * def_cursor
Definition: SDL_mouse_c.h:104

◆ SDL_SetMouseFocus()

void SDL_SetMouseFocus ( SDL_Window window)

Definition at line 211 of file SDL_mouse.c.

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().

212 {
213  SDL_Mouse *mouse = SDL_GetMouse();
214 
215  if (mouse->focus == window) {
216  return;
217  }
218 
219  /* Actually, this ends up being a bad idea, because most operating
220  systems have an implicit grab when you press the mouse button down
221  so you can drag things out of the window and then get the mouse up
222  when it happens. So, #if 0...
223  */
224 #if 0
225  if (mouse->focus && !window) {
226  /* We won't get anymore mouse messages, so reset mouse state */
227  SDL_ResetMouse();
228  }
229 #endif
230 
231  /* See if the current window has lost focus */
232  if (mouse->focus) {
234  }
235 
236  mouse->focus = window;
237  mouse->has_position = SDL_FALSE;
238 
239  if (mouse->focus) {
241  }
242 
243  /* Update cursor visibility */
245 }
SDL_Mouse * SDL_GetMouse(void)
Definition: SDL_mouse.c:178
SDL_bool has_position
Definition: SDL_mouse_c.h:86
SDL_Window * focus
Definition: SDL_mouse_c.h:77
void SDL_SetCursor(SDL_Cursor *cursor)
Set the active cursor.
Definition: SDL_mouse.c:1012
int SDL_SendWindowEvent(SDL_Window *window, Uint8 windowevent, int data1, int data2)
#define NULL
Definition: begin_code.h:167
EGLSurface EGLNativeWindowType * window
Definition: eglext.h:1025