Hi folks
I am new here and I have just started writing a framework/template for small graphical desktop applications, using SDL2 for video, events and audio. So far everything went very smoothly and I really appreciate the work you guys/gals put into this. But today I have encountered the following problem:
When using SDL_RenderSetLogicalSize the mouse coordinates (x/y) reported by mousemotion, mousebuttondown and mousebuttonup events are completely wrong after resizing my main window.
I could not find any documentation on this function in the API reference, so all I know, about what it is supposed to do, is from the comments in the header that defines the function (iirc SDL_render.h). There it says: “If the output display is a window, mouse events in the window will be filtered and scaled so they seem to arrive within the logical resolution.”
I understand this as: If I render an image and click on a feature on that image, then resize the window, display the same (now scaled) image again and click on the same feature I should get the same mousecoordinates in a mousebuttondown event in both cases. But this is not the case (far from it…I get seemingly random numbers like 2254 and -189). If my understanding is correct, and please correct me if it is not, then that would be exactly the behaviour I am looking for.
Also I made a simple test without rendering an image and with keeping the aspect ratio constant between resizes:
- I opened a window with a resolution of 1280x720 (aspect ratio 16:9), and the logical size was set to that. Reported mouse coordinates went from (0,0) to (1279,719); so perfect, exactly what I would expect.
- Then I resized the window to 1600x900 (also aspect ratio 16:9) using SDL_SetWindowSize. Reported mouse coordinates now went from (0,0) to (1023, 575), which is still 16:9, but neither the initial/logical resolution, nor the new one.
So when using the same aspect ratio in resizes the values do not seem like complete bogus, but they still do not make sense to me (why would the reported coordinates be in a smaller 16:9 resolution than the initial/logical resolution?). Btw. it makes no difference whether the window is resized using SDL_SetWindowSize or using the window manager.
This has gotten a bit long, sorry for that. I would basically just like to know whether this behaviour is a bug or I do not understand how it is supposed to work. If you need more information/tests please feel free to ask.
Extra information that may (or may not) be useful:
My programming platform is Debian/GNU Linux with a 3.10.9 kernel, NVidia driver 325.15, Xorg 1.12.4 and Fluxbox 1.3.5 as the window manager (nothing else runs on top of the xserver by default (e.g. no panels, starters, docks, etc.)). I use SDL2 version 2.0.0 and SDL2_image version 2.0.0 at the moment.