Simplify win32_get_metrics

This commit is contained in:
twinaphex 2021-08-21 02:24:32 +02:00
parent eb50d7dbb4
commit 462137305b
2 changed files with 52 additions and 35 deletions

View file

@ -1666,31 +1666,45 @@ bool win32_get_metrics(void *data,
enum display_metric_types type, float *value)
{
#if !defined(_XBOX)
HDC monitor = GetDC(NULL);
int pixels_x = GetDeviceCaps(monitor, HORZRES);
int pixels_y = GetDeviceCaps(monitor, VERTRES);
int physical_width = GetDeviceCaps(monitor, HORZSIZE);
int physical_height = GetDeviceCaps(monitor, VERTSIZE);
ReleaseDC(NULL, monitor);
switch (type)
{
case DISPLAY_METRIC_PIXEL_WIDTH:
*value = pixels_x;
{
HDC monitor = GetDC(NULL);
*value = GetDeviceCaps(monitor, HORZRES);
ReleaseDC(NULL, monitor);
}
return true;
case DISPLAY_METRIC_PIXEL_HEIGHT:
*value = pixels_y;
{
HDC monitor = GetDC(NULL);
*value = GetDeviceCaps(monitor, VERTRES);
ReleaseDC(NULL, monitor);
}
return true;
case DISPLAY_METRIC_MM_WIDTH:
*value = physical_width;
{
HDC monitor = GetDC(NULL);
*value = GetDeviceCaps(monitor, HORZSIZE);
ReleaseDC(NULL, monitor);
}
return true;
case DISPLAY_METRIC_MM_HEIGHT:
*value = physical_height;
{
HDC monitor = GetDC(NULL);
*value = GetDeviceCaps(monitor, VERTSIZE);
ReleaseDC(NULL, monitor);
}
return true;
case DISPLAY_METRIC_DPI:
/* 25.4 mm in an inch. */
*value = 254 * pixels_x / physical_width / 10;
{
HDC monitor = GetDC(NULL);
int pixels_x = GetDeviceCaps(monitor, HORZRES);
int physical_width = GetDeviceCaps(monitor, HORZSIZE);
*value = 254 * pixels_x / physical_width / 10;
ReleaseDC(NULL, monitor);
}
return true;
case DISPLAY_METRIC_NONE:
default:

View file

@ -639,36 +639,39 @@ extern "C" {
bool win32_get_metrics(void* data,
enum display_metric_types type, float* value)
{
int pixels_x = DisplayInformation::GetForCurrentView()->ScreenWidthInRawPixels;
int pixels_y = DisplayInformation::GetForCurrentView()->ScreenHeightInRawPixels;
int raw_dpi_x = DisplayInformation::GetForCurrentView()->RawDpiX;
int raw_dpi_y = DisplayInformation::GetForCurrentView()->RawDpiY;
int physical_width = pixels_x / raw_dpi_x;
int physical_height = pixels_y / raw_dpi_y;
switch (type)
{
case DISPLAY_METRIC_PIXEL_WIDTH:
*value = pixels_x;
return true;
case DISPLAY_METRIC_PIXEL_WIDTH:
*value = DisplayInformation::GetForCurrentView()->ScreenWidthInRawPixels;
return true;
case DISPLAY_METRIC_PIXEL_HEIGHT:
*value = pixels_y;
return true;
*value = DisplayInformation::GetForCurrentView()->ScreenHeightInRawPixels;
return true;
case DISPLAY_METRIC_MM_WIDTH:
/* 25.4 mm in an inch. */
*value = 254 * physical_width / 10;
return true;
/* 25.4 mm in an inch. */
{
int pixels_x = DisplayInformation::GetForCurrentView()->ScreenWidthInRawPixels;
int raw_dpi_x = DisplayInformation::GetForCurrentView()->RawDpiX;
int physical_width = pixels_x / raw_dpi_x;
*value = 254 * physical_width / 10;
}
return true;
case DISPLAY_METRIC_MM_HEIGHT:
/* 25.4 mm in an inch. */
*value = 254 * physical_height / 10;
return true;
/* 25.4 mm in an inch. */
{
int pixels_y = DisplayInformation::GetForCurrentView()->ScreenHeightInRawPixels;
int raw_dpi_y = DisplayInformation::GetForCurrentView()->RawDpiY;
int physical_height = pixels_y / raw_dpi_y;
*value = 254 * physical_height / 10;
}
return true;
case DISPLAY_METRIC_DPI:
*value = raw_dpi_x;
return true;
*value = DisplayInformation::GetForCurrentView()->RawDpiX;
return true;
case DISPLAY_METRIC_NONE:
default:
*value = 0;
break;
*value = 0;
break;
}
return false;
}