Skip to content

Commit

Permalink
Fixed bug 2367 - Bad mouse motion coordinates with two windows where …
Browse files Browse the repository at this point in the history
…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.
  • Loading branch information
slouken committed May 28, 2015
1 parent bccc2ad commit 6a3ad8a
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/render/SDL_render.c
Expand Up @@ -165,7 +165,8 @@ SDL_RendererEventWatch(void *userdata, SDL_Event *event)
}
}
} 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.y -= renderer->viewport.y;
event->motion.x = (int)(event->motion.x / renderer->scale.x);
Expand All @@ -183,7 +184,8 @@ SDL_RendererEventWatch(void *userdata, SDL_Event *event)
}
} else if (event->type == SDL_MOUSEBUTTONDOWN ||
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.y -= renderer->viewport.y;
event->button.x = (int)(event->button.x / renderer->scale.x);
Expand Down

0 comments on commit 6a3ad8a

Please sign in to comment.