mirror of
https://github.com/libsdl-org/SDL.git
synced 2025-10-06 09:56:26 +00:00
events: Add integer wheel fields for sdl2-compat
It's way simpler to just add them back to SDL3 than emulate them purely in sdl2-compat.
(cherry picked from commit 0447c2f3c3
)
This commit is contained in:
@@ -492,6 +492,8 @@ typedef struct SDL_MouseWheelEvent
|
|||||||
SDL_MouseWheelDirection direction; /**< Set to one of the SDL_MOUSEWHEEL_* defines. When FLIPPED the values in X and Y will be opposite. Multiply by -1 to change them back */
|
SDL_MouseWheelDirection direction; /**< Set to one of the SDL_MOUSEWHEEL_* defines. When FLIPPED the values in X and Y will be opposite. Multiply by -1 to change them back */
|
||||||
float mouse_x; /**< X coordinate, relative to window */
|
float mouse_x; /**< X coordinate, relative to window */
|
||||||
float mouse_y; /**< Y coordinate, relative to window */
|
float mouse_y; /**< Y coordinate, relative to window */
|
||||||
|
Sint32 integer_x; /**< The amount scrolled horizontally, accumulated to whole scroll "ticks" (added in 3.2.12) */
|
||||||
|
Sint32 integer_y; /**< The amount scrolled vertically, accumulated to whole scroll "ticks" (added in 3.2.12) */
|
||||||
} SDL_MouseWheelEvent;
|
} SDL_MouseWheelEvent;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -633,9 +633,10 @@ static void SDL_LogEvent(const SDL_Event *event)
|
|||||||
#undef PRINT_MBUTTON_EVENT
|
#undef PRINT_MBUTTON_EVENT
|
||||||
|
|
||||||
SDL_EVENT_CASE(SDL_EVENT_MOUSE_WHEEL)
|
SDL_EVENT_CASE(SDL_EVENT_MOUSE_WHEEL)
|
||||||
(void)SDL_snprintf(details, sizeof(details), " (timestamp=%u windowid=%u which=%u x=%g y=%g direction=%s)",
|
(void)SDL_snprintf(details, sizeof(details), " (timestamp=%u windowid=%u which=%u x=%g y=%g integer_x=%d integer_y=%d direction=%s)",
|
||||||
(uint)event->wheel.timestamp, (uint)event->wheel.windowID,
|
(uint)event->wheel.timestamp, (uint)event->wheel.windowID,
|
||||||
(uint)event->wheel.which, event->wheel.x, event->wheel.y,
|
(uint)event->wheel.which, event->wheel.x, event->wheel.y,
|
||||||
|
(int)event->wheel.integer_x, (int)event->wheel.integer_y,
|
||||||
event->wheel.direction == SDL_MOUSEWHEEL_NORMAL ? "normal" : "flipped");
|
event->wheel.direction == SDL_MOUSEWHEEL_NORMAL ? "normal" : "flipped");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@@ -1022,18 +1022,14 @@ void SDL_SendMouseWheel(Uint64 timestamp, SDL_Window *window, SDL_MouseID mouseI
|
|||||||
SDL_SetMouseFocus(window);
|
SDL_SetMouseFocus(window);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Accumulate fractional wheel motion if integer mode is enabled
|
|
||||||
if (mouse->integer_mode_flags & 2) {
|
|
||||||
mouse->integer_mode_residual_scroll_x = SDL_modff(mouse->integer_mode_residual_scroll_x + x, &x);
|
|
||||||
mouse->integer_mode_residual_scroll_y = SDL_modff(mouse->integer_mode_residual_scroll_y + y, &y);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (x == 0.0f && y == 0.0f) {
|
if (x == 0.0f && y == 0.0f) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Post the event, if desired
|
// Post the event, if desired
|
||||||
if (SDL_EventEnabled(SDL_EVENT_MOUSE_WHEEL)) {
|
if (SDL_EventEnabled(SDL_EVENT_MOUSE_WHEEL)) {
|
||||||
|
float integer_x, integer_y;
|
||||||
|
|
||||||
if (!mouse->relative_mode || mouse->warp_emulation_active) {
|
if (!mouse->relative_mode || mouse->warp_emulation_active) {
|
||||||
// We're not in relative mode, so all mouse events are global mouse events
|
// We're not in relative mode, so all mouse events are global mouse events
|
||||||
mouseID = SDL_GLOBAL_MOUSE_ID;
|
mouseID = SDL_GLOBAL_MOUSE_ID;
|
||||||
@@ -1044,11 +1040,26 @@ void SDL_SendMouseWheel(Uint64 timestamp, SDL_Window *window, SDL_MouseID mouseI
|
|||||||
event.common.timestamp = timestamp;
|
event.common.timestamp = timestamp;
|
||||||
event.wheel.windowID = mouse->focus ? mouse->focus->id : 0;
|
event.wheel.windowID = mouse->focus ? mouse->focus->id : 0;
|
||||||
event.wheel.which = mouseID;
|
event.wheel.which = mouseID;
|
||||||
event.wheel.x = x;
|
|
||||||
event.wheel.y = y;
|
|
||||||
event.wheel.direction = direction;
|
event.wheel.direction = direction;
|
||||||
event.wheel.mouse_x = mouse->x;
|
event.wheel.mouse_x = mouse->x;
|
||||||
event.wheel.mouse_y = mouse->y;
|
event.wheel.mouse_y = mouse->y;
|
||||||
|
|
||||||
|
mouse->residual_scroll_x = SDL_modff(mouse->residual_scroll_x + x, &integer_x);
|
||||||
|
event.wheel.integer_x = (Sint32)integer_x;
|
||||||
|
|
||||||
|
mouse->residual_scroll_y = SDL_modff(mouse->residual_scroll_y + y, &integer_y);
|
||||||
|
event.wheel.integer_y = (Sint32)integer_y;
|
||||||
|
|
||||||
|
// Return the accumulated values in x/y when integer wheel mode is enabled.
|
||||||
|
// This is necessary for compatibility with sdl2-compat 2.32.54.
|
||||||
|
if (mouse->integer_mode_flags & 2) {
|
||||||
|
event.wheel.x = integer_x;
|
||||||
|
event.wheel.y = integer_y;
|
||||||
|
} else {
|
||||||
|
event.wheel.x = x;
|
||||||
|
event.wheel.y = y;
|
||||||
|
}
|
||||||
|
|
||||||
SDL_PushEvent(&event);
|
SDL_PushEvent(&event);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -95,8 +95,6 @@ typedef struct
|
|||||||
Uint8 integer_mode_flags; // 1 to enable mouse quantization, 2 to enable wheel quantization
|
Uint8 integer_mode_flags; // 1 to enable mouse quantization, 2 to enable wheel quantization
|
||||||
float integer_mode_residual_motion_x;
|
float integer_mode_residual_motion_x;
|
||||||
float integer_mode_residual_motion_y;
|
float integer_mode_residual_motion_y;
|
||||||
float integer_mode_residual_scroll_x;
|
|
||||||
float integer_mode_residual_scroll_y;
|
|
||||||
|
|
||||||
// Data common to all mice
|
// Data common to all mice
|
||||||
SDL_Window *focus;
|
SDL_Window *focus;
|
||||||
@@ -105,6 +103,8 @@ typedef struct
|
|||||||
float x_accu;
|
float x_accu;
|
||||||
float y_accu;
|
float y_accu;
|
||||||
float last_x, last_y; // the last reported x and y coordinates
|
float last_x, last_y; // the last reported x and y coordinates
|
||||||
|
float residual_scroll_x;
|
||||||
|
float residual_scroll_y;
|
||||||
double click_motion_x;
|
double click_motion_x;
|
||||||
double click_motion_y;
|
double click_motion_y;
|
||||||
bool has_position;
|
bool has_position;
|
||||||
|
Reference in New Issue
Block a user