1 /* 2 Simple DirectMedia Layer 3 Copyright (C) 1997-2021 Sam Lantinga <slouken@libsdl.org> 4 5 This software is provided 'as-is', without any express or implied 6 warranty. In no event will the authors be held liable for any damages 7 arising from the use of this software. 8 9 Permission is granted to anyone to use this software for any purpose, 10 including commercial applications, and to alter it and redistribute it 11 freely, subject to the following restrictions: 12 13 1. The origin of this software must not be misrepresented; you must not 14 claim that you wrote the original software. If you use this software 15 in a product, an acknowledgment in the product documentation would be 16 appreciated but is not required. 17 2. Altered source versions must be plainly marked as such, and must not be 18 misrepresented as being the original software. 19 3. This notice may not be removed or altered from any source distribution. 20 */ 21 #include "../SDL_internal.h" 22 23 #ifndef SDL_mouse_c_h_ 24 #define SDL_mouse_c_h_ 25 26 #include "SDL_mouse.h" 27 28 typedef Uint32 SDL_MouseID; 29 30 struct SDL_Cursor 31 { 32 struct SDL_Cursor *next; 33 void *driverdata; 34 }; 35 36 typedef struct 37 { 38 SDL_MouseID mouseID; 39 Uint32 buttonstate; 40 } SDL_MouseInputSource; 41 42 typedef struct 43 { 44 int last_x, last_y; 45 Uint32 last_timestamp; 46 Uint8 click_count; 47 } SDL_MouseClickState; 48 49 typedef struct 50 { 51 /* Create a cursor from a surface */ 52 SDL_Cursor *(*CreateCursor) (SDL_Surface * surface, int hot_x, int hot_y); 53 54 /* Create a system cursor */ 55 SDL_Cursor *(*CreateSystemCursor) (SDL_SystemCursor id); 56 57 /* Show the specified cursor, or hide if cursor is NULL */ 58 int (*ShowCursor) (SDL_Cursor * cursor); 59 60 /* This is called when a mouse motion event occurs */ 61 void (*MoveCursor) (SDL_Cursor * cursor); 62 63 /* Free a window manager cursor */ 64 void (*FreeCursor) (SDL_Cursor * cursor); 65 66 /* Warp the mouse to (x,y) within a window */ 67 void (*WarpMouse) (SDL_Window * window, int x, int y); 68 69 /* Warp the mouse to (x,y) in screen space */ 70 int (*WarpMouseGlobal) (int x, int y); 71 72 /* Set relative mode */ 73 int (*SetRelativeMouseMode) (SDL_bool enabled); 74 75 /* Set mouse capture */ 76 int (*CaptureMouse) (SDL_Window * window); 77 78 /* Get absolute mouse coordinates. (x) and (y) are never NULL and set to zero before call. */ 79 Uint32 (*GetGlobalMouseState) (int *x, int *y); 80 81 /* Data common to all mice */ 82 SDL_MouseID mouseID; 83 SDL_Window *focus; 84 int x; 85 int y; 86 int xdelta; 87 int ydelta; 88 int last_x, last_y; /* the last reported x and y coordinates */ 89 float accumulated_wheel_x; 90 float accumulated_wheel_y; 91 SDL_bool has_position; 92 SDL_bool relative_mode; 93 SDL_bool relative_mode_warp; 94 float normal_speed_scale; 95 float relative_speed_scale; 96 float scale_accum_x; 97 float scale_accum_y; 98 Uint32 double_click_time; 99 int double_click_radius; 100 SDL_bool touch_mouse_events; 101 SDL_bool mouse_touch_events; 102 SDL_bool was_touch_mouse_events; /* Was a touch-mouse event pending? */ 103 104 /* Data for input source state */ 105 int num_sources; 106 SDL_MouseInputSource *sources; 107 108 /* Data for double-click tracking */ 109 int num_clickstates; 110 SDL_MouseClickState *clickstate; 111 112 SDL_Cursor *cursors; 113 SDL_Cursor *def_cursor; 114 SDL_Cursor *cur_cursor; 115 SDL_bool cursor_shown; 116 117 /* Driver-dependent data. */ 118 void *driverdata; 119 } SDL_Mouse; 120 121 122 /* Initialize the mouse subsystem */ 123 extern int SDL_MouseInit(void); 124 125 /* Get the mouse state structure */ 126 SDL_Mouse *SDL_GetMouse(void); 127 128 /* Set the default mouse cursor */ 129 extern void SDL_SetDefaultCursor(SDL_Cursor * cursor); 130 131 /* Set the mouse focus window */ 132 extern void SDL_SetMouseFocus(SDL_Window * window); 133 134 /* Send a mouse motion event */ 135 extern int SDL_SendMouseMotion(SDL_Window * window, SDL_MouseID mouseID, int relative, int x, int y); 136 137 /* Send a mouse button event */ 138 extern int SDL_SendMouseButton(SDL_Window * window, SDL_MouseID mouseID, Uint8 state, Uint8 button); 139 140 /* Send a mouse button event with a click count */ 141 extern int SDL_SendMouseButtonClicks(SDL_Window * window, SDL_MouseID mouseID, Uint8 state, Uint8 button, int clicks); 142 143 /* Send a mouse wheel event */ 144 extern int SDL_SendMouseWheel(SDL_Window * window, SDL_MouseID mouseID, float x, float y, SDL_MouseWheelDirection direction); 145 146 /* Shutdown the mouse subsystem */ 147 extern void SDL_MouseQuit(void); 148 149 #endif /* SDL_mouse_c_h_ */ 150 151 /* vi: set ts=4 sw=4 expandtab: */ 152