Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add methods to get device pixel ratio #249

Merged

Conversation

sumibi-yakitori
Copy link
Contributor

@sumibi-yakitori sumibi-yakitori commented Apr 10, 2021

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:

@sumibi-yakitori sumibi-yakitori changed the title Add method to get device pixel ratio Add methods to get device pixel ratio Apr 10, 2021
@sumibi-yakitori sumibi-yakitori force-pushed the add_get_device_pixel_ratio branch from 58afd20 to df7fbd4 Compare April 10, 2021 08:36
@17cupsofcoffee
Copy link
Owner

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).

@sumibi-yakitori
Copy link
Contributor Author

sumibi-yakitori commented Apr 10, 2021

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

@sumibi-yakitori
Copy link
Contributor Author

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.

@17cupsofcoffee
Copy link
Owner

Done a little digging:

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 😄

Copy link
Owner

@17cupsofcoffee 17cupsofcoffee left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀

@sumibi-yakitori
Copy link
Contributor Author

sumibi-yakitori commented Apr 10, 2021

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.

@17cupsofcoffee 17cupsofcoffee merged commit 361dcf9 into 17cupsofcoffee:main Apr 10, 2021
@sumibi-yakitori sumibi-yakitori deleted the add_get_device_pixel_ratio branch April 10, 2021 22:25
@17cupsofcoffee
Copy link
Owner

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

@17cupsofcoffee
Copy link
Owner

@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 :)

@sumibi-yakitori
Copy link
Contributor Author

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...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants