Skip to content

Commit

Permalink
Fix scaling for simulator mode.
Browse files Browse the repository at this point in the history
  • Loading branch information
MouriNaruto committed Dec 11, 2023
1 parent cc01778 commit 36f01ec
Showing 1 changed file with 31 additions and 12 deletions.
43 changes: 31 additions & 12 deletions LvglWindowsSimulator/win32drv.c
Original file line number Diff line number Diff line change
Expand Up @@ -689,14 +689,25 @@ static void lv_windows_display_driver_flush_callback(
context->display_framebuffer_context_handle,
0,
0,
MulDiv(
#if LV_WINDOWS_SIMULATOR_MODE
lv_windows_pixel_to_logical(
client_rect.right - client_rect.left,
LV_WINDOWS_ZOOM_LEVEL,
context->window_dpi),
lv_windows_pixel_to_logical(
client_rect.bottom - client_rect.top,
LV_WINDOWS_ZOOM_LEVEL,
context->window_dpi),
#else
lv_windows_pixel_to_logical(
client_rect.right - client_rect.left,
LV_WINDOWS_ZOOM_BASE_LEVEL,
LV_WINDOWS_ZOOM_LEVEL),
MulDiv(
LV_WINDOWS_ZOOM_LEVEL,
USER_DEFAULT_SCREEN_DPI),
lv_windows_pixel_to_logical(
client_rect.bottom - client_rect.top,
LV_WINDOWS_ZOOM_BASE_LEVEL,
LV_WINDOWS_ZOOM_LEVEL),
LV_WINDOWS_ZOOM_LEVEL,
USER_DEFAULT_SCREEN_DPI),
#endif
SRCCOPY);

ReleaseDC(window_handle, hdc);
Expand Down Expand Up @@ -1372,6 +1383,14 @@ static LRESULT CALLBACK lv_windows_window_message_callback(
context->display_device_object);

#if LV_WINDOWS_SIMULATOR_MODE
context->display_resolution_changed = true;
context->requested_display_resolution.x =
lv_display_get_horizontal_resolution(
context->display_device_object);
context->requested_display_resolution.y =
lv_display_get_vertical_resolution(
context->display_device_object);

int32_t dpi = lv_display_get_dpi(context->display_device_object);

RECT calculated_window_size;
Expand Down Expand Up @@ -1414,6 +1433,7 @@ static LRESULT CALLBACK lv_windows_window_message_callback(

break;
}
#if !LV_WINDOWS_SIMULATOR_MODE
case WM_SIZE:
{
if (wParam != SIZE_MINIMIZED)
Expand All @@ -1429,7 +1449,7 @@ static LRESULT CALLBACK lv_windows_window_message_callback(
}
break;
}
#if !LV_WINDOWS_ALLOW_DPI_OVERRIDE
#endif
case WM_DPICHANGED:
{
lv_windows_window_context_t* context = (lv_windows_window_context_t*)(
Expand All @@ -1438,9 +1458,11 @@ static LRESULT CALLBACK lv_windows_window_message_callback(
{
context->window_dpi = HIWORD(wParam);

#if !LV_WINDOWS_ALLOW_DPI_OVERRIDE
lv_display_set_dpi(
context->display_device_object,
context->window_dpi);
#endif

LPRECT suggested_rect = (LPRECT)lParam;

Expand All @@ -1454,8 +1476,6 @@ static LRESULT CALLBACK lv_windows_window_message_callback(
SWP_NOZORDER | SWP_NOACTIVATE);

#if LV_WINDOWS_SIMULATOR_MODE
int32_t dpi = lv_display_get_dpi(context->display_device_object);

RECT client_rect;
GetClientRect(hWnd, &client_rect);

Expand All @@ -1466,11 +1486,11 @@ static LRESULT CALLBACK lv_windows_window_message_callback(

int window_width = MulDiv(
hor_res,
LV_WINDOWS_ZOOM_LEVEL * dpi,
LV_WINDOWS_ZOOM_LEVEL * context->window_dpi,
LV_WINDOWS_ZOOM_BASE_LEVEL * USER_DEFAULT_SCREEN_DPI);
int window_height = MulDiv(
ver_res,
LV_WINDOWS_ZOOM_LEVEL * dpi,
LV_WINDOWS_ZOOM_LEVEL * context->window_dpi,
LV_WINDOWS_ZOOM_BASE_LEVEL * USER_DEFAULT_SCREEN_DPI);

SetWindowPos(
Expand All @@ -1486,7 +1506,6 @@ static LRESULT CALLBACK lv_windows_window_message_callback(

break;
}
#endif
case WM_ERASEBKGND:
{
return TRUE;
Expand Down

0 comments on commit 36f01ec

Please sign in to comment.