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, int x, int 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 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

◆ SDL_MouseQuit()

void SDL_MouseQuit ( void  )

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

450 {
451  SDL_Cursor *cursor, *next;
452  SDL_Mouse *mouse = SDL_GetMouse();
453 
454  if (mouse->CaptureMouse) {
456  }
458  SDL_ShowCursor(1);
459 
460  cursor = mouse->cursors;
461  while (cursor) {
462  next = cursor->next;
463  SDL_FreeCursor(cursor);
464  cursor = next;
465  }
466 
467  if (mouse->def_cursor && mouse->FreeCursor) {
468  mouse->FreeCursor(mouse->def_cursor);
469  }
470 
471  if (mouse->clickstate) {
472  SDL_free(mouse->clickstate);
473  }
474 
475  SDL_zerop(mouse);
476 }
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:879
#define SDL_zerop(x)
Definition: SDL_stdinc.h:362
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:632
int(* CaptureMouse)(SDL_Window *window)
Definition: SDL_mouse_c.h:70
void SDL_free(void *mem)
SDL_Cursor * cursor
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:575
void SDL_FreeCursor(SDL_Cursor *cursor)
Frees a cursor created with SDL_CreateCursor() or similar functions.
Definition: SDL_mouse.c:845
SDL_Cursor * def_cursor
Definition: SDL_mouse_c.h:92

◆ SDL_SendMouseButton()

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

Definition at line 414 of file SDL_mouse.c.

References SDL_PrivateSendMouseButton().

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

415 {
416  return SDL_PrivateSendMouseButton(window, mouseID, state, button, -1);
417 }
static int SDL_PrivateSendMouseButton(SDL_Window *window, SDL_MouseID mouseID, Uint8 state, Uint8 button, int clicks)
Definition: SDL_mouse.c:326
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 407 of file SDL_mouse.c.

References SDL_max, and SDL_PrivateSendMouseButton().

408 {
409  clicks = SDL_max(clicks, 0);
410  return SDL_PrivateSendMouseButton(window, mouseID, state, button, clicks);
411 }
static int SDL_PrivateSendMouseButton(SDL_Window *window, SDL_MouseID mouseID, Uint8 state, Uint8 button, int clicks)
Definition: SDL_mouse.c:326
SDL_Texture * button
struct xkb_state * state
#define SDL_max(x, y)
Definition: SDL_stdinc.h:352

◆ SDL_SendMouseMotion()

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
GLint GLint GLint GLint GLint GLint y
Definition: SDL_opengl.h:1567
static SDL_bool SDL_UpdateMouseFocus(SDL_Window *window, int x, int y, Uint32 buttonstate)
Definition: SDL_mouse.c:140

◆ SDL_SendMouseWheel()

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

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

421 {
422  SDL_Mouse *mouse = SDL_GetMouse();
423  int posted;
424 
425  if (window) {
426  SDL_SetMouseFocus(window);
427  }
428 
429  if (!x && !y) {
430  return 0;
431  }
432 
433  /* Post the event, if desired */
434  posted = 0;
437  event.type = SDL_MOUSEWHEEL;
438  event.wheel.windowID = mouse->focus ? mouse->focus->id : 0;
439  event.wheel.which = mouseID;
440  event.wheel.x = x;
441  event.wheel.y = y;
442  event.wheel.direction = (Uint32)direction;
443  posted = (SDL_PushEvent(&event) > 0);
444  }
445  return posted;
446 }
SDL_Mouse * SDL_GetMouse(void)
Definition: SDL_mouse.c:66
GLint GLint GLint GLint GLint x
Definition: SDL_opengl.h:1567
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:103
uint32_t Uint32
An unsigned 32-bit integer type.
Definition: SDL_stdinc.h:161
#define SDL_GetEventState(type)
Definition: SDL_events.h:735
GLint GLint GLint GLint GLint GLint y
Definition: SDL_opengl.h:1567
struct _cl_event * event
#define SDL_PushEvent
Uint32 id
Definition: SDL_sysvideo.h:74
General event structure.
Definition: SDL_events.h:525

◆ SDL_SetDefaultCursor()

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:783
SDL_Cursor * cursor
SDL_Cursor * cur_cursor
Definition: SDL_mouse_c.h:93
SDL_Cursor * def_cursor
Definition: SDL_mouse_c.h:92

◆ SDL_SetDoubleClickTime()

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

◆ SDL_SetMouseFocus()

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
static SDL_Window * window
void SDL_SetCursor(SDL_Cursor *cursor)
Set the active cursor.
Definition: SDL_mouse.c:783
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