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_SendMouseWheel (SDL_Window *window, SDL_MouseID mouseID, int x, int 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 45 of file SDL_mouse.c.

References SDL_Mouse::cursor_shown, SDL_GetMouse(), and SDL_TRUE.

Referenced by SDL_VideoInit().

46 {
47  SDL_Mouse *mouse = SDL_GetMouse();
48 
49  mouse->cursor_shown = SDL_TRUE;
50 
51  return (0);
52 }
SDL_Mouse * SDL_GetMouse(void)
Definition: SDL_mouse.c:66
SDL_bool cursor_shown
Definition: SDL_mouse_c.h:94
void SDL_MouseQuit ( void  )

Definition at line 435 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_FALSE, SDL_free(), SDL_FreeCursor(), SDL_GetMouse(), SDL_SetRelativeMouseMode(), SDL_ShowCursor(), and SDL_zerop.

Referenced by SDL_VideoQuit().

436 {
437  SDL_Cursor *cursor, *next;
438  SDL_Mouse *mouse = SDL_GetMouse();
439 
440  if (mouse->CaptureMouse) {
442  }
444  SDL_ShowCursor(1);
445 
446  cursor = mouse->cursors;
447  while (cursor) {
448  next = cursor->next;
449  SDL_FreeCursor(cursor);
450  cursor = next;
451  }
452 
453  if (mouse->def_cursor && mouse->FreeCursor) {
454  mouse->FreeCursor(mouse->def_cursor);
455  }
456 
457  if (mouse->clickstate) {
458  SDL_free(mouse->clickstate);
459  }
460 
461  SDL_zerop(mouse);
462 }
SDL_Mouse * SDL_GetMouse(void)
Definition: SDL_mouse.c:66
SDL_MouseClickState * clickstate
Definition: SDL_mouse_c.h:89
int SDL_ShowCursor(int toggle)
Toggle whether or not the cursor is shown.
Definition: SDL_mouse.c:875
#define SDL_zerop(x)
Definition: SDL_stdinc.h:356
SDL_Cursor * cursors
Definition: SDL_mouse_c.h:91
int SDL_CaptureMouse(SDL_bool enabled)
Capture the mouse, to track input outside an SDL window.
Definition: SDL_mouse.c:628
int(* CaptureMouse)(SDL_Window *window)
Definition: SDL_mouse_c.h:70
void SDL_free(void *mem)
SDL_Cursor * cursor
Definition: testwm2.c:40
void(* FreeCursor)(SDL_Cursor *cursor)
Definition: SDL_mouse_c.h:58
struct SDL_Cursor * next
Definition: SDL_mouse_c.h:32
int SDL_SetRelativeMouseMode(SDL_bool enabled)
Set relative mouse mode.
Definition: SDL_mouse.c:571
void SDL_FreeCursor(SDL_Cursor *cursor)
Frees a cursor created with SDL_CreateCursor().
Definition: SDL_mouse.c:841
SDL_Cursor * def_cursor
Definition: SDL_mouse_c.h:92
int SDL_SendMouseButton ( SDL_Window window,
SDL_MouseID  mouseID,
Uint8  state,
Uint8  button 
)

Definition at line 326 of file SDL_mouse.c.

References button, SDL_Mouse::buttonstate, SDL_MouseClickState::click_count, SDL_Mouse::focus, GetMouseClickState(), SDL_Window::id, SDL_MouseClickState::last_timestamp, SDL_MouseClickState::last_x, SDL_MouseClickState::last_y, SDL_abs, SDL_BUTTON, SDL_double_click_radius, SDL_double_click_time, SDL_ENABLE, SDL_GetEventState, SDL_GetMouse(), SDL_GetTicks(), SDL_MOUSEBUTTONDOWN, SDL_MOUSEBUTTONUP, SDL_PRESSED, SDL_PushEvent, SDL_RELEASED, SDL_TICKS_PASSED, SDL_UpdateMouseFocus(), state, SDL_Mouse::x, and SDL_Mouse::y.

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

327 {
328  SDL_Mouse *mouse = SDL_GetMouse();
329  int posted;
330  Uint32 type;
331  Uint32 buttonstate = mouse->buttonstate;
332  SDL_MouseClickState *clickstate = GetMouseClickState(mouse, button);
333  Uint8 click_count;
334 
335  /* Figure out which event to perform */
336  switch (state) {
337  case SDL_PRESSED:
338  type = SDL_MOUSEBUTTONDOWN;
339  buttonstate |= SDL_BUTTON(button);
340  break;
341  case SDL_RELEASED:
342  type = SDL_MOUSEBUTTONUP;
343  buttonstate &= ~SDL_BUTTON(button);
344  break;
345  default:
346  /* Invalid state -- bail */
347  return 0;
348  }
349 
350  /* We do this after calculating buttonstate so button presses gain focus */
351  if (window && state == SDL_PRESSED) {
352  SDL_UpdateMouseFocus(window, mouse->x, mouse->y, buttonstate);
353  }
354 
355  if (buttonstate == mouse->buttonstate) {
356  /* Ignore this event, no state change */
357  return 0;
358  }
359  mouse->buttonstate = buttonstate;
360 
361  if (clickstate) {
362  if (state == SDL_PRESSED) {
363  Uint32 now = SDL_GetTicks();
364 
365  if (SDL_TICKS_PASSED(now, clickstate->last_timestamp + SDL_double_click_time) ||
366  SDL_abs(mouse->x - clickstate->last_x) > SDL_double_click_radius ||
367  SDL_abs(mouse->y - clickstate->last_y) > SDL_double_click_radius) {
368  clickstate->click_count = 0;
369  }
370  clickstate->last_timestamp = now;
371  clickstate->last_x = mouse->x;
372  clickstate->last_y = mouse->y;
373  if (clickstate->click_count < 255) {
374  ++clickstate->click_count;
375  }
376  }
377  click_count = clickstate->click_count;
378  } else {
379  click_count = 1;
380  }
381 
382  /* Post the event, if desired */
383  posted = 0;
384  if (SDL_GetEventState(type) == SDL_ENABLE) {
386  event.type = type;
387  event.button.windowID = mouse->focus ? mouse->focus->id : 0;
388  event.button.which = mouseID;
389  event.button.state = state;
390  event.button.button = button;
391  event.button.clicks = click_count;
392  event.button.x = mouse->x;
393  event.button.y = mouse->y;
394  posted = (SDL_PushEvent(&event) > 0);
395  }
396 
397  /* We do this after dispatching event so button releases can lose focus */
398  if (window && state == SDL_RELEASED) {
399  SDL_UpdateMouseFocus(window, mouse->x, mouse->y, buttonstate);
400  }
401 
402  return posted;
403 }
#define SDL_abs
SDL_Mouse * SDL_GetMouse(void)
Definition: SDL_mouse.c:66
SDL_Texture * button
uint32_t Uint32
An unsigned 32-bit integer type.
Definition: SDL_stdinc.h:155
Uint32 buttonstate
Definition: SDL_mouse_c.h:83
SDL_Window * focus
Definition: SDL_mouse_c.h:77
struct xkb_state * state
#define SDL_ENABLE
Definition: SDL_events.h:718
static int SDL_double_click_radius
Definition: SDL_mouse.c:38
#define SDL_GetEventState(type)
Definition: SDL_events.h:731
Uint32 SDL_GetTicks(void)
Get the number of milliseconds since the SDL library initialization.
uint8_t Uint8
An unsigned 8-bit integer type.
Definition: SDL_stdinc.h:139
struct _cl_event * event
#define SDL_PushEvent
static SDL_MouseClickState * GetMouseClickState(SDL_Mouse *mouse, Uint8 button)
Definition: SDL_mouse.c:307
static SDL_bool SDL_UpdateMouseFocus(SDL_Window *window, int x, int y, Uint32 buttonstate)
Definition: SDL_mouse.c:140
Uint32 id
Definition: SDL_sysvideo.h:74
#define SDL_BUTTON(X)
Definition: SDL_mouse.h:279
General event structure.
Definition: SDL_events.h:521
GLuint GLuint GLsizei GLenum type
Definition: SDL_opengl.h:1564
#define SDL_PRESSED
Definition: SDL_events.h:50
static Uint32 SDL_double_click_time
Definition: SDL_mouse.c:37
#define SDL_TICKS_PASSED(A, B)
Compare SDL ticks values, and return true if A has passed B.
Definition: SDL_timer.h:56
#define SDL_RELEASED
Definition: SDL_events.h:49
int SDL_SendMouseMotion ( SDL_Window window,
SDL_MouseID  mouseID,
int  relative,
int  x,
int  y 
)

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

189 {
190  if (window && !relative) {
191  SDL_Mouse *mouse = SDL_GetMouse();
192  if (!SDL_UpdateMouseFocus(window, x, y, mouse->buttonstate)) {
193  return 0;
194  }
195  }
196 
197  return SDL_PrivateSendMouseMotion(window, mouseID, relative, x, y);
198 }
SDL_Mouse * SDL_GetMouse(void)
Definition: SDL_mouse.c:66
static int SDL_PrivateSendMouseMotion(SDL_Window *window, SDL_MouseID mouseID, int relative, int x, int y)
Definition: SDL_mouse.c:201
Uint32 buttonstate
Definition: SDL_mouse_c.h:83
GLint GLint GLint GLint GLint x
Definition: SDL_opengl.h:1567
static SDL_bool SDL_UpdateMouseFocus(SDL_Window *window, int x, int y, Uint32 buttonstate)
Definition: SDL_mouse.c:140
GLint GLint GLint GLint GLint GLint y
Definition: SDL_opengl.h:1567
int SDL_SendMouseWheel ( SDL_Window window,
SDL_MouseID  mouseID,
int  x,
int  y,
SDL_MouseWheelDirection  direction 
)

Definition at line 406 of file SDL_mouse.c.

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

Referenced by SDL_BApp::_HandleMouseWheel().

407 {
408  SDL_Mouse *mouse = SDL_GetMouse();
409  int posted;
410 
411  if (window) {
412  SDL_SetMouseFocus(window);
413  }
414 
415  if (!x && !y) {
416  return 0;
417  }
418 
419  /* Post the event, if desired */
420  posted = 0;
423  event.type = SDL_MOUSEWHEEL;
424  event.wheel.windowID = mouse->focus ? mouse->focus->id : 0;
425  event.wheel.which = mouseID;
426  event.wheel.x = x;
427  event.wheel.y = y;
428  event.wheel.direction = (Uint32)direction;
429  posted = (SDL_PushEvent(&event) > 0);
430  }
431  return posted;
432 }
SDL_Mouse * SDL_GetMouse(void)
Definition: SDL_mouse.c:66
uint32_t Uint32
An unsigned 32-bit integer type.
Definition: SDL_stdinc.h:155
SDL_Window * focus
Definition: SDL_mouse_c.h:77
#define SDL_ENABLE
Definition: SDL_events.h:718
void SDL_SetMouseFocus(SDL_Window *window)
Definition: SDL_mouse.c:103
GLint GLint GLint GLint GLint x
Definition: SDL_opengl.h:1567
#define SDL_GetEventState(type)
Definition: SDL_events.h:731
struct _cl_event * event
#define SDL_PushEvent
GLint GLint GLint GLint GLint GLint y
Definition: SDL_opengl.h:1567
Uint32 id
Definition: SDL_sysvideo.h:74
General event structure.
Definition: SDL_events.h:521
void SDL_SetDefaultCursor ( SDL_Cursor cursor)

