Fix test, application.createWindow instead of application.addWindow, remove application.removeWindow (use window.close)

This commit is contained in:
Joshua Granick
2015-08-20 11:46:18 -07:00
parent 04bbbcc180
commit f79a73fa47
5 changed files with 69 additions and 61 deletions

View File

@@ -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);
}

View File

@@ -52,7 +52,7 @@ class HTML5Renderer {
} else if (parent.window.backend.canvas != null) {
#if canvas
#if (canvas || munit)
var webgl = null;

View File

@@ -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);
}

View File

@@ -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;
}
}
}

View File

@@ -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);