From a698fe5673bc296bf3630f201cc91b9658c384e4 Mon Sep 17 00:00:00 2001 From: "Adam D. Ruppe" Date: Thu, 19 Mar 2020 19:34:58 -0400 Subject: [PATCH] fix mouse coord of mouse wheel on windows --- simpledisplay.d | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/simpledisplay.d b/simpledisplay.d index 69cd008..8906bd8 100644 --- a/simpledisplay.d +++ b/simpledisplay.d @@ -7775,8 +7775,11 @@ version(Windows) { static HFONT defaultGuiFont; void setFont(OperatingSystemFont font) { - if(font && font.font) - SelectObject(hdc, font.font); + if(font && font.font) { + if(SelectObject(hdc, font.font) == HGDI_ERROR) { + // error... how to handle tho? + } + } else if(defaultGuiFont) SelectObject(hdc, defaultGuiFont); } @@ -8341,9 +8344,20 @@ version(Windows) { static int triggerEvents(HWND hwnd, uint msg, WPARAM wParam, LPARAM lParam, int offsetX, int offsetY, SimpleWindow wind) { MouseEvent mouse; - void mouseEvent() { - mouse.x = LOWORD(lParam) + offsetX; - mouse.y = HIWORD(lParam) + offsetY; + void mouseEvent(bool isScreen = false) { + auto x = LOWORD(lParam); + auto y = HIWORD(lParam); + if(isScreen) { + POINT p; + p.x = x; + p.y = y; + ScreenToClient(hwnd, &p); + x = cast(ushort) p.x; + y = cast(ushort) p.y; + } + mouse.x = x + offsetX; + mouse.y = y + offsetY; + wind.mdx(mouse); mouse.modifierState = cast(int) wParam; mouse.window = wind; @@ -8441,7 +8455,7 @@ version(Windows) { case 0x020a /*WM_MOUSEWHEEL*/: mouse.type = cast(MouseEventType) 1; mouse.button = ((HIWORD(wParam) > 120) ? MouseButton.wheelDown : MouseButton.wheelUp); - mouseEvent(); + mouseEvent(true); break; case WM_MOUSEMOVE: mouse.type = cast(MouseEventType) 0;