Definition at line 55 of file SDL_mouse.c.

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

56 {
57  SDL_Mouse *mouse = SDL_GetMouse();
58 
59  mouse->def_cursor = cursor;
60  if (!mouse->cur_cursor) {
61  SDL_SetCursor(cursor);
62  }
63 }
SDL_Mouse * SDL_GetMouse(void)
Definition: SDL_mouse.c:66
void SDL_SetCursor(SDL_Cursor *cursor)
Set the active cursor.
Definition: SDL_mouse.c:779
SDL_Cursor * cursor
Definition: testwm2.c:40
SDL_Cursor * cur_cursor
Definition: SDL_mouse_c.h:93
SDL_Cursor * def_cursor
Definition: SDL_mouse_c.h:92
void SDL_SetDoubleClickTime ( Uint32  interval)

Definition at line 72 of file SDL_mouse.c.

References SDL_double_click_time.

73 {
74  SDL_double_click_time = interval;
75 }
static Uint32 SDL_double_click_time
Definition: SDL_mouse.c:37
void SDL_SetMouseFocus ( SDL_Window window)

Definition at line 103 of file SDL_mouse.c.

References SDL_Mouse::focus, NULL, SDL_GetMouse(), SDL_ResetMouse(), SDL_SendWindowEvent(), SDL_SetCursor(), SDL_WINDOWEVENT_ENTER, SDL_WINDOWEVENT_LEAVE, and window.

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

