Skip to content
Snippets Groups Projects
Commit 110edf32 authored by Henri Verbeet's avatar Henri Verbeet
Browse files

demos: Add basic DPI handling.

parent 21e08955
No related branches found
No related tags found
1 merge request!1432demos: Add basic DPI handling.
Pipeline #39719 skipped
......@@ -31,6 +31,8 @@ struct demo
void *user_data;
void (*idle_func)(struct demo *demo, void *user_data);
UINT (*GetDpiForSystem)(void);
};
struct demo_window
......@@ -48,6 +50,11 @@ struct demo_swapchain
IDXGISwapChain3 *swapchain;
};
static inline void demo_get_dpi(struct demo *demo, double *dpi_x, double *dpi_y)
{
*dpi_x = *dpi_y = demo->GetDpiForSystem();
}
static inline struct demo_window *demo_window_create(struct demo *demo, const char *title,
unsigned int width, unsigned int height, void *user_data)
{
......@@ -191,6 +198,11 @@ static inline void demo_process_events(struct demo *demo)
}
}
static inline UINT demo_GetDpiForSystem(void)
{
return 96;
}
static inline bool demo_init(struct demo *demo, void *user_data)
{
WNDCLASSEXW wc;
......@@ -215,6 +227,11 @@ static inline bool demo_init(struct demo *demo, void *user_data)
demo->user_data = user_data;
demo->idle_func = NULL;
if ((demo->GetDpiForSystem = (void *)GetProcAddress(GetModuleHandleA("user32"), "GetDpiForSystem")))
SetProcessDPIAware();
else
demo->GetDpiForSystem = demo_GetDpiForSystem;
return true;
}
......
......@@ -198,6 +198,20 @@ static inline xcb_screen_t *demo_get_screen(xcb_connection_t *c, int idx)
return NULL;
}
static inline void demo_get_dpi(struct demo *demo, double *dpi_x, double *dpi_y)
{
xcb_screen_t *screen;
if (!(screen = demo_get_screen(demo->connection, demo->screen)))
{
*dpi_x = *dpi_y = 96.0;
return;
}
*dpi_x = screen->width_in_pixels * 25.4 / screen->width_in_millimeters;
*dpi_y = screen->height_in_pixels * 25.4 / screen->height_in_millimeters;
}
static inline struct demo_window *demo_window_create(struct demo *demo, const char *title,
unsigned int width, unsigned int height, void *user_data)
{
......
......@@ -849,12 +849,16 @@ static int cxg_main(void)
{
unsigned int width = 300, height = 300;
struct cx_gears cxg;
double dpi_x, dpi_y;
memset(&cxg, 0, sizeof(cxg));
if (!demo_init(&cxg.demo, &cxg))
return EXIT_FAILURE;
demo_set_idle_func(&cxg.demo, cxg_idle);
demo_get_dpi(&cxg.demo, &dpi_x, &dpi_y);
width *= dpi_x / 96.0;
height *= dpi_y / 96.0;
cxg.window = demo_window_create(&cxg.demo, "Vkd3d Gears", width, height, &cxg);
demo_window_set_key_press_func(cxg.window, cxg_key_press);
demo_window_set_expose_func(cxg.window, cxg_expose);
......
......@@ -368,12 +368,16 @@ static int cxt_main(void)
{
unsigned int width = 640, height = 480;
struct cx_triangle cxt;
double dpi_x, dpi_y;
memset(&cxt, 0, sizeof(cxt));
if (!demo_init(&cxt.demo, NULL))
return EXIT_FAILURE;
demo_get_dpi(&cxt.demo, &dpi_x, &dpi_y);
width *= dpi_x / 96.0;
height *= dpi_y / 96.0;
cxt.window = demo_window_create(&cxt.demo, "Vkd3d Triangle", width, height, &cxt);
demo_window_set_expose_func(cxt.window, cxt_render_frame);
demo_window_set_key_press_func(cxt.window, cxt_key_press);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment