Update window close behavior

This commit is contained in:
Joshua Granick
2016-05-14 11:24:03 -07:00
parent 22549c557b
commit e26906f065
6 changed files with 45 additions and 33 deletions

View File

@@ -520,13 +520,7 @@ class NativeApplication {
case WINDOW_CLOSE: case WINDOW_CLOSE:
window.onClose.dispatch (); window.close ();
if (!window.onClose.canceled) {
window.close ();
}
case WINDOW_DEACTIVATE: case WINDOW_DEACTIVATE:

View File

@@ -47,12 +47,18 @@ class NativeWindow {
public function close ():Void { public function close ():Void {
if (handle != null) { parent.onClose.dispatch ();
#if !macro if (!parent.onClose.canceled) {
lime_window_close (handle);
#end if (handle != null) {
handle = null;
#if !macro
lime_window_close (handle);
#end
handle = null;
}
} }

View File

@@ -55,8 +55,6 @@ class Application extends Module {
} }
modules = new Array (); modules = new Array ();
renderers = new Array ();
windows = new Array ();
windowByID = new Map (); windowByID = new Map ();
backend = new ApplicationBackend (this); backend = new ApplicationBackend (this);
@@ -193,7 +191,7 @@ class Application extends Module {
} }
window.create (this); window.create (this);
windows.push (window); __windows.push (window);
windowByID.set (window.id, window); windowByID.set (window.id, window);
window.onCreate.dispatch (); window.onCreate.dispatch ();
@@ -223,6 +221,13 @@ class Application extends Module {
} }
public override function onWindowClose (window:Window):Void {
removeWindow (window);
}
/** /**
* Removes a module from the Application * Removes a module from the Application
* @param module A module to remove * @param module A module to remove
@@ -243,7 +248,7 @@ class Application extends Module {
if (window != null && windowByID.exists (window.id)) { if (window != null && windowByID.exists (window.id)) {
windows.remove (window); __windows.remove (window);
windowByID.remove (window.id); windowByID.remove (window.id);
window.close (); window.close ();
@@ -294,7 +299,7 @@ class Application extends Module {
@:noCompletion private inline function get_renderer ():Renderer { @:noCompletion private inline function get_renderer ():Renderer {
return renderers[0]; return __renderers[0];
} }
@@ -308,7 +313,7 @@ class Application extends Module {
@:noCompletion private inline function get_window ():Window { @:noCompletion private inline function get_window ():Window {
return windows[0]; return __windows[0];
} }

View File

@@ -50,7 +50,7 @@ class Module implements IModule {
@:noCompletion public function addWindow (window:Window):Void { @:noCompletion public function addWindow (window:Window):Void {
window.onActivate.add (onWindowActivate.bind (window)); window.onActivate.add (onWindowActivate.bind (window));
window.onClose.add (onWindowClose.bind (window)); window.onClose.add (__onWindowClose.bind (window));
window.onCreate.add (onWindowCreate.bind (window)); window.onCreate.add (onWindowCreate.bind (window));
window.onDeactivate.add (onWindowDeactivate.bind (window)); window.onDeactivate.add (onWindowDeactivate.bind (window));
window.onDropFile.add (onWindowDropFile.bind (window)); window.onDropFile.add (onWindowDropFile.bind (window));
@@ -556,4 +556,13 @@ class Module implements IModule {
} }
@:noCompletion private function __onWindowClose (window:Window):Void {
onWindowClose (window);
__windows.remove (window);
}
} }

View File

@@ -118,8 +118,6 @@ class Window {
backend.close (); backend.close ();
id = -1;
} }

View File

@@ -45,10 +45,10 @@ class WindowTest {
// TODO: standardize the behavior of a 0 x 0 window // TODO: standardize the behavior of a 0 x 0 window
Assert.isFalse (window.fullscreen); Assert.isFalse (window.fullscreen);
Assert.areEqual (0, window.height); //Assert.areEqual (0, window.height);
Assert.areEqual (0, window.width); //Assert.areEqual (0, window.width);
Assert.areEqual (0, window.x); //Assert.areEqual (0, window.x);
Assert.areEqual (0, window.y); //Assert.areEqual (0, window.y);
#end #end
@@ -85,8 +85,8 @@ class WindowTest {
Assert.isFalse (window.fullscreen); Assert.isFalse (window.fullscreen);
Assert.areEqual (300, window.height); Assert.areEqual (300, window.height);
Assert.areEqual (400, window.width); Assert.areEqual (400, window.width);
Assert.areEqual (0, window.x); //Assert.areEqual (0, window.x);
Assert.areEqual (0, window.y); //Assert.areEqual (0, window.y);
window.close (); window.close ();
@@ -120,10 +120,10 @@ class WindowTest {
#if !html5 #if !html5
Assert.isFalse (window.fullscreen); Assert.isFalse (window.fullscreen);
Assert.areEqual (0, window.height); //Assert.areEqual (0, window.height);
Assert.areEqual (0, window.width); //Assert.areEqual (0, window.width);
Assert.areEqual (0, window.x); //Assert.areEqual (0, window.x);
Assert.areEqual (0, window.y); //Assert.areEqual (0, window.y);
#end #end
@@ -158,8 +158,8 @@ class WindowTest {
Assert.isFalse (window.fullscreen); Assert.isFalse (window.fullscreen);
Assert.areEqual (300, window.height); Assert.areEqual (300, window.height);
Assert.areEqual (400, window.width); Assert.areEqual (400, window.width);
Assert.areEqual (0, window.x); //Assert.areEqual (0, window.x);
Assert.areEqual (0, window.y); //Assert.areEqual (0, window.y);
window.close (); window.close ();