104 {
105  SDL_Mouse *mouse = SDL_GetMouse();
106 
107  if (mouse->focus == window) {
108  return;
109  }
110 
111  /* Actually, this ends up being a bad idea, because most operating
112  systems have an implicit grab when you press the mouse button down
113  so you can drag things out of the window and then get the mouse up
114  when it happens. So, #if 0...
115  */
116 #if 0
117  if (mouse->focus && !window) {
118  /* We won't get anymore mouse messages, so reset mouse state */
119  SDL_ResetMouse();
120  }
121 #endif
122 
123  /* See if the current window has lost focus */
124  if (mouse->focus) {
126  }
127 
128  mouse->focus = window;
129 
130  if (mouse->focus) {
132  }
133 
134  /* Update cursor visibility */
136 }
SDL_Mouse * SDL_GetMouse(void)
Definition: SDL_mouse.c:66
SDL_Window * focus
Definition: SDL_mouse_c.h:77
SDL_Window * window
void SDL_SetCursor(SDL_Cursor *cursor)
Set the active cursor.
Definition: SDL_mouse.c:779
int SDL_SendWindowEvent(SDL_Window *window, Uint8 windowevent, int data1, int data2)
void SDL_ResetMouse(void)
Definition: SDL_mouse.c:86
#define NULL
Definition: begin_code.h:143