diff options
author | Jaakko Keränen <jaakko.keranen@iki.fi> | 2020-09-30 14:54:27 +0300 |
---|---|---|
committer | Jaakko Keränen <jaakko.keranen@iki.fi> | 2020-09-30 14:55:12 +0300 |
commit | d27c0261cbbf77396e70c46c5fdb3745a85e48c0 (patch) | |
tree | 4802b3b2a537e4e278424fb722e79170f3f35933 /src/ui/window.c | |
parent | 3228d8104af43366ae80713594c5998791e09600 (diff) |
Windows: Use the system UI scaling factor
Check for system UI scaling factor via Direct2D DPI values.
Diffstat (limited to 'src/ui/window.c')
-rw-r--r-- | src/ui/window.c | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/src/ui/window.c b/src/ui/window.c index 419e6a0a..c0e8fdad 100644 --- a/src/ui/window.c +++ b/src/ui/window.c | |||
@@ -38,6 +38,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ | |||
38 | #include "../gmutil.h" | 38 | #include "../gmutil.h" |
39 | #if defined (iPlatformMsys) | 39 | #if defined (iPlatformMsys) |
40 | # include "../win32.h" | 40 | # include "../win32.h" |
41 | # include <d2d1.h> | ||
41 | #endif | 42 | #endif |
42 | #if defined (iPlatformApple) && !defined (iPlatformIOS) | 43 | #if defined (iPlatformApple) && !defined (iPlatformIOS) |
43 | # include "macos.h" | 44 | # include "macos.h" |
@@ -491,10 +492,26 @@ static void updateRootSize_Window_(iWindow *d) { | |||
491 | } | 492 | } |
492 | 493 | ||
493 | static float pixelRatio_Window_(const iWindow *d) { | 494 | static float pixelRatio_Window_(const iWindow *d) { |
495 | #if defined (iPlatformMsys) | ||
496 | /* Query Direct2D for the desktop DPI (not aware of which monitor, though). */ { | ||
497 | float ratio = 1.0f; | ||
498 | ID2D1Factory *d2dFactory = NULL; | ||
499 | HRESULT hr = D2D1CreateFactory( | ||
500 | D2D1_FACTORY_TYPE_SINGLE_THREADED, &IID_ID2D1Factory, NULL, (void **) &d2dFactory); | ||
501 | if (SUCCEEDED(hr)) { | ||
502 | FLOAT dpiX = 96; | ||
503 | FLOAT dpiY = 96; | ||
504 | ID2D1Factory_GetDesktopDpi(d2dFactory, &dpiX, &dpiY); | ||
505 | ratio = (float) (dpiX / 96.0); | ||
506 | ID2D1Factory_Release(d2dFactory); | ||
507 | } | ||
508 | } | ||
509 | #else | ||
494 | int dx, x; | 510 | int dx, x; |
495 | SDL_GetRendererOutputSize(d->render, &dx, NULL); | 511 | SDL_GetRendererOutputSize(d->render, &dx, NULL); |
496 | SDL_GetWindowSize(d->win, &x, NULL); | 512 | SDL_GetWindowSize(d->win, &x, NULL); |
497 | return (float) dx / (float) x; | 513 | return (float) dx / (float) x; |
514 | #endif | ||
498 | } | 515 | } |
499 | 516 | ||
500 | static void drawBlank_Window_(iWindow *d) { | 517 | static void drawBlank_Window_(iWindow *d) { |
@@ -778,7 +795,13 @@ iInt2 rootSize_Window(const iWindow *d) { | |||
778 | } | 795 | } |
779 | 796 | ||
780 | iInt2 coord_Window(const iWindow *d, int x, int y) { | 797 | iInt2 coord_Window(const iWindow *d, int x, int y) { |
798 | #if defined (iPlatformMsys) | ||
799 | /* On Windows, surface coordinates are in pixels. */ | ||
800 | return init_I2(x, y); | ||
801 | #else | ||
802 | /* Coordinates are in points. */ | ||
781 | return mulf_I2(init_I2(x, y), d->pixelRatio); | 803 | return mulf_I2(init_I2(x, y), d->pixelRatio); |
804 | #endif | ||
782 | } | 805 | } |
783 | 806 | ||
784 | iInt2 mouseCoord_Window(const iWindow *d) { | 807 | iInt2 mouseCoord_Window(const iWindow *d) { |