Add application.removeWindow, window.close, and fixes for using an empty config
This commit is contained in:
@@ -157,10 +157,6 @@ class FlashApplication {
|
|||||||
|
|
||||||
var window = new Window (config);
|
var window = new Window (config);
|
||||||
var renderer = new Renderer (window);
|
var renderer = new Renderer (window);
|
||||||
|
|
||||||
window.width = config.width;
|
|
||||||
window.height = config.height;
|
|
||||||
|
|
||||||
parent.addWindow (window);
|
parent.addWindow (window);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,6 +29,13 @@ class FlashWindow {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function close ():Void {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public function create (application:Application):Void {
|
public function create (application:Application):Void {
|
||||||
|
|
||||||
Lib.current.stage.addEventListener (Event.ACTIVATE, handleEvent);
|
Lib.current.stage.addEventListener (Event.ACTIVATE, handleEvent);
|
||||||
|
|||||||
@@ -112,11 +112,6 @@ class HTML5Application {
|
|||||||
|
|
||||||
var window = new Window (config);
|
var window = new Window (config);
|
||||||
var renderer = new Renderer (window);
|
var renderer = new Renderer (window);
|
||||||
|
|
||||||
window.width = config.width;
|
|
||||||
window.height = config.height;
|
|
||||||
window.backend.element = config.element;
|
|
||||||
|
|
||||||
parent.addWindow (window);
|
parent.addWindow (window);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -59,10 +59,10 @@ class HTML5Renderer {
|
|||||||
|
|
||||||
var options = {
|
var options = {
|
||||||
alpha: true,
|
alpha: true,
|
||||||
antialias: parent.window.config.antialiasing > 0,
|
antialias: Reflect.hasField (parent.window.config, "antialiasing") ? parent.window.config.antialiasing > 0 : false,
|
||||||
depth: parent.window.config.depthBuffer,
|
depth: Reflect.hasField (parent.window.config, "depthBuffer") ? parent.window.config.depthBuffer : true,
|
||||||
premultipliedAlpha: true,
|
premultipliedAlpha: true,
|
||||||
stencil: parent.window.config.stencilBuffer,
|
stencil: Reflect.hasField (parent.window.config, "stencilBuffer") ? parent.window.config.stencilBuffer : true,
|
||||||
preserveDrawingBuffer: false
|
preserveDrawingBuffer: false
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -38,6 +38,19 @@ class HTML5Window {
|
|||||||
|
|
||||||
this.parent = parent;
|
this.parent = parent;
|
||||||
|
|
||||||
|
if (parent.config != null && Reflect.hasField (parent.config, "element")) {
|
||||||
|
|
||||||
|
element = parent.config.element;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function close ():Void {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -84,10 +84,6 @@ class NativeApplication {
|
|||||||
|
|
||||||
var window = new Window (config);
|
var window = new Window (config);
|
||||||
var renderer = new Renderer (window);
|
var renderer = new Renderer (window);
|
||||||
|
|
||||||
window.width = config.width;
|
|
||||||
window.height = config.height;
|
|
||||||
|
|
||||||
parent.addWindow (window);
|
parent.addWindow (window);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -38,6 +38,18 @@ class NativeWindow {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function close ():Void {
|
||||||
|
|
||||||
|
if (handle != null) {
|
||||||
|
|
||||||
|
lime_window_close (handle);
|
||||||
|
handle = null;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public function create (application:Application):Void {
|
public function create (application:Application):Void {
|
||||||
|
|
||||||
var title = "Lime Application";
|
var title = "Lime Application";
|
||||||
@@ -45,24 +57,32 @@ class NativeWindow {
|
|||||||
|
|
||||||
if (parent.config != null) {
|
if (parent.config != null) {
|
||||||
|
|
||||||
if (parent.config.antialiasing >= 4) {
|
if (Reflect.hasField (parent.config, "antialiasing")) {
|
||||||
|
|
||||||
flags |= cast WindowFlags.WINDOW_FLAG_HW_AA_HIRES;
|
if (parent.config.antialiasing >= 4) {
|
||||||
|
|
||||||
} else if (parent.config.antialiasing >= 2) {
|
flags |= cast WindowFlags.WINDOW_FLAG_HW_AA_HIRES;
|
||||||
|
|
||||||
flags |= cast WindowFlags.WINDOW_FLAG_HW_AA;
|
} else if (parent.config.antialiasing >= 2) {
|
||||||
|
|
||||||
|
flags |= cast WindowFlags.WINDOW_FLAG_HW_AA;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (parent.config.borderless) flags |= cast WindowFlags.WINDOW_FLAG_BORDERLESS;
|
if (Reflect.hasField (parent.config, "borderless") && parent.config.borderless) flags |= cast WindowFlags.WINDOW_FLAG_BORDERLESS;
|
||||||
if (parent.config.depthBuffer) flags |= cast WindowFlags.WINDOW_FLAG_DEPTH_BUFFER;
|
if (Reflect.hasField (parent.config, "depthBuffer") && parent.config.depthBuffer) flags |= cast WindowFlags.WINDOW_FLAG_DEPTH_BUFFER;
|
||||||
if (parent.config.fullscreen) flags |= cast WindowFlags.WINDOW_FLAG_FULLSCREEN;
|
if (Reflect.hasField (parent.config, "fullscreen") && parent.config.fullscreen) flags |= cast WindowFlags.WINDOW_FLAG_FULLSCREEN;
|
||||||
if (parent.config.resizable) flags |= cast WindowFlags.WINDOW_FLAG_RESIZABLE;
|
if (Reflect.hasField (parent.config, "resizable") && parent.config.resizable) flags |= cast WindowFlags.WINDOW_FLAG_RESIZABLE;
|
||||||
if (parent.config.stencilBuffer) flags |= cast WindowFlags.WINDOW_FLAG_STENCIL_BUFFER;
|
if (Reflect.hasField (parent.config, "stencilBuffer") && parent.config.stencilBuffer) flags |= cast WindowFlags.WINDOW_FLAG_STENCIL_BUFFER;
|
||||||
if (parent.config.vsync) flags |= cast WindowFlags.WINDOW_FLAG_VSYNC;
|
if (Reflect.hasField (parent.config, "vsync") && parent.config.vsync) flags |= cast WindowFlags.WINDOW_FLAG_VSYNC;
|
||||||
|
|
||||||
title = parent.config.title;
|
if (Reflect.hasField (parent.config, "title")) {
|
||||||
|
|
||||||
|
title = parent.config.title;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -135,6 +155,7 @@ class NativeWindow {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private static var lime_window_close = System.load ("lime", "lime_window_close", 1);
|
||||||
private static var lime_window_create = System.load ("lime", "lime_window_create", 5);
|
private static var lime_window_create = System.load ("lime", "lime_window_create", 5);
|
||||||
private static var lime_window_event_manager_register = System.load ("lime", "lime_window_event_manager_register", 2);
|
private static var lime_window_event_manager_register = System.load ("lime", "lime_window_event_manager_register", 2);
|
||||||
private static var lime_window_move = System.load ("lime", "lime_window_move", 3);
|
private static var lime_window_move = System.load ("lime", "lime_window_move", 3);
|
||||||
|
|||||||
@@ -224,6 +224,22 @@ class Application extends Module {
|
|||||||
public function onWindowResize (width:Int, height:Int):Void {}
|
public function onWindowResize (width:Int, height:Int):Void {}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Removes a Window from the Application
|
||||||
|
* @param window A Window object to add
|
||||||
|
*/
|
||||||
|
public function removeWindow (window:Window):Void {
|
||||||
|
|
||||||
|
if (window != null && windows.indexOf (window) > -1) {
|
||||||
|
|
||||||
|
window.close ();
|
||||||
|
windows.remove (window);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when a render event is fired
|
* Called when a render event is fired
|
||||||
* @param context The current render context
|
* @param context The current render context
|
||||||
|
|||||||
@@ -34,26 +34,34 @@ class Window {
|
|||||||
|
|
||||||
this.config = config;
|
this.config = config;
|
||||||
|
|
||||||
if (config == null) {
|
width = 0;
|
||||||
|
height = 0;
|
||||||
width = 0;
|
fullscreen = false;
|
||||||
height = 0;
|
|
||||||
|
|
||||||
} else {
|
|
||||||
|
|
||||||
width = config.width;
|
|
||||||
height = config.height;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
x = 0;
|
x = 0;
|
||||||
y = 0;
|
y = 0;
|
||||||
|
|
||||||
|
if (config != null) {
|
||||||
|
|
||||||
|
// TODO: Switch to the tool's Config type?
|
||||||
|
|
||||||
|
if (Reflect.hasField (config, "width")) width = config.width;
|
||||||
|
if (Reflect.hasField (config, "height")) height = config.height;
|
||||||
|
if (Reflect.hasField (config, "fullscreen")) fullscreen = config.fullscreen;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
backend = new WindowBackend (this);
|
backend = new WindowBackend (this);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function close ():Void {
|
||||||
|
|
||||||
|
backend.close ();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public function create (application:Application):Void {
|
public function create (application:Application):Void {
|
||||||
|
|
||||||
backend.create (application);
|
backend.create (application);
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ namespace lime {
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
virtual void Close () = 0;
|
||||||
virtual void Move (int x, int y) = 0;
|
virtual void Move (int x, int y) = 0;
|
||||||
virtual void Resize (int width, int height) = 0;
|
virtual void Resize (int width, int height) = 0;
|
||||||
virtual void SetIcon (ImageBuffer *imageBuffer) = 0;
|
virtual void SetIcon (ImageBuffer *imageBuffer) = 0;
|
||||||
|
|||||||
@@ -461,6 +461,16 @@ namespace lime {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
value lime_window_close (value window) {
|
||||||
|
|
||||||
|
Window* targetWindow = (Window*)(intptr_t)val_float (window);
|
||||||
|
targetWindow->Close ();
|
||||||
|
delete targetWindow;
|
||||||
|
return alloc_null ();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
value lime_window_create (value application, value width, value height, value flags, value title) {
|
value lime_window_create (value application, value width, value height, value flags, value title) {
|
||||||
|
|
||||||
Window* window = CreateWindow ((Application*)(intptr_t)val_float (application), val_int (width), val_int (height), val_int (flags), val_string (title));
|
Window* window = CreateWindow ((Application*)(intptr_t)val_float (application), val_int (width), val_int (height), val_int (flags), val_string (title));
|
||||||
@@ -537,6 +547,7 @@ namespace lime {
|
|||||||
DEFINE_PRIM (lime_text_from_string, 4);
|
DEFINE_PRIM (lime_text_from_string, 4);
|
||||||
DEFINE_PRIM (lime_touch_event_manager_register, 2);
|
DEFINE_PRIM (lime_touch_event_manager_register, 2);
|
||||||
DEFINE_PRIM (lime_update_event_manager_register, 2);
|
DEFINE_PRIM (lime_update_event_manager_register, 2);
|
||||||
|
DEFINE_PRIM (lime_window_close, 1);
|
||||||
DEFINE_PRIM (lime_window_create, 5);
|
DEFINE_PRIM (lime_window_create, 5);
|
||||||
DEFINE_PRIM (lime_window_event_manager_register, 2);
|
DEFINE_PRIM (lime_window_event_manager_register, 2);
|
||||||
DEFINE_PRIM (lime_window_move, 3);
|
DEFINE_PRIM (lime_window_move, 3);
|
||||||
|
|||||||
@@ -70,6 +70,17 @@ namespace lime {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void SDLWindow::Close () {
|
||||||
|
|
||||||
|
if (sdlWindow) {
|
||||||
|
|
||||||
|
SDL_DestroyWindow (sdlWindow);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void SDLWindow::Move (int x, int y) {
|
void SDLWindow::Move (int x, int y) {
|
||||||
|
|
||||||
SDL_SetWindowPosition (sdlWindow, x, y);
|
SDL_SetWindowPosition (sdlWindow, x, y);
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ namespace lime {
|
|||||||
SDLWindow (Application* application, int width, int height, int flags, const char* title);
|
SDLWindow (Application* application, int width, int height, int flags, const char* title);
|
||||||
~SDLWindow ();
|
~SDLWindow ();
|
||||||
|
|
||||||
|
virtual void Close ();
|
||||||
virtual void Move (int x, int y);
|
virtual void Move (int x, int y);
|
||||||
virtual void Resize (int width, int height);
|
virtual void Resize (int width, int height);
|
||||||
virtual void SetIcon (ImageBuffer *imageBuffer);
|
virtual void SetIcon (ImageBuffer *imageBuffer);
|
||||||
|
|||||||
@@ -12,13 +12,6 @@ class WindowTest {
|
|||||||
private var app:Application;
|
private var app:Application;
|
||||||
|
|
||||||
|
|
||||||
public function new () {
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@BeforeClass public function beforeClass ():Void {
|
@BeforeClass public function beforeClass ():Void {
|
||||||
|
|
||||||
app = new Application ();
|
app = new Application ();
|
||||||
@@ -27,31 +20,158 @@ class WindowTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test public function addWindow ():Void {
|
@Test public function createEmptyWindow ():Void {
|
||||||
|
|
||||||
Assert.isNull (app.window);
|
Assert.isNull (app.window);
|
||||||
Assert.areEqual (0, app.windows.length);
|
Assert.areEqual (0, app.windows.length);
|
||||||
|
|
||||||
var window = new Window ();
|
var window = new Window ();
|
||||||
|
|
||||||
|
Assert.isNull (window.currentRenderer);
|
||||||
|
Assert.isNull (window.config);
|
||||||
|
Assert.isFalse (window.fullscreen);
|
||||||
|
Assert.areEqual (0, window.height);
|
||||||
|
Assert.areEqual (0, window.width);
|
||||||
|
Assert.areEqual (0, window.x);
|
||||||
|
Assert.areEqual (0, window.y);
|
||||||
|
|
||||||
app.addWindow (window);
|
app.addWindow (window);
|
||||||
|
|
||||||
Assert.isNotNull (app.window);
|
Assert.isNull (window.currentRenderer);
|
||||||
Assert.areEqual (1, app.windows.length);
|
Assert.isNull (window.config);
|
||||||
Assert.areEqual (window, app.window);
|
|
||||||
Assert.areEqual (window, app.windows[0]);
|
|
||||||
|
|
||||||
//Assert.areEqual (0, window.width);
|
#if !html5
|
||||||
//Assert.areEqual (0, window.height);
|
|
||||||
|
// TODO: standardize the behavior of a 0 x 0 window
|
||||||
|
|
||||||
|
Assert.isFalse (window.fullscreen);
|
||||||
|
Assert.areEqual (0, window.height);
|
||||||
|
Assert.areEqual (0, window.width);
|
||||||
|
Assert.areEqual (0, window.x);
|
||||||
|
Assert.areEqual (0, window.y);
|
||||||
|
|
||||||
|
#end
|
||||||
|
|
||||||
|
app.removeWindow (window);
|
||||||
|
|
||||||
|
Assert.isNull (app.window);
|
||||||
|
Assert.areEqual (0, app.windows.length);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Test public function createBasicWindow ():Void {
|
||||||
|
|
||||||
|
Assert.isNull (app.window);
|
||||||
|
Assert.areEqual (0, app.windows.length);
|
||||||
|
|
||||||
|
var window = new Window ();
|
||||||
|
|
||||||
|
window.width = 400;
|
||||||
|
window.height = 300;
|
||||||
|
|
||||||
|
Assert.isNull (window.currentRenderer);
|
||||||
|
Assert.isNull (window.config);
|
||||||
|
Assert.isFalse (window.fullscreen);
|
||||||
|
Assert.areEqual (300, window.height);
|
||||||
|
Assert.areEqual (400, window.width);
|
||||||
|
Assert.areEqual (0, window.x);
|
||||||
|
Assert.areEqual (0, window.y);
|
||||||
|
|
||||||
|
app.addWindow (window);
|
||||||
|
|
||||||
|
Assert.isNull (window.currentRenderer);
|
||||||
|
Assert.isNull (window.config);
|
||||||
|
Assert.isFalse (window.fullscreen);
|
||||||
|
Assert.areEqual (300, window.height);
|
||||||
|
Assert.areEqual (400, window.width);
|
||||||
|
Assert.areEqual (0, window.x);
|
||||||
|
Assert.areEqual (0, window.y);
|
||||||
|
|
||||||
|
app.removeWindow (window);
|
||||||
|
|
||||||
|
Assert.isNull (app.window);
|
||||||
|
Assert.areEqual (0, app.windows.length);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Test public function createEmptyWindowFromConfig ():Void {
|
||||||
|
|
||||||
|
Assert.isNull (app.window);
|
||||||
|
Assert.areEqual (0, app.windows.length);
|
||||||
|
|
||||||
|
var config = {};
|
||||||
|
var window = new Window (config);
|
||||||
|
|
||||||
|
Assert.isNull (window.currentRenderer);
|
||||||
|
Assert.areEqual (config, window.config);
|
||||||
|
Assert.isFalse (window.fullscreen);
|
||||||
|
Assert.areEqual (0, window.height);
|
||||||
|
Assert.areEqual (0, window.width);
|
||||||
|
Assert.areEqual (0, window.x);
|
||||||
|
Assert.areEqual (0, window.y);
|
||||||
|
|
||||||
|
app.addWindow (window);
|
||||||
|
|
||||||
|
Assert.isNull (window.currentRenderer);
|
||||||
|
Assert.areEqual (config, window.config);
|
||||||
|
|
||||||
|
#if !html5
|
||||||
|
|
||||||
|
Assert.isFalse (window.fullscreen);
|
||||||
|
Assert.areEqual (0, window.height);
|
||||||
|
Assert.areEqual (0, window.width);
|
||||||
|
Assert.areEqual (0, window.x);
|
||||||
|
Assert.areEqual (0, window.y);
|
||||||
|
|
||||||
|
#end
|
||||||
|
|
||||||
|
app.removeWindow (window);
|
||||||
|
|
||||||
|
Assert.isNull (app.window);
|
||||||
|
Assert.areEqual (0, app.windows.length);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Test public function createBasicWindowFromConfig ():Void {
|
||||||
|
|
||||||
|
Assert.isNull (app.window);
|
||||||
|
Assert.areEqual (0, app.windows.length);
|
||||||
|
|
||||||
|
var config = { width: 400, height: 300 };
|
||||||
|
var window = new Window (config);
|
||||||
|
|
||||||
|
Assert.isNull (window.currentRenderer);
|
||||||
|
Assert.areEqual (config, window.config);
|
||||||
|
Assert.isFalse (window.fullscreen);
|
||||||
|
Assert.areEqual (300, window.height);
|
||||||
|
Assert.areEqual (400, window.width);
|
||||||
|
Assert.areEqual (0, window.x);
|
||||||
|
Assert.areEqual (0, window.y);
|
||||||
|
|
||||||
|
app.addWindow (window);
|
||||||
|
|
||||||
|
Assert.isNull (window.currentRenderer);
|
||||||
|
Assert.areEqual (config, window.config);
|
||||||
|
Assert.isFalse (window.fullscreen);
|
||||||
|
Assert.areEqual (300, window.height);
|
||||||
|
Assert.areEqual (400, window.width);
|
||||||
|
Assert.areEqual (0, window.x);
|
||||||
|
Assert.areEqual (0, window.y);
|
||||||
|
|
||||||
|
app.removeWindow (window);
|
||||||
|
|
||||||
|
Assert.isNull (app.window);
|
||||||
|
Assert.areEqual (0, app.windows.length);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@AfterClass public function afterClass ():Void {
|
@AfterClass public function afterClass ():Void {
|
||||||
|
|
||||||
// shutdown
|
app = null;
|
||||||
|
|
||||||
//app = new Application ();
|
|
||||||
//app.create (null);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user