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

Definition at line 28 of file SDL_mouse_c.h.

Function Documentation

int SDL_MouseInit ( void  )

Definition at line 106 of file SDL_mouse.c.

References SDL_Mouse::cursor_shown, SDL_AddHintCallback, 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_TOUCH_MOUSE_EVENTS, SDL_MouseDoubleClickRadiusChanged(), SDL_MouseDoubleClickTimeChanged(), SDL_MouseNormalSpeedScaleChanged(), SDL_MouseRelativeSpeedScaleChanged(), SDL_TouchMouseEventsChanged(), SDL_TRUE, and SDL_zerop.

Referenced by SDL_VideoInit().

107 {
108  SDL_Mouse *mouse = SDL_GetMouse();
109 
110  SDL_zerop(mouse);
111 
114 
117 
120 
123 
126 
127  mouse->cursor_shown = SDL_TRUE;
128 
129  return (0);
130 }
#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:144
#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:41
#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:93
static void SDL_MouseNormalSpeedScaleChanged(void *userdata, const char *name, const char *oldValue, const char *hint)
Definition: SDL_mouse.c:69
#define SDL_zerop(x)
Definition: SDL_stdinc.h:417
SDL_bool cursor_shown
Definition: SDL_mouse_c.h:104
static void SDL_MouseDoubleClickRadiusChanged(void *userdata, const char *name, const char *oldValue, const char *hint)
Definition: SDL_mouse.c:57
static void SDL_MouseRelativeSpeedScaleChanged(void *userdata, const char *name, const char *oldValue, const char *hint)
Definition: SDL_mouse.c:81
#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_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
void SDL_MouseQuit ( void  )

Definition at line 592 of file SDL_mouse.c.

References SDL_Mouse::CaptureMouse, SDL_Mouse::clickstate, 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().

593 {
594  SDL_Cursor *cursor, *next;
595  SDL_Mouse *mouse = SDL_GetMouse();
596 
597  if (mouse->CaptureMouse) {
599  }
601  SDL_ShowCursor(1);
602 
603  cursor = mouse->cursors;
604  while (cursor) {
605  next = cursor->next;
606  SDL_FreeCursor(cursor);
607  cursor = next;
608  }
609  mouse->cursors = NULL;
610 
611  if (mouse->def_cursor && mouse->FreeCursor) {
612  mouse->FreeCursor(mouse->def_cursor);
613  mouse->def_cursor = NULL;
614  }
615 
616  if (mouse->clickstate) {
617  SDL_free(mouse->clickstate);
618  mouse->clickstate = NULL;
619  }
620 
623 
626 }
#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:144
SDL_MouseClickState * clickstate
Definition: SDL_mouse_c.h:99
static void SDL_MouseNormalSpeedScaleChanged(void *userdata, const char *name, const char *oldValue, const char *hint)
Definition: SDL_mouse.c:69
int SDL_ShowCursor(int toggle)
Toggle whether or not the cursor is shown.
Definition: SDL_mouse.c:1034
SDL_Cursor * cursors
Definition: SDL_mouse_c.h:101
int SDL_CaptureMouse(SDL_bool enabled)
Capture the mouse, to track input outside an SDL window.
Definition: SDL_mouse.c:787
void(* FreeCursor)(SDL_Cursor *cursor)
Definition: SDL_mouse_c.h:58
#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:81
#define NULL
Definition: begin_code.h:164
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:725
int(* CaptureMouse)(SDL_Window *window)
Definition: SDL_mouse_c.h:70
#define SDL_DelHintCallback
void SDL_FreeCursor(SDL_Cursor *cursor)
Frees a cursor created with SDL_CreateCursor() or similar functions.
Definition: SDL_mouse.c:1000
SDL_Cursor * def_cursor
Definition: SDL_mouse_c.h:102
int SDL_SendMouseButton ( SDL_Window window,
SDL_MouseID  mouseID,
Uint8  state,
Uint8  button 
)

