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_SetDoubleClickTime (Uint32 interval)
 
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 80 of file SDL_mouse.c.

References SDL_Mouse::cursor_shown, SDL_AddHintCallback, SDL_GetMouse(), SDL_HINT_MOUSE_NORMAL_SPEED_SCALE, SDL_HINT_MOUSE_RELATIVE_SPEED_SCALE, SDL_HINT_TOUCH_MOUSE_EVENTS, SDL_MouseNormalSpeedScaleChanged(), SDL_MouseRelativeSpeedScaleChanged(), SDL_TouchMouseEventsChanged(), and SDL_TRUE.

Referenced by SDL_VideoInit().

81 {
82  SDL_Mouse *mouse = SDL_GetMouse();
83 
86 
89 
92 
93  mouse->cursor_shown = SDL_TRUE;
94 
95  return (0);
96 }
#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:260
SDL_Mouse * SDL_GetMouse(void)
Definition: SDL_mouse.c:110
#define SDL_HINT_TOUCH_MOUSE_EVENTS
A variable controlling whether touch events should generate synthetic mouse events.
Definition: SDL_hints.h:293
static void SDL_TouchMouseEventsChanged(void *userdata, const char *name, const char *oldValue, const char *hint)
Definition: SDL_mouse.c:67
static void SDL_MouseNormalSpeedScaleChanged(void *userdata, const char *name, const char *oldValue, const char *hint)
Definition: SDL_mouse.c:43
SDL_bool cursor_shown
Definition: SDL_mouse_c.h:102
static void SDL_MouseRelativeSpeedScaleChanged(void *userdata, const char *name, const char *oldValue, const char *hint)
Definition: SDL_mouse.c:55
#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:255
#define SDL_AddHintCallback

◆ SDL_MouseQuit()

void SDL_MouseQuit ( void  )

Definition at line 564 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, 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(), SDL_ShowCursor(), and SDL_zerop.

Referenced by SDL_VideoQuit().

565 {
566  SDL_Cursor *cursor, *next;
567  SDL_Mouse *mouse = SDL_GetMouse();
568 
569  if (mouse->CaptureMouse) {
571  }
573  SDL_ShowCursor(1);
574 
575  cursor = mouse->cursors;
576  while (cursor) {
577  next = cursor->next;
578  SDL_FreeCursor(cursor);
579  cursor = next;
580  }
581 
582  if (mouse->def_cursor && mouse->FreeCursor) {
583  mouse->FreeCursor(mouse->def_cursor);
584  }
585 
586  if (mouse->clickstate) {
587  SDL_free(mouse->clickstate);
588  }
589 
590  SDL_zerop(mouse);
591 
594 
597 }
#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:260
SDL_Mouse * SDL_GetMouse(void)
Definition: SDL_mouse.c:110
SDL_MouseClickState * clickstate
Definition: SDL_mouse_c.h:97
static void SDL_MouseNormalSpeedScaleChanged(void *userdata, const char *name, const char *oldValue, const char *hint)
Definition: SDL_mouse.c:43
int SDL_ShowCursor(int toggle)
Toggle whether or not the cursor is shown.
Definition: SDL_mouse.c:1002
#define SDL_zerop(x)
Definition: SDL_stdinc.h:370
SDL_Cursor * cursors
Definition: SDL_mouse_c.h:99
int SDL_CaptureMouse(SDL_bool enabled)
Capture the mouse, to track input outside an SDL window.
Definition: SDL_mouse.c:755
int(* CaptureMouse)(SDL_Window *window)
Definition: SDL_mouse_c.h:70
void SDL_free(void *mem)
SDL_Cursor * cursor
static void SDL_MouseRelativeSpeedScaleChanged(void *userdata, const char *name, const char *oldValue, const char *hint)
Definition: SDL_mouse.c:55
void(* FreeCursor)(SDL_Cursor *cursor)
Definition: SDL_mouse_c.h:58
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:255
int SDL_SetRelativeMouseMode(SDL_bool enabled)
Set relative mouse mode.
Definition: SDL_mouse.c:696
#define SDL_DelHintCallback
void SDL_FreeCursor(SDL_Cursor *cursor)
Frees a cursor created with SDL_CreateCursor() or similar functions.
Definition: SDL_mouse.c:968
SDL_Cursor * def_cursor
Definition: SDL_mouse_c.h:100

◆ SDL_SendMouseButton()

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

Definition at line 504 of file SDL_mouse.c.

References SDL_PrivateSendMouseButton().

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

505 {
506  return SDL_PrivateSendMouseButton(window, mouseID, state, button, -1);
507 }
static int SDL_PrivateSendMouseButton(SDL_Window *window, SDL_MouseID mouseID, Uint8 state, Uint8 button, int clicks)
Definition: SDL_mouse.c:412
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 497 of file SDL_mouse.c.

References SDL_max, and SDL_PrivateSendMouseButton().

498 {
499  clicks = SDL_max(clicks, 0);
500  return SDL_PrivateSendMouseButton(window, mouseID, state, button, clicks);
501 }
static int SDL_PrivateSendMouseButton(SDL_Window *window, SDL_MouseID mouseID, Uint8 state, Uint8 button, int clicks)
Definition: SDL_mouse.c:412
SDL_Texture * button
struct xkb_state * state
#define SDL_max(x, y)
Definition: SDL_stdinc.h:360

◆ SDL_SendMouseMotion()

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

