Closed sumibi-yakitori closed 3 years ago
This looks good, and is basically the same as how I've seen other engines implement this 👍
The only thing I'm not sure about is returning seperate values for the width and height ratio - is there any scenario where those values would not be the same? If not, then it might be worth just returning a single value (which is what Love2D and the web API you linked do).
Since I thought that there might be some very strange display devices in the world, and that there might be a rare possibility that they might appear in the future, and since I thought that a non-square HIDPI scale might be set by hacking, I decided to return two values in this function.
However, I think all of these cases are either very rare or impossible, so I have no objection to modifying this function to return a single value.
Which would be better?
windows - Are pixels ever not a square on a monitor? - Stack Overflow
It seems to be guaranteed that x and y will be on the same scale in Windows.
GetDpiForMonitor function (shellscalingapi.h) - Win32 apps | Microsoft Docs
The values of dpiX and dpiY are identical. You only need to record one of the values to determine the DPI and respond appropriately.
Done a little digging:
Xft.dpi
is the setting you use to set the scaling, and that's a single value.So while I think theoretically displays can have non-square pixels, it doesn't look like OSes really expose this in any meaningful way, so it's probably better to just return a single value. If anyone comes along that desperately needs non-uniform scale factors, I can change it later/add a new method 😄
Fixed. Thanks for the thorough investigation!
If you don't like the name of this function, feel free to change it to get_dpi_scale
or whatever you like.
Thanks for the PR! I may switch the name to your suggestion, just for consistency with the existing high_dpi
flag (and cause it's a little shorter 😛), but happy with the implementation
@sumibi-yakitori FYI, I've also added a get_physical_size
function on the main branch as part of another change, which will give you the unscaled size of the window. Might be useful to you :)
Thank you for taking the time to tell me about this.
Lately, I've been spending a lot of time thinking about whether I should get out of Tokyo, where I live, and I haven't been able to concentrate on development work...
This method allows you to get the pixel ratio of the display on which the current window is displayed, which is more convenient than
SDL_GetDisplayDPI
References: