Browse Source

added Interactive.preventClick

ncannasse 9 years ago
parent
commit
a55d9609c2
2 changed files with 20 additions and 6 deletions
  1. 7 0
      h2d/Interactive.hx
  2. 13 6
      h3d/scene/Interactive.hx

+ 7 - 0
h2d/Interactive.hx

@@ -79,6 +79,13 @@ class Interactive extends Drawable implements hxd.SceneEvents.Interactive {
 		}
 		}
 	}
 	}
 
 
+	/**
+		This can be called during or after a push event in order to prevent the release from triggering a click.
+	**/
+	public function preventClick() {
+		mouseDownButton = -1;
+	}
+
 	@:noCompletion public function getInteractiveScene() : hxd.SceneEvents.InteractiveScene {
 	@:noCompletion public function getInteractiveScene() : hxd.SceneEvents.InteractiveScene {
 		return scene;
 		return scene;
 	}
 	}

+ 13 - 6
h3d/scene/Interactive.hx

@@ -14,7 +14,7 @@ class Interactive extends Object implements hxd.SceneEvents.Interactive {
 	public var propagateEvents : Bool = false;
 	public var propagateEvents : Bool = false;
 	public var enableRightButton : Bool;
 	public var enableRightButton : Bool;
 	var scene : Scene;
 	var scene : Scene;
-	var isMouseDown : Int;
+	var mouseDownButton : Int = -1;
 
 
 	@:allow(h3d.scene.Scene)
 	@:allow(h3d.scene.Scene)
 	var hitPoint = new h3d.Vector();
 	var hitPoint = new h3d.Vector();
@@ -39,6 +39,13 @@ class Interactive extends Object implements hxd.SceneEvents.Interactive {
 		super.onDelete();
 		super.onDelete();
 	}
 	}
 
 
+	/**
+		This can be called during or after a push event in order to prevent the release from triggering a click.
+	**/
+	public function preventClick() {
+		mouseDownButton = -1;
+	}
+
 	@:noCompletion public function getInteractiveScene() : hxd.SceneEvents.InteractiveScene {
 	@:noCompletion public function getInteractiveScene() : hxd.SceneEvents.InteractiveScene {
 		return scene;
 		return scene;
 	}
 	}
@@ -51,28 +58,28 @@ class Interactive extends Object implements hxd.SceneEvents.Interactive {
 			onMove(e);
 			onMove(e);
 		case EPush:
 		case EPush:
 			if( enableRightButton || e.button == 0 ) {
 			if( enableRightButton || e.button == 0 ) {
-				isMouseDown = e.button;
+				mouseDownButton = e.button;
 				onPush(e);
 				onPush(e);
 			}
 			}
 		case ERelease:
 		case ERelease:
 			if( enableRightButton || e.button == 0 ) {
 			if( enableRightButton || e.button == 0 ) {
 				onRelease(e);
 				onRelease(e);
-				if( isMouseDown == e.button )
+				if( mouseDownButton == e.button )
 					onClick(e);
 					onClick(e);
 			}
 			}
-			isMouseDown = -1;
+			mouseDownButton = -1;
 		case EReleaseOutside:
 		case EReleaseOutside:
 			if( enableRightButton || e.button == 0 ) {
 			if( enableRightButton || e.button == 0 ) {
 				e.kind = ERelease;
 				e.kind = ERelease;
 				onRelease(e);
 				onRelease(e);
 				e.kind = EReleaseOutside;
 				e.kind = EReleaseOutside;
 			}
 			}
-			isMouseDown = -1;
+			mouseDownButton = -1;
 		case EOver:
 		case EOver:
 			hxd.System.setCursor(cursor);
 			hxd.System.setCursor(cursor);
 			onOver(e);
 			onOver(e);
 		case EOut:
 		case EOut:
-			isMouseDown = -1;
+			mouseDownButton = -1;
 			hxd.System.setCursor(Default);
 			hxd.System.setCursor(Default);
 			onOut(e);
 			onOut(e);
 		case EWheel:
 		case EWheel: