mirror of
https://github.com/Ryujinx/SDL.git
synced 2024-12-23 05:25:33 +00:00
Normalize touch events to the render viewport (thanks Sylvain!)
This commit is contained in:
parent
5bed4ca92e
commit
a7c79c5e25
|
@ -219,7 +219,35 @@ SDL_RendererEventWatch(void *userdata, SDL_Event *event)
|
||||||
event->button.x = (int)(event->button.x / (renderer->scale.x * renderer->dpi_scale.x));
|
event->button.x = (int)(event->button.x / (renderer->scale.x * renderer->dpi_scale.x));
|
||||||
event->button.y = (int)(event->button.y / (renderer->scale.y * renderer->dpi_scale.y));
|
event->button.y = (int)(event->button.y / (renderer->scale.y * renderer->dpi_scale.y));
|
||||||
}
|
}
|
||||||
|
} else if (event->type == SDL_FINGERDOWN ||
|
||||||
|
event->type == SDL_FINGERUP ||
|
||||||
|
event->type == SDL_FINGERMOTION) {
|
||||||
|
if (renderer->logical_w) {
|
||||||
|
int w = 1;
|
||||||
|
int h = 1;
|
||||||
|
SDL_GetRendererOutputSize(renderer, &w, &h);
|
||||||
|
|
||||||
|
event->tfinger.x *= (w - 1);
|
||||||
|
event->tfinger.y *= (h - 1);
|
||||||
|
|
||||||
|
event->tfinger.x -= (renderer->viewport.x * renderer->dpi_scale.x);
|
||||||
|
event->tfinger.y -= (renderer->viewport.y * renderer->dpi_scale.y);
|
||||||
|
event->tfinger.x = (event->tfinger.x / (renderer->scale.x * renderer->dpi_scale.x));
|
||||||
|
event->tfinger.y = (event->tfinger.y / (renderer->scale.y * renderer->dpi_scale.y));
|
||||||
|
|
||||||
|
if (renderer->logical_w > 1) {
|
||||||
|
event->tfinger.x = event->tfinger.x / (renderer->logical_w - 1);
|
||||||
|
} else {
|
||||||
|
event->tfinger.x = 0.5f;
|
||||||
}
|
}
|
||||||
|
if (renderer->logical_h > 1) {
|
||||||
|
event->tfinger.y = event->tfinger.y / (renderer->logical_h - 1);
|
||||||
|
} else {
|
||||||
|
event->tfinger.y = 0.5f;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue