diff --git a/haxe/ui/backend/ScreenImpl.hx b/haxe/ui/backend/ScreenImpl.hx index 3c20ed1..75f3ff9 100644 --- a/haxe/ui/backend/ScreenImpl.hx +++ b/haxe/ui/backend/ScreenImpl.hx @@ -46,6 +46,7 @@ class ScreenImpl extends ScreenBase { } private function onWindowResize() { + MouseHelper.updateScale(true); resizeRootComponents(); } @@ -63,6 +64,7 @@ class ScreenImpl extends ScreenBase { } private function set_root(value:Object):Object { _root = value; + MouseHelper.updateScale(); return value; } diff --git a/haxe/ui/backend/heaps/MouseHelper.hx b/haxe/ui/backend/heaps/MouseHelper.hx index 4bfef7e..bd0920f 100644 --- a/haxe/ui/backend/heaps/MouseHelper.hx +++ b/haxe/ui/backend/heaps/MouseHelper.hx @@ -108,9 +108,30 @@ class MouseHelper { } } + private static var scaleX:Null = null; + private static var scaleY:Null = null; + public static function updateScale(force:Bool = false) { + if (force) { + scaleX = null; + scaleY = null; + } + if (scaleX != null && scaleY != null) { + return; + } + + switch (Screen.instance.scene.scaleMode) { + case LetterBox(width, height, integerScale, horizontalAlign, verticalAlign): + scaleX = hxd.Window.getInstance().width / width; + scaleY = hxd.Window.getInstance().height / height; + case _: + scaleX = 1; + scaleY = 1; + } + } + private static function onMouseMove(e:hxd.Event) { - currentMouseX = e.relX / Toolkit.scaleX; - currentMouseY = e.relY / Toolkit.scaleY; + currentMouseX = e.relX / (Toolkit.scaleX * scaleX); + currentMouseY = e.relY / (Toolkit.scaleY * scaleY); var list = _callbacks.get(MouseEvent.MOUSE_MOVE); if (list == null || list.length == 0) { @@ -122,8 +143,8 @@ class MouseHelper { var event = new MouseEvent(MouseEvent.MOUSE_MOVE); @:privateAccess event._originalEvent = e; - event.screenX = e.relX / Toolkit.scaleX; - event.screenY = e.relY / Toolkit.scaleY; + event.screenX = e.relX / (Toolkit.scaleX * scaleX); + event.screenY = e.relY / (Toolkit.scaleY * scaleY); for (l in list) { l(event); if (event.canceled) { @@ -143,8 +164,8 @@ class MouseHelper { var event = new MouseEvent(MouseEvent.MOUSE_DOWN); @:privateAccess event._originalEvent = e; - event.screenX = e.relX / Toolkit.scaleX; - event.screenY = e.relY / Toolkit.scaleY; + event.screenX = e.relX / (Toolkit.scaleX * scaleX); + event.screenY = e.relY / (Toolkit.scaleX * scaleX); event.data = e.button; for (l in list) { l(event); @@ -165,8 +186,8 @@ class MouseHelper { var event = new MouseEvent(MouseEvent.MOUSE_UP); @:privateAccess event._originalEvent = e; - event.screenX = e.relX / Toolkit.scaleX; - event.screenY = e.relY / Toolkit.scaleY; + event.screenX = e.relX / (Toolkit.scaleX * scaleX); + event.screenY = e.relY / (Toolkit.scaleX * scaleX); event.data = e.button; for (l in list) { l(event);