The SDL forums have moved to discourse.libsdl.org.
This is just a read-only archive of the previous forums, to keep old links working.


SDL Forum Index
SDL
Simple Directmedia Layer Forums
Mac mouse X/Y on HiDPI
Stefanos A.
Guest

When running SDL2 with the SDL_ALLOW_HIGHDPI flag on a Mac, mouse events are delivered in screen points. For pixel-level access, I am converting these points to pixels by multiplying by the DPI scale factor: SDL_GL_GetDrawableSize() / SDL_GetWindowSize()


Example:

1. Create HiDPI 800x600 window

2. The drawable size of this window is 1600x1200

3. Mouse event coordinates are [0,0]-[799,599]

4. For pixel-level access, I scale the coordinates to [0,0]-[1598,1198]



However, this approach means that I can only address half the pixels of the drawable (i.e. 0, 2, 4, ..., 1598)


Does anyone know of a better approach?
Mac mouse X/Y on HiDPI
Alex Szpakowski
Guest

I encountered the same thing back when retina support was initially added, but it turned out that (at least on my computer) Apple’s own APIs reported the mouse position with the same level of granularity as SDL does, when I used a HiDPI display resolution.

On May 6, 2014, at 4:30 AM, Stefanos A. wrote:

Quote:
When running SDL2 with the SDL_ALLOW_HIGHDPI flag on a Mac, mouse events are delivered in screen points. For pixel-level access, I am converting these points to pixels by multiplying by the DPI scale factor: SDL_GL_GetDrawableSize() / SDL_GetWindowSize()

Example:
1. Create HiDPI 800x600 window
2. The drawable size of this window is 1600x1200
3. Mouse event coordinates are [0,0]-[799,599]
4. For pixel-level access, I scale the coordinates to [0,0]-[1598,1198]

However, this approach means that I can only address half the pixels of the drawable (i.e. 0, 2, 4, ..., 1598)

Does anyone know of a better approach?
_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
Mac mouse X/Y on HiDPI
Stefanos A.
Guest

Cocoa indeed reports mouse coordinates in points (so [0,0]-[800,600] for a 800x600 window), but the datatype is float and, as far as I can tell, mouse events are delivered with sub-point accuracy. SDL2 appears to be chopping off these fractional parts by converting the coordinates to integers.


The end result is that my Cocoa backend can address individual pixels but my SDL2 backend can only address even pixels. This is different than on windows, where SDL2 can address each pixel individually.


Note that a similar thing is happening with wheel events, which are always rounded to integer numbers. This is causing a reduction in accuracy both on Windows and on Mac OS X, which support fractional wheel rotations.

Maybe it would be possible to add two more fields to the event structure that hold the floating point coordinates from the OS? (i.e. float RawX, RawY, RawWheel?)



 



2014-05-06 16:03 GMT+02:00 Alex Szpakowski:
Quote:
I encountered the same thing back when retina support was initially added, but it turned out that (at least on my computer) Apple’s own APIs reported the mouse position with the same level of granularity as SDL does, when I used a HiDPI display resolution.

On May 6, 2014, at 4:30 AM, Stefanos A. wrote:

Quote:
When running SDL2 with the SDL_ALLOW_HIGHDPI flag on a Mac, mouse events are delivered in screen points. For pixel-level access, I am converting these points to pixels by multiplying by the DPI scale factor: SDL_GL_GetDrawableSize() / SDL_GetWindowSize()

Example:
1. Create HiDPI 800x600 window
2. The drawable size of this window is 1600x1200
3. Mouse event coordinates are [0,0]-[799,599]
4. For pixel-level access, I scale the coordinates to [0,0]-[1598,1198]

However, this approach means that I can only address half the pixels of the drawable (i.e. 0, 2, 4, ..., 1598)

Does anyone know of a better approach?


Quote:
_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org