WinRT: fixed a display mode reporting bug, whereby DPI wasn't getting taken into account. (Thanks to Sylvain Becker for the fix!)
authorDavid Ludwig <dludwig@pobox.com>
Sun, 05 May 2013 11:27:58 -0400
changeset 8467 d99fb48fcded
parent 8466 497894d5361e
child 8468 51de52f20d4b
WinRT: fixed a display mode reporting bug, whereby DPI wasn't getting taken into account. (Thanks to Sylvain Becker for the fix!)
src/video/windowsrt/SDL_WinRTApp.cpp
--- a/src/video/windowsrt/SDL_WinRTApp.cpp	Sun May 05 10:27:14 2013 -0400
+++ b/src/video/windowsrt/SDL_WinRTApp.cpp	Sun May 05 11:27:58 2013 -0400
@@ -870,13 +870,22 @@
 
 SDL_DisplayMode SDL_WinRTApp::GetMainDisplayMode()
 {
+    // Create an empty, zeroed-out display mode:
     SDL_DisplayMode mode;
     SDL_zero(mode);
+
+    // Fill in most fields:
     mode.format = SDL_PIXELFORMAT_RGB888;
-    mode.w = (int) CoreWindow::GetForCurrentThread()->Bounds.Width;
-    mode.h = (int) CoreWindow::GetForCurrentThread()->Bounds.Height;
     mode.refresh_rate = 0;  // TODO, WinRT: see if refresh rate data is available, or relevant (for WinRT apps)
     mode.driverdata = NULL;
+
+    // Calculate the display size given the window size, taking into account
+    // the current display's DPI:
+    const float currentDPI = Windows::Graphics::Display::DisplayProperties::LogicalDpi; 
+    const float dipsPerInch = 96.0f;
+    mode.w = (int) ((CoreWindow::GetForCurrentThread()->Bounds.Width * currentDPI) / dipsPerInch);
+    mode.h = (int) ((CoreWindow::GetForCurrentThread()->Bounds.Height * currentDPI) / dipsPerInch);
+
     return mode;
 }