Bladeren bron

Stage -> Window

ncannasse 6 jaren geleden
bovenliggende
commit
d683d8edd4
18 gewijzigde bestanden met toevoegingen van 184 en 174 verwijderingen
  1. 5 0
      h2d/CdbLevel.hx
  2. 2 2
      h2d/Console.hx
  3. 8 8
      h2d/Scene.hx
  4. 10 10
      h3d/Engine.hx
  5. 1 1
      h3d/impl/Benchmark.hx
  6. 2 2
      h3d/impl/GlDriver.hx
  7. 4 4
      h3d/scene/Scene.hx
  8. 5 5
      h3d/scene/pbr/Renderer.hx
  9. 2 2
      hxd/Key.hx
  10. 6 6
      hxd/SceneEvents.hx
  11. 3 103
      hxd/Stage.hx
  12. 9 9
      hxd/System.hl.hx
  13. 6 6
      hxd/System.js.hx
  14. 4 4
      hxd/Window.flash.hx
  15. 3 3
      hxd/Window.hl.hx
  16. 105 0
      hxd/Window.hx
  17. 4 4
      hxd/Window.js.hx
  18. 5 5
      hxd/inspect/ScenePanel.hx

+ 5 - 0
h2d/CdbLevel.hx

@@ -296,6 +296,11 @@ class CdbLevel extends Layers {
 		return collide;
 	}
 
