mirror of
https://github.com/libsdl-org/SDL.git
synced 2025-09-06 03:18:13 +00:00
mouse: Allow use of integer coordinates with fractional wheel events
SDL 2.0.18 added preciseX/Y to mouse wheel events, which we cannot
emulate in sdl2-compat without a mechanism to control integer position
and scroll deltas separately.
(cherry picked from commit aad1e35162
)
This commit is contained in:

committed by
Sam Lantinga

parent
0799237d74
commit
3e34720851
@@ -238,7 +238,11 @@ static void SDLCALL SDL_MouseIntegerModeChanged(void *userdata, const char *name
|
|||||||
{
|
{
|
||||||
SDL_Mouse *mouse = (SDL_Mouse *)userdata;
|
SDL_Mouse *mouse = (SDL_Mouse *)userdata;
|
||||||
|
|
||||||
mouse->integer_mode = SDL_GetStringBoolean(hint, false);
|
if (hint && *hint) {
|
||||||
|
mouse->integer_mode = (Uint8)SDL_atoi(hint);
|
||||||
|
} else {
|
||||||
|
mouse->integer_mode = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Public functions
|
// Public functions
|
||||||
@@ -730,7 +734,7 @@ static void SDL_PrivateSendMouseMotion(Uint64 timestamp, SDL_Window *window, SDL
|
|||||||
y *= mouse->normal_speed_scale;
|
y *= mouse->normal_speed_scale;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (mouse->integer_mode) {
|
if (mouse->integer_mode >= 1) {
|
||||||
// Accumulate the fractional relative motion and only process the integer portion
|
// Accumulate the fractional relative motion and only process the integer portion
|
||||||
mouse->xrel_frac = SDL_modff(mouse->xrel_frac + x, &x);
|
mouse->xrel_frac = SDL_modff(mouse->xrel_frac + x, &x);
|
||||||
mouse->yrel_frac = SDL_modff(mouse->yrel_frac + y, &y);
|
mouse->yrel_frac = SDL_modff(mouse->yrel_frac + y, &y);
|
||||||
@@ -741,7 +745,7 @@ static void SDL_PrivateSendMouseMotion(Uint64 timestamp, SDL_Window *window, SDL
|
|||||||
y = (mouse->last_y + yrel);
|
y = (mouse->last_y + yrel);
|
||||||
ConstrainMousePosition(mouse, window, &x, &y);
|
ConstrainMousePosition(mouse, window, &x, &y);
|
||||||
} else {
|
} else {
|
||||||
if (mouse->integer_mode) {
|
if (mouse->integer_mode >= 1) {
|
||||||
// Discard the fractional component from absolute coordinates
|
// Discard the fractional component from absolute coordinates
|
||||||
x = SDL_truncf(x);
|
x = SDL_truncf(x);
|
||||||
y = SDL_truncf(y);
|
y = SDL_truncf(y);
|
||||||
@@ -1019,7 +1023,7 @@ void SDL_SendMouseWheel(Uint64 timestamp, SDL_Window *window, SDL_MouseID mouseI
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Accumulate fractional wheel motion if integer mode is enabled
|
// Accumulate fractional wheel motion if integer mode is enabled
|
||||||
if (mouse->integer_mode) {
|
if (mouse->integer_mode >= 2) {
|
||||||
mouse->wheel_x_frac = SDL_modff(mouse->wheel_x_frac + x, &x);
|
mouse->wheel_x_frac = SDL_modff(mouse->wheel_x_frac + x, &x);
|
||||||
mouse->wheel_y_frac = SDL_modff(mouse->wheel_y_frac + y, &y);
|
mouse->wheel_y_frac = SDL_modff(mouse->wheel_y_frac + y, &y);
|
||||||
}
|
}
|
||||||
|
@@ -104,7 +104,7 @@ typedef struct
|
|||||||
float wheel_y_frac;
|
float wheel_y_frac;
|
||||||
double click_motion_x;
|
double click_motion_x;
|
||||||
double click_motion_y;
|
double click_motion_y;
|
||||||
bool integer_mode;
|
Uint8 integer_mode;
|
||||||
bool has_position;
|
bool has_position;
|
||||||
bool relative_mode;
|
bool relative_mode;
|
||||||
bool relative_mode_warp_motion;
|
bool relative_mode_warp_motion;
|
||||||
|
Reference in New Issue
Block a user