From d70232e7486104589b66977c776e5a55ef851a57 Mon Sep 17 00:00:00 2001 From: Ian Harrigan Date: Thu, 21 Dec 2023 11:19:01 +0100 Subject: [PATCH] dont reset button down on stage down (use event prop directly) --- haxe/ui/backend/ComponentImpl.hx | 1 - haxe/ui/backend/flixel/MouseHelper.hx | 69 ++++++--------------------- 2 files changed, 15 insertions(+), 55 deletions(-) diff --git a/haxe/ui/backend/ComponentImpl.hx b/haxe/ui/backend/ComponentImpl.hx index 9232a4b..c6f93a7 100644 --- a/haxe/ui/backend/ComponentImpl.hx +++ b/haxe/ui/backend/ComponentImpl.hx @@ -590,7 +590,6 @@ class ComponentImpl extends ComponentBase { if (hasTextInput()) { getTextInput().onMouseDown = null; } - case MouseEvent.MOUSE_UP: _eventMap.remove(type); diff --git a/haxe/ui/backend/flixel/MouseHelper.hx b/haxe/ui/backend/flixel/MouseHelper.hx index ea5e50e..bea313b 100644 --- a/haxe/ui/backend/flixel/MouseHelper.hx +++ b/haxe/ui/backend/flixel/MouseHelper.hx @@ -25,19 +25,12 @@ class MouseHelper { if (_hasOnMouseDown == false) { FlxG.stage.addEventListener(openfl.events.MouseEvent.MOUSE_DOWN, onMouseDown); FlxG.stage.addEventListener(openfl.events.MouseEvent.RIGHT_MOUSE_DOWN, onMouseDown); - - - FlxG.stage.addEventListener(openfl.events.MouseEvent.MOUSE_DOWN, onStageDown); - FlxG.stage.addEventListener(openfl.events.MouseEvent.RIGHT_MOUSE_DOWN, onStageRightDown); _hasOnMouseDown = true; } case MouseEvent.MOUSE_UP: if (_hasOnMouseUp == false) { FlxG.stage.addEventListener(openfl.events.MouseEvent.MOUSE_UP, onMouseUp); FlxG.stage.addEventListener(openfl.events.MouseEvent.RIGHT_MOUSE_UP, onMouseUp); - - FlxG.stage.addEventListener(openfl.events.MouseEvent.MOUSE_UP, onStageUp); - FlxG.stage.addEventListener(openfl.events.MouseEvent.RIGHT_MOUSE_UP, onStageRightUp); _hasOnMouseUp = true; FlxG.signals.preStateSwitch.add(onPreStateSwitched); } @@ -64,7 +57,7 @@ class MouseHelper { fn: callback, priority: priority }); - + list.sort(function(a, b) { return a.priority - b.priority; }); @@ -83,18 +76,12 @@ class MouseHelper { if (_hasOnMouseDown == true) { FlxG.stage.removeEventListener(openfl.events.MouseEvent.MOUSE_DOWN, onMouseDown); FlxG.stage.removeEventListener(openfl.events.MouseEvent.RIGHT_MOUSE_DOWN, onMouseDown); - - FlxG.stage.removeEventListener(openfl.events.MouseEvent.MOUSE_DOWN, onStageDown); - FlxG.stage.removeEventListener(openfl.events.MouseEvent.RIGHT_MOUSE_DOWN, onStageRightDown); _hasOnMouseDown = false; } case MouseEvent.MOUSE_UP: if (_hasOnMouseUp == true) { FlxG.stage.removeEventListener(openfl.events.MouseEvent.MOUSE_UP, onMouseUp); FlxG.stage.removeEventListener(openfl.events.MouseEvent.RIGHT_MOUSE_UP, onMouseUp); - - FlxG.stage.removeEventListener(openfl.events.MouseEvent.MOUSE_UP, onStageUp); - FlxG.stage.removeEventListener(openfl.events.MouseEvent.RIGHT_MOUSE_UP, onStageRightUp); _hasOnMouseUp = false; FlxG.signals.preStateSwitch.remove(onPreStateSwitched); } @@ -139,7 +126,13 @@ class MouseHelper { event.screenX = (currentMouseX - FlxG.scaleMode.offset.x) / (FlxG.scaleMode.scale.x * initialZoom()); event.screenY = (currentMouseY - FlxG.scaleMode.offset.y) / (FlxG.scaleMode.scale.y * initialZoom()); } - event.data = buttonPressed; + + #if FLX_NO_MOUSE + event.data = -1; + #else + event.data = (e.buttonDown ? 0 : 1); + #end + for (l in list) { l.fn(event); if (event.canceled == true) { @@ -169,7 +162,13 @@ class MouseHelper { event.screenX = (currentMouseX - FlxG.scaleMode.offset.x) / (FlxG.scaleMode.scale.x * initialZoom()); event.screenY = (currentMouseY - FlxG.scaleMode.offset.y) / (FlxG.scaleMode.scale.y * initialZoom()); } - event.data = buttonPressed; + + #if FLX_NO_MOUSE + event.data = -1; + #else + event.data = (e.buttonDown ? 0 : 1); + #end + for (l in list) { l.fn(event); if (event.canceled == true) { @@ -225,44 +224,6 @@ class MouseHelper { } } - private static function onStageDown(_) { - _buttonPressed = 0; - } - - private static function onStageUp(_) { - _buttonPressed = -1; - } - - private static function onStageRightDown(_) { - _buttonPressed = 1; - } - - private static function onStageRightUp(_) { - _buttonPressed = -1; - } - - private static var _buttonPressed:Int = -1; - private static var buttonPressed(get, null):Int; - private static function get_buttonPressed():Int { - var n = _buttonPressed; - - #if FLX_NO_MOUSE - - n = 0; - - #else - - if (FlxG.mouse.pressed == true) { - n = 0; - } else if (FlxG.mouse.pressedRight == true) { - n = 1; - } - - #end - - return n; - } - private static inline function initialZoom():Float { #if (flixel <= "4.11.0") // FlxG.initialZoom removed in later versions of flixel