|
@@ -234,6 +234,13 @@ static void SDLCALL SDL_MouseRelativeCursorVisibleChanged(void *userdata, const
|
|
|
SDL_SetCursor(NULL); // Update cursor visibility
|
|
|
}
|
|
|
|
|
|
+static void SDLCALL SDL_MouseIntegerModeChanged(void *userdata, const char *name, const char *oldValue, const char *hint)
|
|
|
+{
|
|
|
+ SDL_Mouse *mouse = (SDL_Mouse *)userdata;
|
|
|
+
|
|
|
+ mouse->integer_mode = SDL_GetStringBoolean(hint, false);
|
|
|
+}
|
|
|
+
|
|
|
// Public functions
|
|
|
bool SDL_PreInitMouse(void)
|
|
|
{
|
|
@@ -288,6 +295,9 @@ bool SDL_PreInitMouse(void)
|
|
|
SDL_AddHintCallback(SDL_HINT_MOUSE_RELATIVE_CURSOR_VISIBLE,
|
|
|
SDL_MouseRelativeCursorVisibleChanged, mouse);
|
|
|
|
|
|
+ SDL_AddHintCallback("SDL_MOUSE_INTEGER_MODE",
|
|
|
+ SDL_MouseIntegerModeChanged, mouse);
|
|
|
+
|
|
|
mouse->was_touch_mouse_events = false; // no touch to mouse movement event pending
|
|
|
|
|
|
mouse->cursor_shown = true;
|
|
@@ -725,12 +735,22 @@ static void SDL_PrivateSendMouseMotion(Uint64 timestamp, SDL_Window *window, SDL
|
|
|
y *= mouse->normal_speed_scale;
|
|
|
}
|
|
|
}
|
|
|
+ if (mouse->integer_mode) {
|
|
|
+ // Accumulate the fractional relative motion and only process the integer portion
|
|
|
+ mouse->xrel_frac = SDL_modff(mouse->xrel_frac + x, &x);
|
|
|
+ mouse->yrel_frac = SDL_modff(mouse->yrel_frac + y, &y);
|
|
|
+ }
|
|
|
xrel = x;
|
|
|
yrel = y;
|
|
|
x = (mouse->last_x + xrel);
|
|
|
y = (mouse->last_y + yrel);
|
|
|
ConstrainMousePosition(mouse, window, &x, &y);
|
|
|
} else {
|
|
|
+ if (mouse->integer_mode) {
|
|
|
+ // Discard the fractional component from absolute coordinates
|
|
|
+ x = SDL_truncf(x);
|
|
|
+ y = SDL_truncf(y);
|
|
|
+ }
|
|
|
ConstrainMousePosition(mouse, window, &x, &y);
|
|
|
if (mouse->has_position) {
|
|
|
xrel = x - mouse->last_x;
|
|
@@ -1003,6 +1023,12 @@ void SDL_SendMouseWheel(Uint64 timestamp, SDL_Window *window, SDL_MouseID mouseI
|
|
|
SDL_SetMouseFocus(window);
|
|
|
}
|
|
|
|
|
|
+ // Accumulate fractional wheel motion if integer mode is enabled
|
|
|
+ if (mouse->integer_mode) {
|
|
|
+ mouse->wheel_x_frac = SDL_modff(mouse->wheel_x_frac + x, &x);
|
|
|
+ mouse->wheel_y_frac = SDL_modff(mouse->wheel_y_frac + y, &y);
|
|
|
+ }
|
|
|
+
|
|
|
if (x == 0.0f && y == 0.0f) {
|
|
|
return;
|
|
|
}
|
|
@@ -1113,6 +1139,9 @@ void SDL_QuitMouse(void)
|
|
|
SDL_RemoveHintCallback(SDL_HINT_MOUSE_RELATIVE_CURSOR_VISIBLE,
|
|
|
SDL_MouseRelativeCursorVisibleChanged, mouse);
|
|
|
|
|
|
+ SDL_RemoveHintCallback("SDL_MOUSE_INTEGER_MODE",
|
|
|
+ SDL_MouseIntegerModeChanged, mouse);
|
|
|
+
|
|
|
for (int i = SDL_mouse_count; i--; ) {
|
|
|
SDL_RemoveMouse(SDL_mice[i].instance_id, false);
|
|
|
}
|