Create win32_get_metrics

This commit is contained in:
twinaphex 2015-04-09 05:19:29 +02:00
parent 1f23338ca4
commit dc10606b23
5 changed files with 51 additions and 62 deletions

View File

@ -13,10 +13,8 @@
* If not, see <http://www.gnu.org/licenses/>.
*/
#include "../../driver.h"
#include "../../general.h"
#include "win32_common.h"
#include <string.h>
#if !defined(_XBOX) && defined(_WIN32)
@ -182,3 +180,39 @@ LRESULT win32_menu_loop(HWND owner, WPARAM wparam)
return 0L;
}
#endif
bool win32_get_metrics(void *data,
enum display_metric_types type, float *value)
{
#ifdef _XBOX
return false;
#else
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_MM_WIDTH:
*value = physical_width;
break;
case DISPLAY_METRIC_MM_HEIGHT:
*value = physical_height;
break;
case DISPLAY_METRIC_DPI:
/* 25.4 mm in an inch. */
*value = 254 * pixels_x / physical_width / 10;
break;
case DISPLAY_METRIC_NONE:
default:
*value = 0;
return false;
}
return true;
#endif
}

View File

@ -17,6 +17,11 @@
#ifndef WIN32_COMMON_H__
#define WIN32_COMMON_H__
#include <string.h>
#include <boolean.h>
#include "../../driver.h"
#include "../video_context_driver.h"
#ifdef __cplusplus
extern "C" {
#endif
@ -32,6 +37,9 @@ LRESULT win32_handle_keyboard_event(HWND hwnd, UINT message,
LRESULT win32_menu_loop(HWND handle, WPARAM wparam);
#endif
bool win32_get_metrics(void *data,
enum display_metric_types type, float *value);
#ifdef __cplusplus
}
#endif

View File

@ -495,37 +495,7 @@ static void gfx_ctx_d3d_swap_interval(void *data, unsigned interval)
static bool gfx_ctx_d3d_get_metrics(void *data,
enum display_metric_types type, float *value)
{
#ifdef _XBOX
return false;
#else
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_MM_WIDTH:
*value = physical_width;
break;
case DISPLAY_METRIC_MM_HEIGHT:
*value = physical_height;
break;
case DISPLAY_METRIC_DPI:
/* 25.4 mm in an inch. */
*value = 254 * pixels_x / physical_width / 10;
break;
case DISPLAY_METRIC_NONE:
default:
*value = 0;
return false;
}
return true;
#endif
return win32_get_metrics(data, type, value);
}
const gfx_ctx_driver_t gfx_ctx_d3d = {

View File

@ -667,34 +667,7 @@ static gfx_ctx_proc_t gfx_ctx_wgl_get_proc_address(const char *symbol)
static bool gfx_ctx_wgl_get_metrics(void *data,
enum display_metric_types type, float *value)
{
bool ret = true;
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_MM_WIDTH:
*value = physical_width;
break;
case DISPLAY_METRIC_MM_HEIGHT:
*value = physical_height;
break;
case DISPLAY_METRIC_DPI:
/* 25.4 mm in an inch. */
*value = 254 * pixels_x / physical_width / 10;
break;
case DISPLAY_METRIC_NONE:
default:
*value = 0;
return false;
}
return true;
return win32_get_metrics(data, type, value);
}
static bool gfx_ctx_wgl_bind_api(void *data,

View File

@ -86,11 +86,15 @@ CHEATS
/*============================================================
UI COMMON CONTEXT
============================================================ */
#if defined(_WIN32) && !defined(_XBOX)
#if defined(_WIN32)
#include "../gfx/common/win32_common.c"
#ifndef _XBOX
#include "../gfx/drivers_wm/win32_dwm_common.c"
#endif
#endif
/*============================================================
VIDEO CONTEXT
============================================================ */