Jelajahi Sumber

Rename startDrag to startCapture (#874)

Pavel Alexandrov 4 tahun lalu
induk
melakukan
d0edc184f9
6 mengubah file dengan 55 tambahan dan 25 penghapusan
  1. 19 9
      h2d/Interactive.hx
  2. 15 5
      h2d/Scene.hx
  3. 2 2
      h2d/Slider.hx
  4. 2 2
      h2d/TextInput.hx
  5. 2 2
      h3d/scene/CameraController.hx
  6. 15 5
      hxd/SceneEvents.hx

+ 19 - 9
h2d/Interactive.hx

@@ -249,33 +249,43 @@ class Interactive extends Drawable implements hxd.SceneEvents.Interactive {
 	}
 
 	/**
-		Starts input events capture and redirects them to `callb` method until `Interactive.stopDrag` is called.
+		Starts input events capture and redirects them to `callb` method until `Interactive.stopCapture` is called.
 		While the method name may imply that only mouse events would be captured: This is not the case,
 		as it will also capture all other input events, including keyboard events.
 
-		Starting event capture through `Interactive.startDrag` will convert `Event.relX` and `relY` to local coordinates
+		Starting event capture through `Interactive.startCapture` will convert `Event.relX` and `relY` to local coordinates
 		of the Interactive and will restore them after invoking `callb`.
-		In order to receive coordinates in scene coordinate space use `Scene.startDrag`.
+		In order to receive coordinates in scene coordinate space use `Scene.startCapture`.
 
 		@param callb A callback method that receives `hxd.Event` when input event happens.
 		Unless `callb` sets `Event.propagate` to `true`, event won't be sent to other Interactives.
-		@param onCancel An optional callback that is invoked when `Interactive.stopDrag` is called.
+		@param onCancel An optional callback that is invoked when `Interactive.stopCapture` is called.
 	**/
-	public function startDrag( callb : hxd.Event -> Void,?onCancel : Void -> Void ) {
-		scene.startDrag(function(event) {
+	public function startCapture(callb : hxd.Event -> Void, ?onCancel : Void -> Void, ?touchId : Int) {
+		scene.startCapture(function(event) {
 			var x = event.relX, y = event.relY;
 			eventToLocal(event);
 			callb(event);
 			event.relX = x;
 			event.relY = y;
-		},onCancel);
+		}, onCancel, touchId);
 	}
 
 	/**
 		Stops current input event capture.
 	**/
-	public function stopDrag() {
-		scene.stopDrag();
+	public function stopCapture() {
+		scene.stopCapture();
+	}
+
+	@:deprecated("Renamed to startCapture") @:dox(hide)
+	public inline function startDrag(callb,?onCancel) {
+		startCapture(callb, onCancel);
+	}
+
+	@:deprecated("Renamed to stopCapture") @:dox(hide)
+	public inline function stopDrag() {
+		stopCapture();
 	}
 
 	/**

+ 15 - 5
h2d/Scene.hx

@@ -609,18 +609,28 @@ class Scene extends Layers implements h3d.IDrawable implements hxd.SceneEvents.I
 		@param onCancel An optional callback that is invoked when `Scene.stopDrag` is called.
 		@param refEvent For touch events, when defined, only capture events that match the reference `Event.touchId`.
 	**/
-	public function startDrag( onEvent : hxd.Event -> Void, ?onCancel : Void -> Void, ?refEvent : hxd.Event ) {
-		events.startDrag(function(e) {
+	public function startCapture( onEvent : hxd.Event -> Void, ?onCancel : Void -> Void, ?touchId : Int ) {
+		events.startCapture(function(e) {
 			screenToViewport(e);
 			onEvent(e);
-		},onCancel, refEvent);
+		},onCancel, touchId);
 	}
 
 	/**
 		Stops current input event capture.
 	**/
-	public function stopDrag() {
-		events.stopDrag();
+	public function stopCapture() {
+		events.stopCapture();
+	}
+
+	@:deprecated("Renamed to startCapture") @:dox(hide)
+	public inline function startDrag( onEvent : hxd.Event -> Void, ?onCancel : Void -> Void, ?refEvent : hxd.Event ) {
+		startCapture(onEvent, onCancel, refEvent != null ? refEvent.touchId : null);
+	}
+
+	@:deprecated("Renamed to stopCapture") @:dox(hide)
+	public inline function stopDrag() {
+		stopCapture();
 	}
 
 	/**

+ 2 - 2
h2d/Slider.hx

@@ -108,9 +108,9 @@ class Slider extends h2d.Interactive {
 
 			onChange();
 			var scene = scene;
-			startDrag(function(e) {
+			startCapture(function(e) {
 				if( this.scene != scene || e.kind == ERelease ) {
-					scene.stopDrag();
+					scene.stopCapture();
 					return;
 				}
 				value = getValue(e.relX);

+ 2 - 2
h2d/TextInput.hx

@@ -88,7 +88,7 @@ class TextInput extends Text {
 
 				var pt = new h2d.col.Point();
 				var scene = getScene();
-				scene.startDrag(function(e) {
+				scene.startCapture(function(e) {
 					pt.x = e.relX;
 					pt.y = e.relY;
 					globalToLocal(pt);
@@ -102,7 +102,7 @@ class TextInput extends Text {
 					selectionSize = 0;
 					cursorIndex = index;
 					if( e.kind == ERelease || getScene() != scene )
-						scene.stopDrag();
+						scene.stopCapture();
 				});
 			}
 		};

+ 2 - 2
h3d/scene/CameraController.hx

@@ -153,7 +153,7 @@ class CameraController extends h3d.scene.Object {
 			else
 				zoom(e.wheelDelta);
 		case EPush:
-			@:privateAccess scene.events.startDrag(onEvent, function() pushing = -1, e);
+			@:privateAccess scene.events.startCapture(onEvent, function() pushing = -1, e.touchId);
 			pushing = e.button;
 			pushTime = haxe.Timer.stamp();
 			pushStartX = pushX = e.relX;
@@ -161,7 +161,7 @@ class CameraController extends h3d.scene.Object {
 		case ERelease, EReleaseOutside:
 			if( pushing == e.button ) {
 				pushing = -1;
-				@:privateAccess scene.events.stopDrag();
+				@:privateAccess scene.events.stopCapture();
 				if( e.kind == ERelease && haxe.Timer.stamp() - pushTime < 0.2 && hxd.Math.distance(e.relX - pushStartX,e.relY - pushStartY) < 5 )
 					onClick(e);
 			}

+ 15 - 5
hxd/SceneEvents.hx

@@ -379,18 +379,28 @@ class SceneEvents {
 		}
 	}
 
-	public function startDrag( f : hxd.Event -> Void, ?onCancel : Void -> Void, ?refEvent : hxd.Event ) {
-		if( currentDrag != null && currentDrag.onCancel != null )
+	public function startCapture( f : hxd.Event -> Void, ?onCancel : Void -> Void, ?touchId : Int ) {
+		if ( currentDrag != null && currentDrag.onCancel != null )
 			currentDrag.onCancel();
-		currentDrag = { f : f, ref : refEvent == null ? null : refEvent.touchId, onCancel : onCancel };
+		currentDrag = { f: f, ref: touchId, onCancel: onCancel };
 	}
 
-	public function stopDrag() {
-		if( currentDrag != null && currentDrag.onCancel != null )
+	public function stopCapture() {
+		if ( currentDrag != null && currentDrag.onCancel != null )
 			currentDrag.onCancel();
 		currentDrag = null;
 	}
 
+	@:deprecated("Renamed to startCapture") @:dox(hide)
+	public inline function startDrag( f : hxd.Event -> Void, ?onCancel : Void -> Void, ?refEvent : hxd.Event ) {
+		startCapture(f, onCancel, refEvent != null ? refEvent.touchId : null);
+	}
+
+	@:deprecated("Renamed to stopCapture") @:dox(hide)
+	public inline function stopDrag() {
+		stopCapture();
+	}
+
 	public function getFocus() {
 		return currentFocus;
 	}