I’m running my app on ios 5s iphone simulator which have [640, 1136] screen resolution.
I create window with SDL_WINDOW_RESIZABLE | SDL_WINDOW_ALLOW_HIGHDPI flags.
But when I trigger SDL_MOUSEBUTTONUP event is gives me wrong coordinates like my screen has 320 580 screen resolution.
auto Window = SDL_CreateWindow("Hello world", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 800, 600, SDL_WINDOW_RESIZABLE | SDL_WINDOW_ALLOW_HIGHDPI);
auto Renderer = SDL_CreateRenderer(Window, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);
SDL_Event event;
while (SDL_PollEvent(&event))
{
switch (event.type)
{
case SDL_MOUSEBUTTONDOWN:
if (App.onTouchDown(event.button.x, event.button.y)) NeedReDraw = true;
break;
case SDL_MOUSEBUTTONUP:
if (App.onTouchUp(event.button.x, event.button.y)) NeedReDraw = true;
break;
}
}
I was under the impression that this is the intended behaviour. Event
coordinates are always in points, they do not rescale if you use HIGHDPI. So
I added some logic to my code to handle it properly if the renderer’s size
(in pixels) is different from the screen size (in points).
---------- Původní e-mail ----------
Od: akk0rd87 noreply@discourse.libsdl.org
Komu: hardcoredaniel@seznam.cz
Předmět: [SDL] Ios retina SDL_WINDOW_ALLOW_HIGHDPI and SDL_MOUSEBUTTONUP
event coordinates
"
akk0rd87(https://discourse.libsdl.org/u/akk0rd87)
February 4
SDL 2.0.7
I’m running my app on ios 5s iphone simulator which have [640, 1136] screen
resolution.
I create window with SDL_WINDOW_RESIZABLE | SDL_WINDOW_ALLOW_HIGHDPI flags.
But when I trigger SDL_MOUSEBUTTONUP event is gives me wrong coordinates
like my screen has 320 580 screen resolution.
auto Window = SDL_CreateWindow(“Hello world”, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 800, 600, SDL_WINDOW_RESIZABLE | SDL_WINDOW_ALLOW_HIGHDPI);
auto Renderer = SDL_CreateRenderer(Window, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);
SDL_Event event;
while (SDL_PollEvent(&event))
{
switch (event.type)
{
case SDL_MOUSEBUTTONDOWN:
if (App.onTouchDown(event.button.x, event.button.y)) NeedReDraw = true;
break;
case SDL_MOUSEBUTTONUP:
if (App.onTouchUp(event.button.x, event.button.y)) NeedReDraw = true;
break;
}
Yes, the code is open source. Nevertheless it’s spread all over the project, so I doubt you’ll find the interesting parts easily. This file contains most of the logic if you like to take a look:
The idea behind this are several “resolutions” or “coordinate systems”, and conversions between them:
the game’s own native resolution (in my case: 1024 x 600)
the systems “logical”/“point” resolution (for event coordinates)
the systems “physical” rendering resolution (the actual pixels) - which can be equal to 2) if there is no high-resolution-display available
internally, event coordinates are transposed from 2) to 1) and rendering happens transposing from 1) to 3). Thus, a direct transformation between 3) and 2) and vice versa is not needed.