Skip to content

Commit

Permalink
dont reset button down on stage down (use event prop directly)
Browse files Browse the repository at this point in the history
  • Loading branch information
ianharrigan committed Dec 21, 2023
1 parent 9a1abf4 commit d70232e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 55 deletions.
1 change: 0 additions & 1 deletion haxe/ui/backend/ComponentImpl.hx
Original file line number Diff line number Diff line change
Expand Up @@ -590,7 +590,6 @@ class ComponentImpl extends ComponentBase {
if (hasTextInput()) {
getTextInput().onMouseDown = null;
}


case MouseEvent.MOUSE_UP:
_eventMap.remove(type);
Expand Down
69 changes: 15 additions & 54 deletions haxe/ui/backend/flixel/MouseHelper.hx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -64,7 +57,7 @@ class MouseHelper {
fn: callback,
priority: priority
});

list.sort(function(a, b) {
return a.priority - b.priority;
});
Expand All @@ -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);
}
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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

Expand Down

0 comments on commit d70232e

Please sign in to comment.