Definition at line 532 of file SDL_mouse.c.

References SDL_PrivateSendMouseButton().

Referenced by SDL_BApp::_HandleMouseButton().

533 {
534  return SDL_PrivateSendMouseButton(window, mouseID, state, button, -1);
535 }
static int SDL_PrivateSendMouseButton(SDL_Window *window, SDL_MouseID mouseID, Uint8 state, Uint8 button, int clicks)
Definition: SDL_mouse.c:440
SDL_Texture * button
struct xkb_state * state
int SDL_SendMouseButtonClicks ( SDL_Window window,
SDL_MouseID  mouseID,
Uint8  state,
Uint8  button,
int  clicks 
)

Definition at line 525 of file SDL_mouse.c.

References SDL_max, and SDL_PrivateSendMouseButton().

526 {
527  clicks = SDL_max(clicks, 0);
528  return SDL_PrivateSendMouseButton(window, mouseID, state, button, clicks);
529 }
static int SDL_PrivateSendMouseButton(SDL_Window *window, SDL_MouseID mouseID, Uint8 state, Uint8 button, int clicks)
Definition: SDL_mouse.c:440
SDL_Texture * button
struct xkb_state * state
#define SDL_max(x, y)
Definition: SDL_stdinc.h:407
int SDL_SendMouseMotion ( SDL_Window window,
SDL_MouseID  mouseID,
int  relative,
int  x,
int  y 
)

Definition at line 263 of file SDL_mouse.c.

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

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

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 }
SDL_Mouse * SDL_GetMouse(void)
Definition: SDL_mouse.c:144
static int SDL_PrivateSendMouseMotion(SDL_Window *window, SDL_MouseID mouseID, int relative, int x, int y)
Definition: SDL_mouse.c:291
GLint GLint GLint GLint GLint x
Definition: SDL_opengl.h:1574
Uint32 buttonstate
Definition: SDL_mouse_c.h:85
GLint GLint GLint GLint GLint GLint y
Definition: SDL_opengl.h:1574
static SDL_bool SDL_UpdateMouseFocus(SDL_Window *window, int x, int y, Uint32 buttonstate)
Definition: SDL_mouse.c:215
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.

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

539 {
540  SDL_Mouse *mouse = SDL_GetMouse();
541  int posted;
542  int integral_x, integral_y;
543 
544  if (window) {
545  SDL_SetMouseFocus(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 }
SDL_Mouse * SDL_GetMouse(void)
Definition: SDL_mouse.c:144
#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:756
void SDL_SetMouseFocus(SDL_Window *window)
Definition: SDL_mouse.c:177
#define SDL_floor
#define SDL_GetEventState(type)
Definition: SDL_events.h:769
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
void SDL_SetDefaultCursor ( SDL_Cursor cursor)

Definition at line 133 of file SDL_mouse.c.

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

134 {
135  SDL_Mouse *mouse = SDL_GetMouse();
136 
137  mouse->def_cursor = cursor;
138  if (!mouse->cur_cursor) {
139  SDL_SetCursor(cursor);
140  }
141 }
SDL_Mouse * SDL_GetMouse(void)
Definition: SDL_mouse.c:144
void SDL_SetCursor(SDL_Cursor *cursor)
Set the active cursor.
Definition: SDL_mouse.c:938
SDL_Cursor * cursor
Definition: testwm2.c:40
SDL_Cursor * cur_cursor
Definition: SDL_mouse_c.h:103
SDL_Cursor * def_cursor
Definition: SDL_mouse_c.h:102
void SDL_SetMouseFocus ( SDL_Window window)

Definition at line 177 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().

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 }
SDL_Mouse * SDL_GetMouse(void)
Definition: SDL_mouse.c:144
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:938
int SDL_SendWindowEvent(SDL_Window *window, Uint8 windowevent, int data1, int data2)
#define NULL
Definition: begin_code.h:164
EGLSurface EGLNativeWindowType * window
Definition: eglext.h:1025