Improve smallwindow detection, code cleanup.

This commit is contained in:
Henrik Rydgård committed 2017-01-17 17:21:00 +07:00
1 parent d91f82604d
commit 0be02f6de0
5 files changed
+45 -30

No files matched your search

+22 -6
View File
@@ -130,22 +130,38 @@ bool Core_GetPowerSaving() {
return powerSaving;
}
static int ScreenDPI() {
HDC screenDC = GetDC(nullptr);
int dotsPerInch = GetDeviceCaps(screenDC, LOGPIXELSY);
ReleaseDC(nullptr, screenDC);
return dotsPerInch;
}
static bool IsWindowSmall(int pixelWidth, int pixelHeight) {
// Can't take this from config as it will not be set if windows is maximized.
int w = (int)(pixelWidth * g_dpi_scale);
int h = (int)(pixelHeight * g_dpi_scale);
return g_Config.IsPortrait() ? (h < 480 + 80) : (w < 480 + 80);
}
// TODO: Feels like this belongs elsewhere.
bool UpdateScreenScale(int width, int height, bool smallWindow) {
bool UpdateScreenScale(int width, int height) {
bool smallWindow;
#ifdef _WIN32
// Use legacy DPI handling, because we still compile as XP compatible we don't get the new SDK, unless
// we do unholy tricks.
HDC screenDC = GetDC(nullptr);
double hPixelsPerInch = GetDeviceCaps(screenDC, LOGPIXELSY);
ReleaseDC(nullptr, screenDC);
g_dpi = hPixelsPerInch;
g_dpi = ScreenDPI();
g_dpi_scale = 96.0f / g_dpi;
smallWindow = IsWindowSmall(width, height);
#else
g_dpi = 96;
g_dpi_scale = 1.0f;
#endif
if (smallWindow) {
g_dpi /= 2;
g_dpi_scale *= 2.0f;
}
pixel_in_dps = 1.0f / g_dpi_scale;
int new_dp_xres = width * g_dpi_scale;