Is SDL_TouchfingerEvent position values adapted to logical size and letterboxing?


My logical size is 320x240. My window size is 640x480. SDL scales while rendering.
When using SDL_MouseButtonDown the returned values seem to adhere to the logical size as i can just use Event.Button.x or y and do my calculations on 320x240 perspective.

Now i noticed my official raspberry pi touchscreen was not producing mousebuttondown events so i started adding in Fingerdown events. The documents say the x and y values are normalized between 0 and 1 however i seem to be getting negative values when letterboxing occurs and i can not seem to calculate the correct positions compared to the logical 320x240 size / perspective. If i do not resize my window and no letterboxing occurs i can seemingly find out the correct values by multiplying event.tfinger.x * windowsize but this does not work if letterboxing occurs and the negative values arise. How can i get these calculation done or is not normal when letterboxing occurs i get negative values for event.tfinger.x /y ?

i mean this with letterboxing to keep aspect ratio when i resize my window

I’m starting to think this might be a bug, i absolutely can’t find any calculation to get correct coordinates from sdl touchfinger event when letterboxing occurs and i can’t find any information on google either. Most examples i find run their games fullscreen at a resolution where no letterboxing occurs

Edit: i’m on to something. It seems rendertarget must be the screen texture / surface before calling pollevent if not doing this you can’t seem to calculate correct screen offsets am investigating and trying to reproduce sample code on what was occuring in my game

Ok i fixed the problem in my game but i’m not sure if it’s a bug in SDL or something or what i did wrong. I created a small sample application to show what was going wrong in my game.

You can see the code here

In my code line 39 does not exist and the buffer was my rendertarget so when i call SDL_Pollevent the screen is not the render target and then things got akward i could not never get correct coordinates for my logical size (320x240). If i add line 39 the code works perfectly. You can test this touching the red / black borders while the window is resized and letterboxing occurs. If you press the one on the right it should show an x coordinate of 320 if you touch the border on the left it should show 0. When i was testing things my render target was not the screen and i could never get any good coordinates only if the screensize remained constant and no letterboxing occured.

Maybe i was doing something wrong all along but for now i made sure to set my render target to NULL before running SDL_Pollevent or is this some kind of bug ?