Definition at line 235 of file SDL_mouse.c.

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

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

236 {
237  if (window && !relative) {
238  SDL_Mouse *mouse = SDL_GetMouse();
239  if (!SDL_UpdateMouseFocus(window, x, y, mouse->buttonstate)) {
240  return 0;
241  }
242  }
243 
244  return SDL_PrivateSendMouseMotion(window, mouseID, relative, x, y);
245 }
SDL_Mouse * SDL_GetMouse(void)
Definition: SDL_mouse.c:110
static int SDL_PrivateSendMouseMotion(SDL_Window *window, SDL_MouseID mouseID, int relative, int x, int y)
Definition: SDL_mouse.c:263
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:187

◆ SDL_SendMouseWheel()

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

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

511 {
512  SDL_Mouse *mouse = SDL_GetMouse();
513  int posted;
514  int integral_x, integral_y;
515 
516  if (window) {
517  SDL_SetMouseFocus(window);
518  }
519 
520  if (!x && !y) {
521  return 0;
522  }
523 
524  mouse->accumulated_wheel_x += x;
525  if (mouse->accumulated_wheel_x > 0) {
526  integral_x = (int)SDL_floor(mouse->accumulated_wheel_x);
527  } else if (mouse->accumulated_wheel_x < 0) {
528  integral_x = (int)SDL_ceil(mouse->accumulated_wheel_x);
529  } else {
530  integral_x = 0;
531  }
532  mouse->accumulated_wheel_x -= integral_x;
533 
534  mouse->accumulated_wheel_y += y;
535  if (mouse->accumulated_wheel_y > 0) {
536  integral_y = (int)SDL_floor(mouse->accumulated_wheel_y);
537  } else if (mouse->accumulated_wheel_y < 0) {
538  integral_y = (int)SDL_ceil(mouse->accumulated_wheel_y);
539  } else {
540  integral_y = 0;
541  }
542  mouse->accumulated_wheel_y -= integral_y;
543 
544  /* Post the event, if desired */
545  posted = 0;
548  event.type = SDL_MOUSEWHEEL;
549  event.wheel.windowID = mouse->focus ? mouse->focus->id : 0;
550  event.wheel.which = mouseID;
551 #if 0 /* Uncomment this when it goes in for SDL 2.1 */
552  event.wheel.preciseX = x;
553  event.wheel.preciseY = y;
554 #endif
555  event.wheel.x = integral_x;
556  event.wheel.y = integral_y;
557  event.wheel.direction = (Uint32)direction;
558  posted = (SDL_PushEvent(&event) > 0);
559  }
560  return posted;
561 }
SDL_Mouse * SDL_GetMouse(void)
Definition: SDL_mouse.c:110
#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:722
void SDL_SetMouseFocus(SDL_Window *window)
Definition: SDL_mouse.c:149
uint32_t Uint32
An unsigned 32-bit integer type.
Definition: SDL_stdinc.h:169
#define SDL_floor
#define SDL_GetEventState(type)
Definition: SDL_events.h:735
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 id
Definition: SDL_sysvideo.h:76
General event structure.
Definition: SDL_events.h:525
float accumulated_wheel_x
Definition: SDL_mouse_c.h:83

◆ SDL_SetDefaultCursor()

void SDL_SetDefaultCursor ( SDL_Cursor cursor)

Definition at line 99 of file SDL_mouse.c.

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

100 {
101  SDL_Mouse *mouse = SDL_GetMouse();
102 
103  mouse->def_cursor = cursor;
104  if (!mouse->cur_cursor) {
105  SDL_SetCursor(cursor);
106  }
107 }
SDL_Mouse * SDL_GetMouse(void)
Definition: SDL_mouse.c:110
void SDL_SetCursor(SDL_Cursor *cursor)
Set the active cursor.
Definition: SDL_mouse.c:906
SDL_Cursor * cursor
SDL_Cursor * cur_cursor
Definition: SDL_mouse_c.h:101
SDL_Cursor * def_cursor
Definition: SDL_mouse_c.h:100

◆ SDL_SetDoubleClickTime()

void SDL_SetDoubleClickTime ( Uint32  interval)

Definition at line 116 of file SDL_mouse.c.

References SDL_double_click_time.

117 {
118  SDL_double_click_time = interval;
119 }
static Uint32 SDL_double_click_time
Definition: SDL_mouse.c:36

◆ SDL_SetMouseFocus()

void SDL_SetMouseFocus ( SDL_Window window)

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

150 {
151  SDL_Mouse *mouse = SDL_GetMouse();
152 
153  if (mouse->focus == window) {
154  return;
155  }
156 
157  /* Actually, this ends up being a bad idea, because most operating
158  systems have an implicit grab when you press the mouse button down
159  so you can drag things out of the window and then get the mouse up
160  when it happens. So, #if 0...
161  */
162 #if 0
163  if (mouse->focus && !window) {
164  /* We won't get anymore mouse messages, so reset mouse state */
165  SDL_ResetMouse();
166  }
167 #endif
168 
169  /* See if the current window has lost focus */
170  if (mouse->focus) {
172  }
173 
174  mouse->focus = window;
175  mouse->has_position = SDL_FALSE;
176 
177  if (mouse->focus) {
179  }
180 
181  /* Update cursor visibility */
183 }
SDL_Mouse * SDL_GetMouse(void)
Definition: SDL_mouse.c:110
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:906
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