Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/thirdparty/sdl/events/SDL_mouse_c.h
9902 views
1
/*
2
Simple DirectMedia Layer
3
Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
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
// Mouse events not associated with a specific input device
27
#define SDL_GLOBAL_MOUSE_ID 0
28
29
// The default mouse input device, for platforms that don't have multiple mice
30
#define SDL_DEFAULT_MOUSE_ID 1
31
32
typedef struct SDL_CursorData SDL_CursorData;
33
34
struct SDL_Cursor
35
{
36
struct SDL_Cursor *next;
37
SDL_CursorData *internal;
38
};
39
40
typedef struct
41
{
42
Uint64 last_timestamp;
43
double click_motion_x;
44
double click_motion_y;
45
Uint8 click_count;
46
} SDL_MouseClickState;
47
48
typedef struct
49
{
50
SDL_MouseID mouseID;
51
Uint32 buttonstate;
52
53
// Data for double-click tracking
54
int num_clickstates;
55
SDL_MouseClickState *clickstate;
56
} SDL_MouseInputSource;
57
58
typedef struct
59
{
60
// Create a cursor from a surface
61
SDL_Cursor *(*CreateCursor)(SDL_Surface *surface, int hot_x, int hot_y);
62
63
// Create a system cursor
64
SDL_Cursor *(*CreateSystemCursor)(SDL_SystemCursor id);
65
66
// Show the specified cursor, or hide if cursor is NULL
67
bool (*ShowCursor)(SDL_Cursor *cursor);
68
69
// This is called when a mouse motion event occurs
70
bool (*MoveCursor)(SDL_Cursor *cursor);
71
72
// Free a window manager cursor
73
void (*FreeCursor)(SDL_Cursor *cursor);
74
75
// Warp the mouse to (x,y) within a window
76
bool (*WarpMouse)(SDL_Window *window, float x, float y);
77
78
// Warp the mouse to (x,y) in screen space
79
bool (*WarpMouseGlobal)(float x, float y);
80
81
// Set relative mode
82
bool (*SetRelativeMouseMode)(bool enabled);
83
84
// Set mouse capture
85
bool (*CaptureMouse)(SDL_Window *window);
86
87
// Get absolute mouse coordinates. (x) and (y) are never NULL and set to zero before call.
88
SDL_MouseButtonFlags (*GetGlobalMouseState)(float *x, float *y);
89
90
// Platform-specific system mouse transform
91
void (*ApplySystemScale)(void *internal, Uint64 timestamp, SDL_Window *window, SDL_MouseID mouseID, float *x, float *y);
92
void *system_scale_data;
93
94
// integer mode data
95
Uint8 integer_mode_flags; // 1 to enable mouse quantization, 2 to enable wheel quantization
96
float integer_mode_residual_motion_x;
97
float integer_mode_residual_motion_y;
98
99
// Data common to all mice
100
SDL_Window *focus;
101
float x;
102
float y;
103
float x_accu;
104
float y_accu;
105
float last_x, last_y; // the last reported x and y coordinates
106
float residual_scroll_x;
107
float residual_scroll_y;
108
double click_motion_x;
109
double click_motion_y;
110
bool has_position;
111
bool relative_mode;
112
bool relative_mode_warp_motion;
113
bool relative_mode_cursor_visible;
114
bool relative_mode_center;
115
bool warp_emulation_hint;
116
bool warp_emulation_active;
117
bool warp_emulation_prohibited;
118
Uint64 last_center_warp_time_ns;
119
bool enable_normal_speed_scale;
120
float normal_speed_scale;
121
bool enable_relative_speed_scale;
122
float relative_speed_scale;
123
bool enable_relative_system_scale;
124
Uint32 double_click_time;
125
int double_click_radius;
126
bool touch_mouse_events;
127
bool mouse_touch_events;
128
bool pen_mouse_events;
129
bool pen_touch_events;
130
bool was_touch_mouse_events; // Was a touch-mouse event pending?
131
bool added_mouse_touch_device; // did we SDL_AddTouch() a virtual touch device for the mouse?
132
bool added_pen_touch_device; // did we SDL_AddTouch() a virtual touch device for pens?
133
#ifdef SDL_PLATFORM_VITA
134
Uint8 vita_touch_mouse_device;
135
#endif
136
bool auto_capture;
137
bool capture_desired;
138
SDL_Window *capture_window;
139
140
// Data for input source state
141
int num_sources;
142
SDL_MouseInputSource *sources;
143
144
SDL_Cursor *cursors;
145
SDL_Cursor *def_cursor;
146
SDL_Cursor *cur_cursor;
147
bool cursor_shown;
148
149
// Driver-dependent data.
150
void *internal;
151
} SDL_Mouse;
152
153
// Initialize the mouse subsystem, called before the main video driver is initialized
154
extern bool SDL_PreInitMouse(void);
155
156
// Finish initializing the mouse subsystem, called after the main video driver was initialized
157
extern void SDL_PostInitMouse(void);
158
159
// Return whether a device is actually a mouse
160
extern bool SDL_IsMouse(Uint16 vendor, Uint16 product);
161
162
// A mouse has been added to the system
163
extern void SDL_AddMouse(SDL_MouseID mouseID, const char *name, bool send_event);
164
165
// A mouse has been removed from the system
166
extern void SDL_RemoveMouse(SDL_MouseID mouseID, bool send_event);
167
168
// Get the mouse state structure
169
extern SDL_Mouse *SDL_GetMouse(void);
170
171
// Set the default mouse cursor
172
extern void SDL_SetDefaultCursor(SDL_Cursor *cursor);
173
174
// Get the preferred default system cursor
175
extern SDL_SystemCursor SDL_GetDefaultSystemCursor(void);
176
177
// Set the mouse focus window
178
extern void SDL_SetMouseFocus(SDL_Window *window);
179
180
// Update the mouse capture window
181
extern bool SDL_UpdateMouseCapture(bool force_release);
182
183
// Send a mouse motion event
184
extern void SDL_SendMouseMotion(Uint64 timestamp, SDL_Window *window, SDL_MouseID mouseID, bool relative, float x, float y);
185
186
// Send a mouse button event
187
extern void SDL_SendMouseButton(Uint64 timestamp, SDL_Window *window, SDL_MouseID mouseID, Uint8 button, bool down);
188
189
// Send a mouse button event with a click count
190
extern void SDL_SendMouseButtonClicks(Uint64 timestamp, SDL_Window *window, SDL_MouseID mouseID, Uint8 button, bool down, int clicks);
191
192
// Send a mouse wheel event
193
extern void SDL_SendMouseWheel(Uint64 timestamp, SDL_Window *window, SDL_MouseID mouseID, float x, float y, SDL_MouseWheelDirection direction);
194
195
// Warp the mouse within the window, potentially overriding relative mode
196
extern void SDL_PerformWarpMouseInWindow(SDL_Window *window, float x, float y, bool ignore_relative_mode);
197
198
// Relative mouse mode
199
extern bool SDL_SetRelativeMouseMode(bool enabled);
200
extern bool SDL_GetRelativeMouseMode(void);
201
extern void SDL_UpdateRelativeMouseMode(void);
202
extern void SDL_DisableMouseWarpEmulation(void);
203
204
// TODO RECONNECT: Set mouse state to "zero"
205
#if 0
206
extern void SDL_ResetMouse(void);
207
#endif // 0
208
209
// Check if mouse position is within window or captured by window
210
extern bool SDL_MousePositionInWindow(SDL_Window *window, float x, float y);
211
212
// Shutdown the mouse subsystem
213
extern void SDL_QuitMouse(void);
214
215
#endif // SDL_mouse_c_h_
216
217