From e8f2057ecdef9bad05f9717b5f8afac984cbe82a Mon Sep 17 00:00:00 2001 From: Vadim Lopatin Date: Tue, 10 Mar 2015 17:55:26 +0300 Subject: [PATCH] fix mouse coordinates for HIGHDPI on mac --- src/dlangui/platforms/sdl/sdlapp.d | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/dlangui/platforms/sdl/sdlapp.d b/src/dlangui/platforms/sdl/sdlapp.d index 1cde62f6..f1b4fa57 100644 --- a/src/dlangui/platforms/sdl/sdlapp.d +++ b/src/dlangui/platforms/sdl/sdlapp.d @@ -432,6 +432,22 @@ class SDLWindow : Window { short lastx; short lasty; void processMouseEvent(MouseAction action, uint button, uint state, int x, int y) { + + // correct mouse coordinates for HIGHDPI on mac + int drawableW = 0; + int drawableH = 0; + int winW = 0; + int winH = 0; + SDL_GL_GetDrawableSize(_win, &drawableW, &drawableH); + SDL_GetWindowSize(_win, &winW, &winH); + if (drawableW != winW || drawableH != winH) { + if (drawableW > 0 && winW > 0 && drawableH > 0 && drawableW > 0) { + x = x * drawableW / winW; + y = y * drawableH / winH; + } + } + + MouseEvent event = null; if (action == MouseAction.Wheel) { // handle wheel