Sfoglia il codice sorgente

fixes for multiples scenes handling same event (keep relX/relY)

ncannasse 11 anni fa
parent
commit
a0c9a61f8d
1 ha cambiato i file con 16 aggiunte e 16 eliminazioni
  1. 16 16
      h2d/Scene.hx

+ 16 - 16
h2d/Scene.hx

@@ -75,11 +75,8 @@ class Scene extends Layers implements h3d.IDrawable {
 	}
 	}
 
 
 	function onEvent( e : hxd.Event ) {
 	function onEvent( e : hxd.Event ) {
-		if( pendingEvents != null ) {
-			e.relX = screenXToLocal(e.relX);
-			e.relY = screenYToLocal(e.relY);
+		if( pendingEvents != null )
 			pendingEvents.push(e);
 			pendingEvents.push(e);
-		}
 	}
 	}
 
 
 	function screenXToLocal(mx:Float) {
 	function screenXToLocal(mx:Float) {
@@ -245,41 +242,44 @@ class Scene extends Layers implements h3d.IDrawable {
 		if( old.length == 0 )
 		if( old.length == 0 )
 			return;
 			return;
 		pendingEvents = null;
 		pendingEvents = null;
-		var ox = 0., oy = 0.;
 		for( e in old ) {
 		for( e in old ) {
-			var hasPos = switch( e.kind ) {
-			case EKeyUp, EKeyDown: false;
-			default: true;
-			}
-
-			if( hasPos ) {
-				ox = e.relX;
-				oy = e.relY;
-			}
+			var ox = e.relX, oy = e.relY;
+			e.relX = screenXToLocal(ox);
+			e.relY = screenYToLocal(oy);
 
 
 			if( currentDrag != null && (currentDrag.ref == null || currentDrag.ref == e.touchId) ) {
 			if( currentDrag != null && (currentDrag.ref == null || currentDrag.ref == e.touchId) ) {
 				currentDrag.f(e);
 				currentDrag.f(e);
-				if( e.cancel )
+				if( e.cancel ) {
+					e.relX = ox;
+					e.relY = oy;
 					continue;
 					continue;
+				}
 			}
 			}
+
 			emitEvent(e);
 			emitEvent(e);
+
 			/*
 			/*
 				We want to make sure that after we have pushed, we send a release even if the mouse
 				We want to make sure that after we have pushed, we send a release even if the mouse
 				has been outside of the Interactive (release outside). We will reset the mouse button
 				has been outside of the Interactive (release outside). We will reset the mouse button
 				to prevent click to be generated
 				to prevent click to be generated
 			*/
 			*/
 			if( e.kind == ERelease && pushList.length > 0 ) {
 			if( e.kind == ERelease && pushList.length > 0 ) {
+				e.relX = screenXToLocal(ox);
+				e.relY = screenYToLocal(oy);
 				for( i in pushList ) {
 				for( i in pushList ) {
-					// relX/relY is not correct here
 					if( i == null )
 					if( i == null )
 						dispatchListeners(e);
 						dispatchListeners(e);
 					else {
 					else {
 						@:privateAccess i.isMouseDown = -1;
 						@:privateAccess i.isMouseDown = -1;
+						// relX/relY not good here
 						i.handleEvent(e);
 						i.handleEvent(e);
 					}
 					}
 				}
 				}
 				pushList = new Array();
 				pushList = new Array();
 			}
 			}
+
+			e.relX = ox;
+			e.relY = oy;
 		}
 		}
 		if( hasEvents() )
 		if( hasEvents() )
 			pendingEvents = new Array();
 			pendingEvents = new Array();