|
@@ -1,10 +1,23 @@
|
|
package h2d;
|
|
package h2d;
|
|
|
|
|
|
|
|
+@:allow(h2d.Scene)
|
|
class Interactive extends Drawable implements hxd.SceneEvents.Interactive {
|
|
class Interactive extends Drawable implements hxd.SceneEvents.Interactive {
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ Width of the Interactive. Ignored if `shape` is set.
|
|
|
|
+ **/
|
|
public var width : Float;
|
|
public var width : Float;
|
|
|
|
+ /**
|
|
|
|
+ Height of the Interactive. Ignored if `shape` is set.
|
|
|
|
+ **/
|
|
public var height : Float;
|
|
public var height : Float;
|
|
|
|
+ /**
|
|
|
|
+ Cursor used when Interactive is under mouse cursor ( default : Button )
|
|
|
|
+ **/
|
|
public var cursor(default,set) : hxd.Cursor;
|
|
public var cursor(default,set) : hxd.Cursor;
|
|
|
|
+ /**
|
|
|
|
+ Should object collision be in rectangle or ellipse form? Ignored if `shape` is set.
|
|
|
|
+ **/
|
|
public var isEllipse : Bool;
|
|
public var isEllipse : Bool;
|
|
/**
|
|
/**
|
|
Set the default `cancel` mode (see `hxd.Event`), default to false.
|
|
Set the default `cancel` mode (see `hxd.Event`), default to false.
|
|
@@ -19,10 +32,11 @@ class Interactive extends Drawable implements hxd.SceneEvents.Interactive {
|
|
var scene : Scene;
|
|
var scene : Scene;
|
|
var mouseDownButton : Int = -1;
|
|
var mouseDownButton : Int = -1;
|
|
var parentMask : Mask;
|
|
var parentMask : Mask;
|
|
|
|
+ var invDet : Float;
|
|
|
|
|
|
/**
|
|
/**
|
|
Detailed shape collider for Interactive.
|
|
Detailed shape collider for Interactive.
|
|
- Keep in mind that shape parts that are out of [0, 0, width, height] bounds will never interact with the mouse.
|
|
|
|
|
|
+ If set, `width` and `height` properties are ignored for collision checks.
|
|
**/
|
|
**/
|
|
public var shape : h2d.col.Collider;
|
|
public var shape : h2d.col.Collider;
|
|
/**
|
|
/**
|
|
@@ -123,7 +137,7 @@ class Interactive extends Drawable implements hxd.SceneEvents.Interactive {
|
|
p = @:privateAccess p.parentMask;
|
|
p = @:privateAccess p.parentMask;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- if( isEllipse && checkBounds(e) ) {
|
|
|
|
|
|
+ if(shape == null && isEllipse && checkBounds(e) ) {
|
|
var cx = width * 0.5, cy = height * 0.5;
|
|
var cx = width * 0.5, cy = height * 0.5;
|
|
var dx = (e.relX - cx) / cx;
|
|
var dx = (e.relX - cx) / cx;
|
|
var dy = (e.relY - cy) / cy;
|
|
var dy = (e.relY - cy) / cy;
|
|
@@ -182,6 +196,12 @@ class Interactive extends Drawable implements hxd.SceneEvents.Interactive {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ override private function calcAbsPos()
|
|
|
|
+ {
|
|
|
|
+ super.calcAbsPos();
|
|
|
|
+ invDet = 1 / (matA * matD - matB * matC);
|
|
|
|
+ }
|
|
|
|
+
|
|
function set_cursor(c) {
|
|
function set_cursor(c) {
|
|
this.cursor = c;
|
|
this.cursor = c;
|
|
if( isOver() && cursor != null )
|
|
if( isOver() && cursor != null )
|
|
@@ -191,25 +211,13 @@ class Interactive extends Drawable implements hxd.SceneEvents.Interactive {
|
|
|
|
|
|
function eventToLocal( e : hxd.Event ) {
|
|
function eventToLocal( e : hxd.Event ) {
|
|
// convert scene event to our local space
|
|
// convert scene event to our local space
|
|
- var rx = e.relX, ry = e.relY;
|
|
|
|
-
|
|
|
|
var i = this;
|
|
var i = this;
|
|
|
|
|
|
- var dx = rx - i.absX;
|
|
|
|
- var dy = ry - i.absY;
|
|
|
|
-
|
|
|
|
- var w1 = i.width * i.matA;
|
|
|
|
- var h1 = i.width * i.matC;
|
|
|
|
- var ky = h1 * dx - w1 * dy;
|
|
|
|
-
|
|
|
|
- var w2 = i.height * i.matB;
|
|
|
|
- var h2 = i.height * i.matD;
|
|
|
|
- var kx = w2 * dy - h2 * dx;
|
|
|
|
-
|
|
|
|
- var max = h1 * w2 - w1 * h2;
|
|
|
|
|
|
+ var dx = e.relX - i.absX;
|
|
|
|
+ var dy = e.relY - i.absY;
|
|
|
|
|
|
- e.relX = (kx / max) * i.width;
|
|
|
|
- e.relY = (ky / max) * i.height;
|
|
|
|
|
|
+ e.relX = ( dx * i.matD - dy * i.matC) * i.invDet;
|
|
|
|
+ e.relY = (-dx * i.matB + dy * i.matA) * i.invDet;
|
|
}
|
|
}
|
|
|
|
|
|
public function startDrag(callb,?onCancel) {
|
|
public function startDrag(callb,?onCancel) {
|