Skip to content

Commit

Permalink
DPI bug hotfix
Browse files Browse the repository at this point in the history
  • Loading branch information
Wassimulator committed Nov 14, 2023
1 parent f3d07d7 commit acfcc00
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
17 changes: 15 additions & 2 deletions src/events.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,13 @@ void reset_inputs() {
K->scroll_y_diff = 0;
K->double_click = 0;
}
static void set_framebuffer_size(Graphics *ctx, iv2 size);
static void set_framebuffer_size(Graphics *ctx, iv2 size, bool set_dpi = false);

LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) {
Keys *K = &G->keys;

switch (message) {
case WM_DESTROY: PostQuitMessage(0); Running = false; break;
case WM_DPICHANGED:
case WM_SIZE:
{
RECT rect;
Expand All @@ -39,6 +38,20 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)

break;
}
case WM_DPICHANGED:
{
RECT rect;
GetClientRect(hwnd, &rect);
WW = rect.right - rect.left;
WH = rect.bottom - rect.top;
set_framebuffer_size(&G->graphics, iv2(WW, WH), true);

G->minimized = false;
if (wParam == SIZE_MINIMIZED)
G->minimized = true;

break;
}
case WM_DROPFILES: {
if (!G->loading_dropped_file) {
UINT length = DragQueryFile((HDROP)wParam, /*only first one is handled*/ 0, NULL, 0);
Expand Down
9 changes: 6 additions & 3 deletions src/source.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,16 +169,19 @@ static void upload_texture(Texture* texture, void* data, u64 size) {
G->graphics.device_ctx->Unmap(texture->d3d_texture, 0);
}

static void set_framebuffer_size(Graphics *ctx, iv2 size) {
static void set_framebuffer_size(Graphics *ctx, iv2 size, bool set_dpi) {
if (ctx == nullptr) return;
if (ctx->viewport_size == size) return;
if (ctx->frame_buffer == nullptr) return;
if (size.x <= 0 || size.y <= 0) return;

// resize swapchain

UINT dpi = GetDpiForWindow(hwnd);
float dpi_scale_factor = dpi / 96.0f;
float dpi_scale_factor = 1;
if (set_dpi) {
UINT dpi = GetDpiForWindow(hwnd);
dpi_scale_factor = dpi / 96.0f;
}

ctx->frame_buffer_view->Release();
ctx->frame_buffer->Release();
Expand Down

0 comments on commit acfcc00

Please sign in to comment.