mirror of
https://github.com/libsdl-org/SDL.git
synced 2025-09-06 03:18:13 +00:00
On Windows the mouse speed is affected by the content scale
Fixes https://github.com/libsdl-org/SDL/issues/7802
This commit is contained in:
@@ -350,7 +350,7 @@ int SDL_SendMouseMotion(Uint64 timestamp, SDL_Window *window, SDL_MouseID mouseI
|
|||||||
return SDL_PrivateSendMouseMotion(timestamp, window, mouseID, relative, x, y);
|
return SDL_PrivateSendMouseMotion(timestamp, window, mouseID, relative, x, y);
|
||||||
}
|
}
|
||||||
|
|
||||||
static float CalculateSystemScale(SDL_Mouse *mouse, const float *x, const float *y)
|
static float CalculateSystemScale(SDL_Mouse *mouse, SDL_Window *window, const float *x, const float *y)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
int n = mouse->num_system_scale_values;
|
int n = mouse->num_system_scale_values;
|
||||||
@@ -359,9 +359,8 @@ static float CalculateSystemScale(SDL_Mouse *mouse, const float *x, const float
|
|||||||
|
|
||||||
/* If we're using a single scale value, return that */
|
/* If we're using a single scale value, return that */
|
||||||
if (n == 1) {
|
if (n == 1) {
|
||||||
return v[0];
|
scale = v[0];
|
||||||
}
|
} else {
|
||||||
|
|
||||||
speed = SDL_sqrtf((*x * *x) + (*y * *y));
|
speed = SDL_sqrtf((*x * *x) + (*y * *y));
|
||||||
for (i = 0; i < (n - 2); i += 2) {
|
for (i = 0; i < (n - 2); i += 2) {
|
||||||
if (speed < v[i + 2]) {
|
if (speed < v[i + 2]) {
|
||||||
@@ -376,6 +375,22 @@ static float CalculateSystemScale(SDL_Mouse *mouse, const float *x, const float
|
|||||||
coef = (speed - v[i]) / (v[i + 2] - v[i]);
|
coef = (speed - v[i]) / (v[i + 2] - v[i]);
|
||||||
scale = v[i + 1] + (coef * (v[i + 3] - v[i + 1]));
|
scale = v[i + 1] + (coef * (v[i + 3] - v[i + 1]));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
#ifdef __WIN32__
|
||||||
|
{
|
||||||
|
/* On Windows the mouse speed is affected by the content scale */
|
||||||
|
SDL_VideoDisplay *display;
|
||||||
|
|
||||||
|
if (window) {
|
||||||
|
display = SDL_GetVideoDisplayForWindow(window);
|
||||||
|
} else {
|
||||||
|
display = SDL_GetVideoDisplay(SDL_GetPrimaryDisplay());
|
||||||
|
}
|
||||||
|
if (display) {
|
||||||
|
scale *= display->content_scale;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
return scale;
|
return scale;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -421,14 +436,14 @@ int SDL_SetMouseSystemScale(int num_values, const float *values)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void GetScaledMouseDeltas(SDL_Mouse *mouse, float *x, float *y)
|
static void GetScaledMouseDeltas(SDL_Mouse *mouse, SDL_Window *window, float *x, float *y)
|
||||||
{
|
{
|
||||||
if (mouse->relative_mode) {
|
if (mouse->relative_mode) {
|
||||||
if (mouse->enable_relative_speed_scale) {
|
if (mouse->enable_relative_speed_scale) {
|
||||||
*x *= mouse->relative_speed_scale;
|
*x *= mouse->relative_speed_scale;
|
||||||
*y *= mouse->relative_speed_scale;
|
*y *= mouse->relative_speed_scale;
|
||||||
} else if (mouse->enable_relative_system_scale && mouse->num_system_scale_values > 0) {
|
} else if (mouse->enable_relative_system_scale && mouse->num_system_scale_values > 0) {
|
||||||
float relative_system_scale = CalculateSystemScale(mouse, x, y);
|
float relative_system_scale = CalculateSystemScale(mouse, window, x, y);
|
||||||
*x *= relative_system_scale;
|
*x *= relative_system_scale;
|
||||||
*y *= relative_system_scale;
|
*y *= relative_system_scale;
|
||||||
}
|
}
|
||||||
@@ -529,7 +544,7 @@ static int SDL_PrivateSendMouseMotion(Uint64 timestamp, SDL_Window *window, SDL_
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (relative) {
|
if (relative) {
|
||||||
GetScaledMouseDeltas(mouse, &x, &y);
|
GetScaledMouseDeltas(mouse, window, &x, &y);
|
||||||
xrel = x;
|
xrel = x;
|
||||||
yrel = y;
|
yrel = y;
|
||||||
x = (mouse->last_x + xrel);
|
x = (mouse->last_x + xrel);
|
||||||
|
Reference in New Issue
Block a user