From f79a73fa476ad9bd440d75d4c6a794aec9ff6495 Mon Sep 17 00:00:00 2001 From: Joshua Granick Date: Thu, 20 Aug 2015 11:46:18 -0700 Subject: [PATCH] Fix test, application.createWindow instead of application.addWindow, remove application.removeWindow (use window.close) --- lime/_backend/flash/FlashWindow.hx | 3 +- lime/_backend/html5/HTML5Renderer.hx | 2 +- lime/_backend/html5/HTML5Window.hx | 3 +- lime/app/Application.hx | 98 ++++++++++++++------------- tests/runtime/test/lime/WindowTest.hx | 24 +++---- 5 files changed, 69 insertions(+), 61 deletions(-) diff --git a/lime/_backend/flash/FlashWindow.hx b/lime/_backend/flash/FlashWindow.hx index 34358bb7c..b788739ee 100644 --- a/lime/_backend/flash/FlashWindow.hx +++ b/lime/_backend/flash/FlashWindow.hx @@ -10,6 +10,7 @@ import lime.system.Display; import lime.system.System; import lime.ui.Window; +@:access(lime.app.Application) @:access(lime.ui.Window) @@ -29,7 +30,7 @@ class FlashWindow { public function close ():Void { - + parent.application.removeWindow (parent); } diff --git a/lime/_backend/html5/HTML5Renderer.hx b/lime/_backend/html5/HTML5Renderer.hx index 47923dcaa..fd8ee14c5 100644 --- a/lime/_backend/html5/HTML5Renderer.hx +++ b/lime/_backend/html5/HTML5Renderer.hx @@ -52,7 +52,7 @@ class HTML5Renderer { } else if (parent.window.backend.canvas != null) { - #if canvas + #if (canvas || munit) var webgl = null; diff --git a/lime/_backend/html5/HTML5Window.hx b/lime/_backend/html5/HTML5Window.hx index 046b36176..ed5a53a97 100644 --- a/lime/_backend/html5/HTML5Window.hx +++ b/lime/_backend/html5/HTML5Window.hx @@ -28,6 +28,7 @@ typedef InputElement = Dynamic; typedef InputEvent = js.html.Event; #end +@:access(lime.app.Application) @:access(lime.ui.Window) @@ -67,7 +68,7 @@ class HTML5Window { public function close ():Void { - + parent.application.removeWindow (parent); } diff --git a/lime/app/Application.hx b/lime/app/Application.hx index aa7eeed25..037bd0b56 100644 --- a/lime/app/Application.hx +++ b/lime/app/Application.hx @@ -115,12 +115,54 @@ class Application extends Module { } + /** + * Initializes the Application, using the settings defined in + * the config instance. By default, this is called automatically + * when building the project using Lime's command-line tools + * @param config A Config object + */ + public function create (config:Config):Void { + + this.config = config; + + backend.create (config); + + if (config != null) { + + if (Reflect.hasField (config, "fps")) { + + frameRate = config.fps; + + } + + if (Reflect.hasField (config, "windows")) { + + for (windowConfig in config.windows) { + + var window = new Window (windowConfig); + createWindow (window); + + #if (flash || html5) + break; + #end + + } + + } + + init (this); + + } + + } + + /** * Adds a new Window to the Application. By default, this is * called automatically by create() * @param window A Window object to add */ - public function addWindow (window:Window):Void { + public function createWindow (window:Window):Void { this.window = window; @@ -160,50 +202,6 @@ class Application extends Module { } - /** - * Initializes the Application, using the settings defined in - * the config instance. By default, this is called automatically - * when building the project using Lime's command-line tools - * @param config A Config object - */ - public function create (config:Config):Void { - - this.config = config; - - backend.create (config); - - if (config != null) { - - if (Reflect.hasField (config, "fps")) { - - frameRate = config.fps; - - } - - if (Reflect.hasField (config, "windows")) { - - for (windowConfig in config.windows) { - - var window = new Window (windowConfig); - var renderer = new Renderer (window); - addWindow (window); - addRenderer (renderer); - - #if (flash || html5) - break; - #end - - } - - } - - init (this); - - } - - } - - /** * Execute the Application. On native platforms, this method * blocks until the application is finished running. On other @@ -504,6 +502,8 @@ class Application extends Module { } + removeWindow (window); + } @@ -652,7 +652,7 @@ class Application extends Module { * Removes a Window from the Application * @param window A Window object to remove */ - public function removeWindow (window:Window):Void { + private function removeWindow (window:Window):Void { if (window != null && windowByID.exists (window.id)) { @@ -660,6 +660,12 @@ class Application extends Module { windowByID.remove (window.id); window.close (); + if (this.window == window) { + + this.window = null; + + } + } } diff --git a/tests/runtime/test/lime/WindowTest.hx b/tests/runtime/test/lime/WindowTest.hx index ce4473ad9..2c6113709 100644 --- a/tests/runtime/test/lime/WindowTest.hx +++ b/tests/runtime/test/lime/WindowTest.hx @@ -35,9 +35,9 @@ class WindowTest { Assert.areEqual (0, window.x); Assert.areEqual (0, window.y); - app.addWindow (window); + app.createWindow (window); - Assert.isNull (window.currentRenderer); + Assert.isNotNull (window.currentRenderer); Assert.isNull (window.config); #if !html5 @@ -52,7 +52,7 @@ class WindowTest { #end - app.removeWindow (window); + window.close (); Assert.isNull (app.window); Assert.areEqual (0, app.windows.length); @@ -78,9 +78,9 @@ class WindowTest { Assert.areEqual (0, window.x); Assert.areEqual (0, window.y); - app.addWindow (window); + app.createWindow (window); - Assert.isNull (window.currentRenderer); + Assert.isNotNull (window.currentRenderer); Assert.isNull (window.config); Assert.isFalse (window.fullscreen); Assert.areEqual (300, window.height); @@ -88,7 +88,7 @@ class WindowTest { Assert.areEqual (0, window.x); Assert.areEqual (0, window.y); - app.removeWindow (window); + window.close (); Assert.isNull (app.window); Assert.areEqual (0, app.windows.length); @@ -112,9 +112,9 @@ class WindowTest { Assert.areEqual (0, window.x); Assert.areEqual (0, window.y); - app.addWindow (window); + app.createWindow (window); - Assert.isNull (window.currentRenderer); + Assert.isNotNull (window.currentRenderer); Assert.areEqual (config, window.config); #if !html5 @@ -127,7 +127,7 @@ class WindowTest { #end - app.removeWindow (window); + window.close (); Assert.isNull (app.window); Assert.areEqual (0, app.windows.length); @@ -151,9 +151,9 @@ class WindowTest { Assert.areEqual (0, window.x); Assert.areEqual (0, window.y); - app.addWindow (window); + app.createWindow (window); - Assert.isNull (window.currentRenderer); + Assert.isNotNull (window.currentRenderer); Assert.areEqual (config, window.config); Assert.isFalse (window.fullscreen); Assert.areEqual (300, window.height); @@ -161,7 +161,7 @@ class WindowTest { Assert.areEqual (0, window.x); Assert.areEqual (0, window.y); - app.removeWindow (window); + window.close (); Assert.isNull (app.window); Assert.areEqual (0, app.windows.length);