Ver código fonte

fixed focused + !visible element getting all events until blurred

ncannasse 8 anos atrás
pai
commit
efab469abf
3 arquivos alterados com 28 adições e 6 exclusões
  1. 9 0
      h2d/Scene.hx
  2. 9 0
      h3d/scene/Scene.hx
  3. 10 6
      hxd/SceneEvents.hx

+ 9 - 0
h2d/Scene.hx

@@ -102,6 +102,15 @@ class Scene extends Layers implements h3d.IDrawable implements hxd.SceneEvents.I
 		}
 	}
 
+	public function isInteractiveVisible( i : hxd.SceneEvents.Interactive ) {
+		var s : Sprite = cast i;
+		while( s != null ) {
+			if( !s.visible ) return false;
+			s = s.parent;
+		}
+		return true;
+	}
+
 	public function getInteractive( x : Float, y : Float ) {
 		var rx = x * matA + y * matB + absX;
 		var ry = x * matC + y * matD + absY;

+ 9 - 0
h3d/scene/Scene.hx

@@ -71,6 +71,15 @@ class Scene extends Object implements h3d.IDrawable implements hxd.SceneEvents.I
 		i.handleEvent(event);
 	}
 
+	public function isInteractiveVisible( i : hxd.SceneEvents.Interactive ) {
+		var o : Object = cast i;
+		while( o != null ) {
+			if( !o.visible ) return false;
+			o = o.parent;
+		}
+		return true;
+	}
+
 	public function handleEvent( event : hxd.Event, last : hxd.SceneEvents.Interactive ) {
 
 		if( interactives.length == 0 )

+ 10 - 6
hxd/SceneEvents.hx

@@ -5,6 +5,7 @@ interface InteractiveScene {
 	public function handleEvent( e : Event, last : Interactive ) : Interactive;
 	public function dispatchEvent( e : Event, to : Interactive ) : Void;
 	public function dispatchListeners( e : Event ) : Void;
+	public function isInteractiveVisible( i : Interactive ) : Bool;
 }
 
 interface Interactive {
@@ -96,12 +97,15 @@ class SceneEvents {
 		case ERelease: checkPush = true;
 		case EKeyUp, EKeyDown, EWheel:
 			if( currentFocus != null ) {
-				event.relX = event.relY = 0;
-				currentFocus.handleEvent(event);
-				event.relX = oldX;
-				event.relY = oldY;
-				if( !event.propagate )
-					return;
+				var s = currentFocus.getInteractiveScene();
+				if( s != null && s.isInteractiveVisible(currentFocus) ) {
+					event.relX = event.relY = 0;
+					currentFocus.handleEvent(event);
+					event.relX = oldX;
+					event.relY = oldY;
+					if( !event.propagate )
+						return;
+				}
 			}
 		default:
 		}