+	override function getBoundsRec(relativeTo:Object, out:h2d.col.Bounds, forSize:Bool) {
+		redraw();
+		super.getBoundsRec(relativeTo, out, forSize);
+	}
+
 	public function buildStringProperty( name : String ) {
 		var collide = null;
 		for( l in layers ) {

+ 2 - 2
h2d/Console.hx

@@ -76,11 +76,11 @@ class Console extends h2d.Object {
 
 	override function onAdd() {
 		super.onAdd();
-		@:privateAccess getScene().stage.addEventTarget(onEvent);
+		@:privateAccess getScene().window.addEventTarget(onEvent);
 	}
 
 	override function onRemove() {
-		@:privateAccess getScene().stage.removeEventTarget(onEvent);
+		@:privateAccess getScene().window.removeEventTarget(onEvent);
 		super.onRemove();
 	}
 

+ 8 - 8
h2d/Scene.hx

@@ -46,7 +46,7 @@ class Scene extends Layers implements h3d.IDrawable implements hxd.SceneEvents.I
 	var interactive : Array<Interactive>;
 	var eventListeners : Array< hxd.Event -> Void >;
 	var ctx : RenderContext;
-	var stage : hxd.Stage;
+	var window : hxd.Window;
 	@:allow(h2d.Interactive)
 	var events : hxd.SceneEvents;
 
@@ -61,7 +61,7 @@ class Scene extends Layers implements h3d.IDrawable implements hxd.SceneEvents.I
 		height = e.height;
 		interactive = new Array();
 		eventListeners = new Array();
-		stage = hxd.Stage.getInstance();
+		window = hxd.Window.getInstance();
 		posChanged = true;
 	}
 
@@ -79,8 +79,8 @@ class Scene extends Layers implements h3d.IDrawable implements hxd.SceneEvents.I
 
 	function set_zoom(v:Int) {
 		var e = h3d.Engine.getCurrent();
-		var twidth = Math.ceil(stage.width / v);
-		var theight = Math.ceil(stage.height / v);
+		var twidth = Math.ceil(window.width / v);
+		var theight = Math.ceil(window.height / v);
 		var totalWidth = twidth * v;
 		var totalHeight = theight * v;
 		// increase back buffer size if necessary
@@ -115,19 +115,19 @@ class Scene extends Layers implements h3d.IDrawable implements hxd.SceneEvents.I
 	}
 
 	inline function screenXToLocal(mx:Float) {
-		return mx * width / (stage.width * scaleX) - x;
+		return mx * width / (window.width * scaleX) - x;
 	}
 
 	inline function screenYToLocal(my:Float) {
-		return my * height / (stage.height * scaleY) - y;
+		return my * height / (window.height * scaleY) - y;
 	}
 
 	function get_mouseX() {
-		return screenXToLocal(stage.mouseX);
+		return screenXToLocal(window.mouseX);
 	}
 
 	function get_mouseY() {
-		return screenYToLocal(stage.mouseY);
+		return screenYToLocal(window.mouseY);
 	}
 
 	@:dox(hide) @:noCompletion

+ 10 - 10
h3d/Engine.hx

@@ -40,7 +40,7 @@ class Engine {
 	var lastTime : Float;
 	var antiAlias : Int;
 	var tmpVector = new h3d.Vector();
-	var stage : hxd.Stage;
+	var window : hxd.Window;
 
 	var targetTmp : TargetTmp;
 	var targetStack : TargetTmp;
@@ -53,16 +53,16 @@ class Engine {
 	public var ready(default,null) = false;
 	@:allow(hxd.res) var resCache = new Map<{},Dynamic>();
 
-	@:access(hxd.Stage)
+	@:access(hxd.Window)
 	public function new( hardware = true, aa = 0 ) {
 		this.hardware = hardware;
 		this.antiAlias = aa;
 		this.autoResize = true;
 		fullScreen = !hxd.System.getValue(IsWindowed);
-		stage = hxd.Stage.getInstance();
+		window = hxd.Window.getInstance();
 		realFps = hxd.System.getDefaultFrameRate();
 		lastTime = haxe.Timer.stamp();
-		stage.addResizeEvent(onStageResize);
+		window.addResizeEvent(onWindowResize);
 		#if (js || cpp || hlsdl || usegl)
 		driver = new h3d.impl.GlDriver(antiAlias);
 		#elseif flash
@@ -220,8 +220,8 @@ class Engine {
 	function onCreate( disposed ) {
 		setCurrent();
 		if( autoResize ) {
-			width = stage.width;
-			height = stage.height;
+			width = window.width;
+			height = window.height;
 		}
 		if( disposed )
 			mem.onContextLost();
@@ -246,9 +246,9 @@ class Engine {
 	public dynamic function onReady() {
 	}
 
-	function onStageResize() {
+	function onWindowResize() {
 		if( autoResize && !driver.isDisposed() ) {
-			var w = stage.width, h = stage.height;
+			var w = window.width, h = window.height;
 			if( w != width || h != height )
 				resize(w, h);
 			onResized();
@@ -258,7 +258,7 @@ class Engine {
 	function set_fullScreen(v) {
 		fullScreen = v;
 		if( mem != null && hxd.System.getValue(IsWindowed) )
-			stage.setFullScreen(v);
+			window.setFullScreen(v);
 		return v;
 	}
 
@@ -400,7 +400,7 @@ class Engine {
 
 	public function dispose() {
 		driver.dispose();
-		stage.removeResizeEvent(onStageResize);
+		window.removeResizeEvent(onWindowResize);
 	}
 
 	function get_fps() {

+ 1 - 1
h3d/impl/Benchmark.hx

@@ -215,7 +215,7 @@ class Benchmark extends h2d.Graphics {
 			if( estimateWait ) {
 				var waitT = frameTime - totalTime;
 				if( waitT > 0 ) {
-					if( hxd.Stage.getInstance().vsync ) {
+					if( hxd.Window.getInstance().vsync ) {
 						var vst = 1e9 / hxd.System.getDefaultFrameRate() - totalTime;
 						if( vst > waitT ) vst = waitT;
 						if( vst > 0 ) {

+ 2 - 2
h3d/impl/GlDriver.hx

@@ -189,7 +189,7 @@ class GlDriver extends Driver {
 
 	public function new(antiAlias=0) {
 		#if js
-		canvas = @:privateAccess hxd.Stage.getInstance().canvas;
+		canvas = @:privateAccess hxd.Window.getInstance().canvas;
 		var options = {alpha:false,stencil:true,antialias:antiAlias>0};
 		gl = cast canvas.getContext("webgl2",options);
 		if( gl == null )
@@ -1309,7 +1309,7 @@ class GlDriver extends Driver {
 
 	override function present() {
 		#if hlsdl
-		@:privateAccess hxd.Stage.inst.window.present();
+		@:privateAccess hxd.Window.inst.window.present();
 		#elseif usesys
 		haxe.System.present();
 		#end

+ 4 - 4
h3d/scene/Scene.hx

@@ -26,14 +26,14 @@ class Scene extends Object implements h3d.IDrawable implements hxd.SceneEvents.I
 	var events : hxd.SceneEvents;
 	var hitInteractives : Array<Interactive>;
 	var eventListeners : Array<hxd.Event -> Void>;
-	var stage : hxd.Stage;
+	var window : hxd.Window;
 
 	/**
 		Create a new scene. A default 3D scene is already available in `hxd.App.s3d`
 	**/
 	public function new() {
 		super(null);
-		stage = hxd.Stage.getInstance();
+		window = hxd.Window.getInstance();
 		eventListeners = [];
 		hitInteractives = [];
 		interactives = [];
@@ -117,8 +117,8 @@ class Scene extends Object implements h3d.IDrawable implements hxd.SceneEvents.I
 
 		if( hitInteractives.length == 0 ) {
 
-			var screenX = (event.relX / stage.width - 0.5) * 2;
-			var screenY = -(event.relY / stage.height - 0.5) * 2;
+			var screenX = (event.relX / window.width - 0.5) * 2;
+			var screenY = -(event.relY / window.height - 0.5) * 2;
 			var p0 = camera.unproject(screenX, screenY, 0);
 			var p1 = camera.unproject(screenX, screenY, 1);
 			var r = h3d.col.Ray.fromPoints(p0.toPoint(), p1.toPoint());

+ 5 - 5
h3d/scene/pbr/Renderer.hx

@@ -319,22 +319,22 @@ class Renderer extends h3d.scene.Renderer {
 
 			if( !hasDebugEvent ) {
 				hasDebugEvent = true;
-				hxd.Stage.getInstance().addEventTarget(onEvent);
+				hxd.Window.getInstance().addEventTarget(onEvent);
 			}
 
 		}
 
 		if( hasDebugEvent && displayMode != Debug ) {
 			hasDebugEvent = false;
-			hxd.Stage.getInstance().removeEventTarget(onEvent);
+			hxd.Window.getInstance().removeEventTarget(onEvent);
 		}
 	}
 
 	function onEvent(e:hxd.Event) {
 		if( e.kind == EPush && e.button == 2 ) {
-			var st = hxd.Stage.getInstance();
-			var x = Std.int((e.relX / st.width) * 4);
-			var y = Std.int((e.relY / st.height) * 4);
+			var win = hxd.Window.getInstance();
+			var x = Std.int((e.relX / win.width) * 4);
+			var y = Std.int((e.relY / win.height) * 4);
 			if( slides.shader.mode != Full ) {
 				slides.shader.mode = Full;
 			} else {

+ 2 - 2
hxd/Key.hx

@@ -150,7 +150,7 @@ class Key {
 			dispose();
 		initDone = true;
 		keyPressed = [];
-		Stage.getInstance().addEventTarget(onEvent);
+		Window.getInstance().addEventTarget(onEvent);
 		#if flash
 		flash.Lib.current.stage.addEventListener(flash.events.Event.DEACTIVATE, onDeactivate);
 		#end
@@ -158,7 +158,7 @@ class Key {
 
 	public static function dispose() {
 		if( initDone ) {
-			Stage.getInstance().removeEventTarget(onEvent);
+			Window.getInstance().removeEventTarget(onEvent);
 			#if flash
 			flash.Lib.current.stage.removeEventListener(flash.events.Event.DEACTIVATE, onDeactivate);
 			#end

+ 6 - 6
hxd/SceneEvents.hx

@@ -15,7 +15,7 @@ interface Interactive {
 
 class SceneEvents {
 
-	var stage : hxd.Stage;
+	var window : hxd.Window;
 	var scenes : Array<InteractiveScene>;
 
 	var currentOver : Interactive;
@@ -32,13 +32,13 @@ class SceneEvents {
 	var checkPos = new hxd.Event(ECheck);
 	var onOut = new hxd.Event(EOut);
 
-	public function new( ?stage ) {
+	public function new( ?window ) {
 		scenes = [];
 		pendingEvents = [];
 		pushList = [];
-		if( stage == null ) stage = hxd.Stage.getInstance();
-		this.stage = stage;
-		stage.addEventTarget(onEvent);
+		if( window == null ) window = hxd.Window.getInstance();
+		this.window = window;
+		window.addEventTarget(onEvent);
 	}
 
 	function onRemove(i) {
@@ -61,7 +61,7 @@ class SceneEvents {
 	}
 
 	public function dispose() {
-		stage.removeEventTarget(onEvent);
+		window.removeEventTarget(onEvent);
 	}
 
 	public function focus( i : Interactive ) {

+ 3 - 103
hxd/Stage.hx

@@ -1,105 +1,5 @@
 package hxd;
 
-class Stage {
-
-	var resizeEvents : List<Void -> Void>;
-	var eventTargets : List<Event -> Void>;
-
-	public var width(get, never) : Int;
-	public var height(get, never) : Int;
-	public var mouseX(get, never) : Int;
-	public var mouseY(get, never) : Int;
-	public var mouseLock(get, set) : Bool;
-	public var vsync(get, set) : Bool;
-	public var isFocused(get, never) : Bool;
-
-	function new() : Void {
-		eventTargets = new List();
-		resizeEvents = new List();
-	}
-
-	public dynamic function onClose() : Bool {
-		return true;
-	}
-
-	public function event( e : hxd.Event ) : Void {
-		for( et in eventTargets )
-			et(e);
-	}
-
-	public function addEventTarget( et : Event->Void ) : Void {
-		eventTargets.add(et);
-	}
-
-	public function removeEventTarget( et : Event->Void ) : Void {
-		for( e in eventTargets )
-			if( Reflect.compareMethods(e,et) ) {
-				eventTargets.remove(e);
-				break;
-			}
-	}
-
-	public function addResizeEvent( f : Void -> Void ) : Void {
-		resizeEvents.push(f);
-	}
-
-	public function removeResizeEvent( f : Void -> Void ) : Void {
-		for( e in resizeEvents )
-			if( Reflect.compareMethods(e,f) ) {
-				resizeEvents.remove(f);
-				break;
-			}
-	}
-
-	function onResize(e:Dynamic) : Void {
-		for( r in resizeEvents )
-			r();
-	}
-
-	public function resize( width : Int, height : Int ) : Void {
-	}
-
-	public function setFullScreen( v : Bool ) : Void {
-	}
-
-	static var inst : Stage = null;
-	public static function getInstance() : Stage {
-		if( inst == null ) inst = new Stage();
-		return inst;
-	}
-
-	function get_mouseX() : Int {
-		return 0;
-	}
-
-	function get_mouseY() : Int {
-		return 0;
-	}
-
-	function get_width() : Int {
-		return 0;
-	}
-
-	function get_height() : Int {
-		return 0;
-	}
-
-	function get_mouseLock() : Bool {
-		return false;
-	}
-
-	function set_mouseLock( v : Bool ) : Bool {
-		if( v ) throw "Not implemented";
-		return false;
-	}
-
-	function get_vsync() : Bool return true;
-
-	function set_vsync( b : Bool ) : Bool {
-		if( !b ) throw "Can't disable vsync on this platform";
-		return true;
-	}
-
-	function get_isFocused() : Bool return true;
-
-}
+@:deprecated("hxd.Stage is now hxd.Window")
+@:noCompletion
+typedef Stage = Window;

+ 9 - 9
hxd/System.hl.hx

@@ -55,13 +55,13 @@ class System {
 	static function mainLoop() : Bool {
 		// process events
 		#if usesys
-		if( !haxe.System.emitEvents(@:privateAccess hxd.Stage.inst.event) )
+		if( !haxe.System.emitEvents(@:privateAccess hxd.Window.inst.event) )
 			return false;
 		#elseif hldx
-		if( !dx.Loop.processEvents(@:privateAccess hxd.Stage.inst.onEvent) )
+		if( !dx.Loop.processEvents(@:privateAccess hxd.Window.inst.onEvent) )
 			return false;
 		#elseif hlsdl
-		if( !sdl.Sdl.processEvents(@:privateAccess hxd.Stage.inst.onEvent) )
+		if( !sdl.Sdl.processEvents(@:privateAccess hxd.Window.inst.onEvent) )
 			return false;
 		#end
 
@@ -79,7 +79,7 @@ class System {
 		#if usesys
 
 		if( !haxe.System.init() ) return;
-		@:privateAccess Stage.inst = new Stage("", haxe.System.width, haxe.System.height);
+		@:privateAccess Window.inst = new Window("", haxe.System.width, haxe.System.height);
 		init();
 
 		#else
@@ -97,14 +97,14 @@ class System {
 		timeoutTick();
 		#if hlsdl
 			sdl.Sdl.init();
-			@:privateAccess Stage.initChars();
-			@:privateAccess Stage.inst = new Stage(title, width, height);
+			@:privateAccess Window.initChars();
+			@:privateAccess Window.inst = new Window(title, width, height);
 			init();
 		#elseif hldx
-			@:privateAccess Stage.inst = new Stage(title, width, height);
+			@:privateAccess Window.inst = new Window(title, width, height);
 			init();
 		#else
-			@:privateAccess Stage.inst = new Stage(title, width, height);
+			@:privateAccess Window.inst = new Window(title, width, height);
 			init();
 		#end
 		#end
@@ -220,7 +220,7 @@ class System {
 		}
 		#end
 	}
-	
+
 	#if (hlsdl || hldx)
 	static function updateCursor() : Void {
 		if (currentCustomCursor != null)

+ 6 - 6
hxd/System.js.hx

@@ -27,7 +27,7 @@ class System {
 
 	public static function timeoutTick() : Void {
 	}
-	
+
 	static var loopFunc : Void -> Void;
 
 	// JS
@@ -65,7 +65,7 @@ class System {
 			return;
 		currentNativeCursor = c;
 		currentCustomCursor = null;
-		var canvas = @:privateAccess hxd.Stage.getInstance().canvas;
+		var canvas = @:privateAccess hxd.Window.getInstance().canvas;
 		if( canvas != null ) {
 			canvas.style.cursor = switch( c ) {
 			case Default: "default";
@@ -108,14 +108,14 @@ class System {
 		if ( currentCustomCursor != null ) {
 			var change = currentCustomCursor.update(hxd.Timer.deltaT);
 			if ( change != -1 ) {
-				var canvas = @:privateAccess hxd.Stage.getInstance().canvas;
+				var canvas = @:privateAccess hxd.Window.getInstance().canvas;
 				if ( canvas != null ) {
 					canvas.style.cursor = currentCustomCursor.alloc[change];
 				}
 			}
 		}
 	}
-	
+
 	// getters
 
 	static function get_width() : Int return Math.round(js.Browser.document.body.clientWidth * js.Browser.window.devicePixelRatio);
@@ -125,9 +125,9 @@ class System {
 	static function get_screenDPI() : Int return 72;
 	static function get_allowTimeout() return false;
 	static function set_allowTimeout(b) return false;
-	
+
 	static function __init__() : Void {
 		haxe.MainLoop.add(updateCursor, -1);
 	}
-	
+
 }

+ 4 - 4
hxd/Stage.flash.hx → hxd/Window.flash.hx

@@ -1,6 +1,6 @@
 package hxd;
 
-class Stage {
+class Window {
 
 	var resizeEvents : List<Void -> Void>;
 	var eventTargets : List<Event -> Void>;
@@ -120,9 +120,9 @@ class Stage {
 		}
 	}
 
-	static var inst : Stage = null;
-	public static function getInstance() : Stage {
-		if( inst == null ) inst = new Stage();
+	static var inst : Window = null;
+	public static function getInstance() : Window {
+		if( inst == null ) inst = new Window();
 		return inst;
 	}
 

+ 3 - 3
hxd/Stage.hl.hx → hxd/Window.hl.hx

@@ -6,7 +6,7 @@ import hxd.Key in K;
 #end
 
 //@:coreApi
-class Stage {
+class Window {
 
 	var resizeEvents : List<Void -> Void>;
 	var eventTargets : List<Event -> Void>;
@@ -333,8 +333,8 @@ class Stage {
 
 	#end
 
-	static var inst : Stage = null;
-	public static function getInstance() : Stage {
+	static var inst : Window = null;
+	public static function getInstance() : Window {
 		return inst;
 	}
 }

+ 105 - 0
hxd/Window.hx

@@ -0,0 +1,105 @@
+package hxd;
+
+class Window {
+
+	var resizeEvents : List<Void -> Void>;
+	var eventTargets : List<Event -> Void>;
+
+	public var width(get, never) : Int;
+	public var height(get, never) : Int;
+	public var mouseX(get, never) : Int;
+	public var mouseY(get, never) : Int;
+	public var mouseLock(get, set) : Bool;
+	public var vsync(get, set) : Bool;
+	public var isFocused(get, never) : Bool;
+
+	function new() : Void {
+		eventTargets = new List();
+		resizeEvents = new List();
+	}
+
+	public dynamic function onClose() : Bool {
+		return true;
+	}
+
+	public function event( e : hxd.Event ) : Void {
+		for( et in eventTargets )
+			et(e);
+	}
+
+	public function addEventTarget( et : Event->Void ) : Void {
+		eventTargets.add(et);
+	}
+
+	public function removeEventTarget( et : Event->Void ) : Void {
+		for( e in eventTargets )
+			if( Reflect.compareMethods(e,et) ) {
+				eventTargets.remove(e);
+				break;
+			}
+	}
+
+	public function addResizeEvent( f : Void -> Void ) : Void {
+		resizeEvents.push(f);
+	}
+
+	public function removeResizeEvent( f : Void -> Void ) : Void {
+		for( e in resizeEvents )
+			if( Reflect.compareMethods(e,f) ) {
+				resizeEvents.remove(f);
+				break;
+			}
+	}
+
+	function onResize(e:Dynamic) : Void {
+		for( r in resizeEvents )
+			r();
+	}
+
+	public function resize( width : Int, height : Int ) : Void {
+	}
+
+	public function setFullScreen( v : Bool ) : Void {
+	}
+
+	static var inst : Window = null;
+	public static function getInstance() : Window {
+		if( inst == null ) inst = new Window();
+		return inst;
+	}
+
+	function get_mouseX() : Int {
+		return 0;
+	}
+
+	function get_mouseY() : Int {
+		return 0;
+	}
+
+	function get_width() : Int {
+		return 0;
+	}
+
+	function get_height() : Int {
+		return 0;
+	}
+
+	function get_mouseLock() : Bool {
+		return false;
+	}
+
+	function set_mouseLock( v : Bool ) : Bool {
+		if( v ) throw "Not implemented";
+		return false;
+	}
+
+	function get_vsync() : Bool return true;
+
+	function set_vsync( b : Bool ) : Bool {
+		if( !b ) throw "Can't disable vsync on this platform";
+		return true;
+	}
+
+	function get_isFocused() : Bool return true;
+
+}

+ 4 - 4
hxd/Stage.js.hx → hxd/Window.js.hx

@@ -1,6 +1,6 @@
 package hxd;
 
-class Stage {
+class Window {
 
 	var resizeEvents : List<Void -> Void>;
 	var eventTargets : List<Event -> Void>;
@@ -132,9 +132,9 @@ class Stage {
 		inst = this;
 	}
 
-	static var inst : Stage = null;
-	public static function getInstance() : Stage {
-		if( inst == null ) inst = new Stage();
+	static var inst : Window = null;
+	public static function getInstance() : Window {
+		if( inst == null ) inst = new Window();
 		return inst;
 	}
 

+ 5 - 5
hxd/inspect/ScenePanel.hx

@@ -271,15 +271,15 @@ class ScenePanel extends Panel {
 		btPick = j.find(".bt_pick");
 		btPick.click(function(_) {
 			btPick.toggleClass("active");
-			var stage = hxd.Stage.getInstance();
+			var window = hxd.Window.getInstance();
 			if( !btPick.hasClass("active") ) {
 				currentPick = null;
 				lastPickEvent = null;
-				stage.removeEventTarget(onPickEvent);
+				window.removeEventTarget(onPickEvent);
 				return;
 			}
 			lastPickEvent = 0;
-			stage.addEventTarget(onPickEvent);
+			window.addEventTarget(onPickEvent);
 		});
 	}
 
@@ -355,8 +355,8 @@ class ScenePanel extends Panel {
 			sceneObjects.pop().dispose();
 		var frame = h3d.Engine.getCurrent().frameCount;
 		if( lastPickEvent != null && lastPickEvent < frame - 1 ) {
-			var stage = hxd.Stage.getInstance();
-			var e = new hxd.Event(EMove, stage.mouseX, stage.mouseY);
+			var window = hxd.Window.getInstance();
+			var e = new hxd.Event(EMove, window.mouseX, window.mouseY);
 			haxe.Timer.delay(function() { if( lastPickEvent == null ) return; onPickEvent(e); }, 0); // flash don't like to capture while rendering
 		}
 	}