Ios retina SDL_WINDOW_ALLOW_HIGHDPI and SDL_MOUSEBUTTONUP event coordinates

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;
    }
}

What I’m doing wrong?

I found changeset https://hg.libsdl.org/SDL/rev/0ef6b8b9ca6d.

Looking at the line

if (renderer->logical_w && window == renderer->window) {

It seems to be I shoud use SDL_RenderSetLogicalSize after render create and each time screen size and orientation changes?

May be the best practise using SDL_FINGER events instead of MOUSE on mobile platforms?

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;
}

}

What I’m doing wrong?

Thank you, hardcoredaniel. Now I handle FINGER events instead of Mouse events on ios and Android.

hardcoredaniel, is your code open source and can be looked at?

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:

https://bitbucket.org/hcdaniel/wmelite-rapaki-edition/src/8f873d69d2d8034e109ed439f5a64ba30d2d2dc3/src/BRenderSDL.cpp?at=default&fileviewer=file-view-default

The idea behind this are several “resolutions” or “coordinate systems”, and conversions between them:

  1. the game’s own native resolution (in my case: 1024 x 600)
  2. the systems “logical”/“point” resolution (for event coordinates)
  3. 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.

Regards,

Daniel