|
@@ -5,25 +5,27 @@ class Scene extends Layers implements h3d.IDrawable {
|
|
|
|
|
|
public var width(default,null) : Int;
|
|
public var width(default,null) : Int;
|
|
public var height(default, null) : Int;
|
|
public var height(default, null) : Int;
|
|
-
|
|
|
|
|
|
+
|
|
public var mouseX(get, null) : Float;
|
|
public var mouseX(get, null) : Float;
|
|
public var mouseY(get, null) : Float;
|
|
public var mouseY(get, null) : Float;
|
|
-
|
|
|
|
|
|
+
|
|
|
|
+ public var zoom(get, set) : Int;
|
|
|
|
+
|
|
var fixedSize : Bool;
|
|
var fixedSize : Bool;
|
|
var interactive : Array<Interactive>;
|
|
var interactive : Array<Interactive>;
|
|
var pendingEvents : Array<hxd.Event>;
|
|
var pendingEvents : Array<hxd.Event>;
|
|
var ctx : RenderContext;
|
|
var ctx : RenderContext;
|
|
var stage : hxd.Stage;
|
|
var stage : hxd.Stage;
|
|
-
|
|
|
|
|
|
+
|
|
@:allow(h2d.Interactive)
|
|
@:allow(h2d.Interactive)
|
|
var currentOver : Interactive;
|
|
var currentOver : Interactive;
|
|
@:allow(h2d.Interactive)
|
|
@:allow(h2d.Interactive)
|
|
var currentFocus : Interactive;
|
|
var currentFocus : Interactive;
|
|
-
|
|
|
|
|
|
+
|
|
var pushList : Array<Interactive>;
|
|
var pushList : Array<Interactive>;
|
|
var currentDrag : { f : hxd.Event -> Void, onCancel : Void -> Void, ref : Null<Int> };
|
|
var currentDrag : { f : hxd.Event -> Void, onCancel : Void -> Void, ref : Null<Int> };
|
|
var eventListeners : Array< hxd.Event -> Void >;
|
|
var eventListeners : Array< hxd.Event -> Void >;
|
|
-
|
|
|
|
|
|
+
|
|
public function new() {
|
|
public function new() {
|
|
super(null);
|
|
super(null);
|
|
var e = h3d.Engine.getCurrent();
|
|
var e = h3d.Engine.getCurrent();
|
|
@@ -36,7 +38,25 @@ class Scene extends Layers implements h3d.IDrawable {
|
|
stage = hxd.Stage.getInstance();
|
|
stage = hxd.Stage.getInstance();
|
|
posChanged = true;
|
|
posChanged = true;
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
|
|
+ function get_zoom() {
|
|
|
|
+ return Std.int(h3d.Engine.getCurrent().width / width);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ function set_zoom(v:Int) {
|
|
|
|
+ var e = h3d.Engine.getCurrent();
|
|
|
|
+ var stage = hxd.Stage.getInstance();
|
|
|
|
+ var twidth = Math.ceil(stage.width / v);
|
|
|
|
+ var theight = Math.ceil(stage.height / v);
|
|
|
|
+ var totalWidth = twidth * v;
|
|
|
|
+ var totalHeight = theight * v;
|
|
|
|
+ // increase back buffer size if necessary
|
|
|
|
+ if( totalWidth != e.width || totalHeight != e.height )
|
|
|
|
+ e.resize(totalWidth, totalHeight);
|
|
|
|
+ setFixedSize(twidth, theight);
|
|
|
|
+ return v;
|
|
|
|
+ }
|
|
|
|
+
|
|
public function setFixedSize( w, h ) {
|
|
public function setFixedSize( w, h ) {
|
|
width = w;
|
|
width = w;
|
|
height = h;
|
|
height = h;
|
|
@@ -48,12 +68,12 @@ class Scene extends Layers implements h3d.IDrawable {
|
|
stage.addEventTarget(onEvent);
|
|
stage.addEventTarget(onEvent);
|
|
super.onAlloc();
|
|
super.onAlloc();
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
override function onDelete() {
|
|
override function onDelete() {
|
|
stage.removeEventTarget(onEvent);
|
|
stage.removeEventTarget(onEvent);
|
|
super.onDelete();
|
|
super.onDelete();
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
function onEvent( e : hxd.Event ) {
|
|
function onEvent( e : hxd.Event ) {
|
|
if( pendingEvents != null ) {
|
|
if( pendingEvents != null ) {
|
|
e.relX = screenXToLocal(e.relX);
|
|
e.relX = screenXToLocal(e.relX);
|
|
@@ -61,7 +81,7 @@ class Scene extends Layers implements h3d.IDrawable {
|
|
pendingEvents.push(e);
|
|
pendingEvents.push(e);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
function screenXToLocal(mx:Float) {
|
|
function screenXToLocal(mx:Float) {
|
|
return (mx - x) * width / (stage.width * scaleX);
|
|
return (mx - x) * width / (stage.width * scaleX);
|
|
}
|
|
}
|
|
@@ -69,7 +89,7 @@ class Scene extends Layers implements h3d.IDrawable {
|
|
function screenYToLocal(my:Float) {
|
|
function screenYToLocal(my:Float) {
|
|
return (my - y) * height / (stage.height * scaleY);
|
|
return (my - y) * height / (stage.height * scaleY);
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
function get_mouseX() {
|
|
function get_mouseX() {
|
|
return screenXToLocal(stage.mouseX);
|
|
return screenXToLocal(stage.mouseX);
|
|
}
|
|
}
|
|
@@ -77,7 +97,7 @@ class Scene extends Layers implements h3d.IDrawable {
|
|
function get_mouseY() {
|
|
function get_mouseY() {
|
|
return screenYToLocal(stage.mouseY);
|
|
return screenYToLocal(stage.mouseY);
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
function dispatchListeners( event : hxd.Event ) {
|
|
function dispatchListeners( event : hxd.Event ) {
|
|
event.propagate = true;
|
|
event.propagate = true;
|
|
event.cancel = false;
|
|
event.cancel = false;
|
|
@@ -107,27 +127,27 @@ class Scene extends Layers implements h3d.IDrawable {
|
|
default:
|
|
default:
|
|
}
|
|
}
|
|
for( i in interactive ) {
|
|
for( i in interactive ) {
|
|
-
|
|
|
|
|
|
+
|
|
// this is a bit tricky since we are not in the not-euclide viewport space
|
|
// this is a bit tricky since we are not in the not-euclide viewport space
|
|
// (r = ratio correction)
|
|
// (r = ratio correction)
|
|
var dx = rx - i.absX;
|
|
var dx = rx - i.absX;
|
|
var dy = ry - i.absY;
|
|
var dy = ry - i.absY;
|
|
-
|
|
|
|
|
|
+
|
|
var w1 = i.width * i.matA * r;
|
|
var w1 = i.width * i.matA * r;
|
|
var h1 = i.width * i.matC;
|
|
var h1 = i.width * i.matC;
|
|
var ky = h1 * dx - w1 * dy;
|
|
var ky = h1 * dx - w1 * dy;
|
|
// up line
|
|
// up line
|
|
if( ky < 0 )
|
|
if( ky < 0 )
|
|
continue;
|
|
continue;
|
|
-
|
|
|
|
|
|
+
|
|
var w2 = i.height * i.matB * r;
|
|
var w2 = i.height * i.matB * r;
|
|
var h2 = i.height * i.matD;
|
|
var h2 = i.height * i.matD;
|
|
var kx = w2 * dy - h2 * dx;
|
|
var kx = w2 * dy - h2 * dx;
|
|
-
|
|
|
|
|
|
+
|
|
// left line
|
|
// left line
|
|
if( kx < 0 )
|
|
if( kx < 0 )
|
|
continue;
|
|
continue;
|
|
-
|
|
|
|
|
|
+
|
|
var max = h1 * w2 - w1 * h2;
|
|
var max = h1 * w2 - w1 * h2;
|
|
// bottom/right
|
|
// bottom/right
|
|
if( ky >= max || kx * r >= max )
|
|
if( ky >= max || kx * r >= max )
|
|
@@ -144,12 +164,12 @@ class Scene extends Layers implements h3d.IDrawable {
|
|
p = p.parent;
|
|
p = p.parent;
|
|
}
|
|
}
|
|
if( !visible ) continue;
|
|
if( !visible ) continue;
|
|
-
|
|
|
|
|
|
+
|
|
event.relX = (kx * r / max) * i.width;
|
|
event.relX = (kx * r / max) * i.width;
|
|
event.relY = (ky / max) * i.height;
|
|
event.relY = (ky / max) * i.height;
|
|
-
|
|
|
|
|
|
+
|
|
i.handleEvent(event);
|
|
i.handleEvent(event);
|
|
-
|
|
|
|
|
|
+
|
|
if( event.cancel )
|
|
if( event.cancel )
|
|
event.cancel = false;
|
|
event.cancel = false;
|
|
else if( checkOver ) {
|
|
else if( checkOver ) {
|
|
@@ -184,12 +204,12 @@ class Scene extends Layers implements h3d.IDrawable {
|
|
if( cancelFocus && i == currentFocus )
|
|
if( cancelFocus && i == currentFocus )
|
|
cancelFocus = false;
|
|
cancelFocus = false;
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
if( event.propagate ) {
|
|
if( event.propagate ) {
|
|
event.propagate = false;
|
|
event.propagate = false;
|
|
continue;
|
|
continue;
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
handled = true;
|
|
handled = true;
|
|
break;
|
|
break;
|
|
}
|
|
}
|
|
@@ -210,11 +230,11 @@ class Scene extends Layers implements h3d.IDrawable {
|
|
dispatchListeners(event);
|
|
dispatchListeners(event);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
function hasEvents() {
|
|
function hasEvents() {
|
|
return interactive.length > 0 || eventListeners.length > 0;
|
|
return interactive.length > 0 || eventListeners.length > 0;
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
public function checkEvents() {
|
|
public function checkEvents() {
|
|
if( pendingEvents == null ) {
|
|
if( pendingEvents == null ) {
|
|
if( !hasEvents() )
|
|
if( !hasEvents() )
|
|
@@ -231,12 +251,12 @@ class Scene extends Layers implements h3d.IDrawable {
|
|
case EKeyUp, EKeyDown: false;
|
|
case EKeyUp, EKeyDown: false;
|
|
default: true;
|
|
default: true;
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
if( hasPos ) {
|
|
if( hasPos ) {
|
|
ox = e.relX;
|
|
ox = e.relX;
|
|
oy = e.relY;
|
|
oy = e.relY;
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
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 )
|
|
@@ -264,7 +284,7 @@ class Scene extends Layers implements h3d.IDrawable {
|
|
if( hasEvents() )
|
|
if( hasEvents() )
|
|
pendingEvents = new Array();
|
|
pendingEvents = new Array();
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
public function addEventListener( f : hxd.Event -> Void ) {
|
|
public function addEventListener( f : hxd.Event -> Void ) {
|
|
eventListeners.push(f);
|
|
eventListeners.push(f);
|
|
}
|
|
}
|
|
@@ -272,21 +292,21 @@ class Scene extends Layers implements h3d.IDrawable {
|
|
public function removeEventListener( f : hxd.Event -> Void ) {
|
|
public function removeEventListener( f : hxd.Event -> Void ) {
|
|
return eventListeners.remove(f);
|
|
return eventListeners.remove(f);
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
public function startDrag( f : hxd.Event -> Void, ?onCancel : Void -> Void, ?refEvent : hxd.Event ) {
|
|
public function startDrag( f : hxd.Event -> Void, ?onCancel : Void -> Void, ?refEvent : hxd.Event ) {
|
|
if( currentDrag != null && currentDrag.onCancel != null )
|
|
if( currentDrag != null && currentDrag.onCancel != null )
|
|
currentDrag.onCancel();
|
|
currentDrag.onCancel();
|
|
currentDrag = { f : f, ref : refEvent == null ? null : refEvent.touchId, onCancel : onCancel };
|
|
currentDrag = { f : f, ref : refEvent == null ? null : refEvent.touchId, onCancel : onCancel };
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
public function stopDrag() {
|
|
public function stopDrag() {
|
|
currentDrag = null;
|
|
currentDrag = null;
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
public function getFocus() {
|
|
public function getFocus() {
|
|
return currentFocus;
|
|
return currentFocus;
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
@:allow(h2d)
|
|
@:allow(h2d)
|
|
function addEventTarget(i:Interactive) {
|
|
function addEventTarget(i:Interactive) {
|
|
// sort by which is over the other in the scene hierarchy
|
|
// sort by which is over the other in the scene hierarchy
|
|
@@ -338,7 +358,7 @@ class Scene extends Layers implements h3d.IDrawable {
|
|
}
|
|
}
|
|
interactive.push(i);
|
|
interactive.push(i);
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
@:allow(h2d)
|
|
@:allow(h2d)
|
|
function removeEventTarget(i) {
|
|
function removeEventTarget(i) {
|
|
for( k in 0...interactive.length )
|
|
for( k in 0...interactive.length )
|
|
@@ -356,7 +376,7 @@ class Scene extends Layers implements h3d.IDrawable {
|
|
matD = scaleY;
|
|
matD = scaleY;
|
|
absX = x;
|
|
absX = x;
|
|
absY = y;
|
|
absY = y;
|
|
-
|
|
|
|
|
|
+
|
|
// adds a pixels-to-viewport transform
|
|
// adds a pixels-to-viewport transform
|
|
var w = 2 / width;
|
|
var w = 2 / width;
|
|
var h = -2 / height;
|
|
var h = -2 / height;
|
|
@@ -366,7 +386,7 @@ class Scene extends Layers implements h3d.IDrawable {
|
|
matB *= h;
|
|
matB *= h;
|
|
matC *= w;
|
|
matC *= w;
|
|
matD *= h;
|
|
matD *= h;
|
|
-
|
|
|
|
|
|
+
|
|
// perform final rotation around center
|
|
// perform final rotation around center
|
|
if( rotation != 0 ) {
|
|
if( rotation != 0 ) {
|
|
var cr = Math.cos(rotation);
|
|
var cr = Math.cos(rotation);
|
|
@@ -385,16 +405,16 @@ class Scene extends Layers implements h3d.IDrawable {
|
|
absY = tmpY;
|
|
absY = tmpY;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
public function dispose() {
|
|
public function dispose() {
|
|
if( allocated )
|
|
if( allocated )
|
|
onDelete();
|
|
onDelete();
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
public function setElapsedTime( v : Float ) {
|
|
public function setElapsedTime( v : Float ) {
|
|
ctx.elapsedTime = v;
|
|
ctx.elapsedTime = v;
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
public function render( engine : h3d.Engine ) {
|
|
public function render( engine : h3d.Engine ) {
|
|
ctx.engine = engine;
|
|
ctx.engine = engine;
|
|
ctx.frame++;
|
|
ctx.frame++;
|
|
@@ -403,7 +423,7 @@ class Scene extends Layers implements h3d.IDrawable {
|
|
sync(ctx);
|
|
sync(ctx);
|
|
drawRec(ctx);
|
|
drawRec(ctx);
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
override function sync( ctx : RenderContext ) {
|
|
override function sync( ctx : RenderContext ) {
|
|
if( !allocated )
|
|
if( !allocated )
|
|
onAlloc();
|
|
onAlloc();
|
|
@@ -415,7 +435,7 @@ class Scene extends Layers implements h3d.IDrawable {
|
|
Tools.checkCoreObjects();
|
|
Tools.checkCoreObjects();
|
|
super.sync(ctx);
|
|
super.sync(ctx);
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
public function captureBitmap( ?target : Tile ) {
|
|
public function captureBitmap( ?target : Tile ) {
|
|
var engine = h3d.Engine.getCurrent();
|
|
var engine = h3d.Engine.getCurrent();
|
|
if( target == null ) {
|
|
if( target == null ) {
|
|
@@ -438,6 +458,6 @@ class Scene extends Layers implements h3d.IDrawable {
|
|
engine.end();
|
|
engine.end();
|
|
return new Bitmap(target);
|
|
return new Bitmap(target);
|
|
}
|
|
}
|
|
-
|
|
|
|
-
|
|
|
|
|
|
+
|
|
|
|
+
|
|
}
|
|
}
|