mirror of https://github.com/encounter/SDL.git
Fixed bug 2367 - Bad mouse motion coordinates with two windows where one has changed logical size
Andreas Ragnerstam I have two windows where one has a renderer where the logical size has been changed with SDL_RenderSetLogicalSize. When I get SDL_MOUSEMOTION events belonging to the non-scaled window these will have been scaled with the factor of the scaled window, which is not expected. Adding some printf debugging to SDL_RendererEventWatch of SDL_render.c, where (event->type == SDL_MOUSEMOTION), I found that for every mouse motion SDL_RendererEventWatch is called twice and the event->motion.x and event.motion.y are set twice for the event, once for each renderer where only the last one set will be saved to the event struct. This will work fine if both renderers have the same scale, but otherwise the motion coordinates will be scaled for the renderer belonging to another window than the mouse was moved in. I guess one solution would be to check that window == renderer->window for SDL_MOUSEMOTION events, similar to what is done for when SDL_WINDOWEVENT events. I get the same error on both X11 and Windows. The same problem also exists for SDL_MOUSEBUTTONDOWN and SDL_MOUSEBUTTONUP events.
This commit is contained in:
parent
bccc2ad09e
commit
6a3ad8a998
|
@ -165,7 +165,8 @@ SDL_RendererEventWatch(void *userdata, SDL_Event *event)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (event->type == SDL_MOUSEMOTION) {
|
} else if (event->type == SDL_MOUSEMOTION) {
|
||||||
if (renderer->logical_w) {
|
SDL_Window *window = SDL_GetWindowFromID(event->motion.windowID);
|
||||||
|
if (renderer->logical_w && window == renderer->window) {
|
||||||
event->motion.x -= renderer->viewport.x;
|
event->motion.x -= renderer->viewport.x;
|
||||||
event->motion.y -= renderer->viewport.y;
|
event->motion.y -= renderer->viewport.y;
|
||||||
event->motion.x = (int)(event->motion.x / renderer->scale.x);
|
event->motion.x = (int)(event->motion.x / renderer->scale.x);
|
||||||
|
@ -183,7 +184,8 @@ SDL_RendererEventWatch(void *userdata, SDL_Event *event)
|
||||||
}
|
}
|
||||||
} else if (event->type == SDL_MOUSEBUTTONDOWN ||
|
} else if (event->type == SDL_MOUSEBUTTONDOWN ||
|
||||||
event->type == SDL_MOUSEBUTTONUP) {
|
event->type == SDL_MOUSEBUTTONUP) {
|
||||||
if (renderer->logical_w) {
|
SDL_Window *window = SDL_GetWindowFromID(event->button.windowID);
|
||||||
|
if (renderer->logical_w && window == renderer->window) {
|
||||||
event->button.x -= renderer->viewport.x;
|
event->button.x -= renderer->viewport.x;
|
||||||
event->button.y -= renderer->viewport.y;
|
event->button.y -= renderer->viewport.y;
|
||||||
event->button.x = (int)(event->button.x / renderer->scale.x);
|
event->button.x = (int)(event->button.x / renderer->scale.x);
|
||||||
|
|
Loading…
Reference in New Issue