Expose Application.window, and define config.background for all platforms
This commit is contained in:
@@ -17,30 +17,29 @@ class Application {
|
|||||||
|
|
||||||
public static var onUpdate = new Event<Int->Void> ();
|
public static var onUpdate = new Event<Int->Void> ();
|
||||||
|
|
||||||
private static var eventInfo = new UpdateEventInfo ();
|
private static var __eventInfo = new UpdateEventInfo ();
|
||||||
private static var instance:Application;
|
private static var __instance:Application;
|
||||||
private static var registered:Bool;
|
private static var __registered:Bool;
|
||||||
|
|
||||||
public var handle:Dynamic;
|
public var config (default, null):Config;
|
||||||
|
public var window (get, null):Window;
|
||||||
|
public var windows (default, null):Array<Window>;
|
||||||
|
|
||||||
private var config:Config;
|
private var __handle:Dynamic;
|
||||||
private var lastUpdate:Int;
|
|
||||||
private var windows:Array<Window>;
|
|
||||||
|
|
||||||
|
|
||||||
public function new () {
|
public function new () {
|
||||||
|
|
||||||
instance = this;
|
__instance = this;
|
||||||
|
|
||||||
lastUpdate = 0;
|
|
||||||
windows = new Array ();
|
windows = new Array ();
|
||||||
|
|
||||||
if (!registered) {
|
if (!__registered) {
|
||||||
|
|
||||||
registered = true;
|
__registered = true;
|
||||||
|
|
||||||
#if (cpp || neko)
|
#if (cpp || neko)
|
||||||
lime_update_event_manager_register (__dispatch, eventInfo);
|
lime_update_event_manager_register (__dispatch, __eventInfo);
|
||||||
#end
|
#end
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -98,7 +97,7 @@ class Application {
|
|||||||
this.config = config;
|
this.config = config;
|
||||||
|
|
||||||
#if (cpp || neko)
|
#if (cpp || neko)
|
||||||
handle = lime_application_create (null);
|
__handle = lime_application_create (null);
|
||||||
#end
|
#end
|
||||||
|
|
||||||
KeyEventManager.create ();
|
KeyEventManager.create ();
|
||||||
@@ -137,7 +136,7 @@ class Application {
|
|||||||
public function exec ():Int {
|
public function exec ():Int {
|
||||||
|
|
||||||
#if (cpp || neko)
|
#if (cpp || neko)
|
||||||
return lime_application_exec (handle);
|
return lime_application_exec (__handle);
|
||||||
#else
|
#else
|
||||||
return 0;
|
return 0;
|
||||||
#end
|
#end
|
||||||
@@ -177,16 +176,15 @@ class Application {
|
|||||||
windows[0].stats.begin ();
|
windows[0].stats.begin ();
|
||||||
#end
|
#end
|
||||||
|
|
||||||
instance.update (eventInfo.deltaTime);
|
__instance.update (__eventInfo.deltaTime);
|
||||||
|
onUpdate.dispatch (__eventInfo.deltaTime);
|
||||||
onUpdate.dispatch (eventInfo.deltaTime);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@:noCompletion private function __triggerFrame (?_):Void {
|
@:noCompletion private function __triggerFrame (?_):Void {
|
||||||
|
|
||||||
eventInfo.deltaTime = 16; //TODO
|
__eventInfo.deltaTime = 16; //TODO
|
||||||
__dispatch ();
|
__dispatch ();
|
||||||
|
|
||||||
Renderer.dispatch ();
|
Renderer.dispatch ();
|
||||||
@@ -198,6 +196,13 @@ class Application {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private inline function get_window ():Window {
|
||||||
|
|
||||||
|
return windows[0];
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
#if (cpp || neko)
|
#if (cpp || neko)
|
||||||
private static var lime_application_create = System.load ("lime", "lime_application_create", 1);
|
private static var lime_application_create = System.load ("lime", "lime_application_create", 1);
|
||||||
private static var lime_application_exec = System.load ("lime", "lime_application_exec", 1);
|
private static var lime_application_exec = System.load ("lime", "lime_application_exec", 1);
|
||||||
|
|||||||
@@ -15,7 +15,11 @@ import flash.Lib;
|
|||||||
#end
|
#end
|
||||||
|
|
||||||
|
|
||||||
@:access(lime.graphics.opengl.GL) @:access(lime.app.Application) @:allow(lime.app.Application)
|
@:access(lime.graphics.opengl.GL)
|
||||||
|
@:access(lime.app.Application)
|
||||||
|
@:allow(lime.app.Application)
|
||||||
|
|
||||||
|
|
||||||
class Renderer {
|
class Renderer {
|
||||||
|
|
||||||
|
|
||||||
@@ -111,13 +115,13 @@ class Renderer {
|
|||||||
|
|
||||||
private static function dispatch ():Void {
|
private static function dispatch ():Void {
|
||||||
|
|
||||||
for (window in Application.instance.windows) {
|
for (window in Application.__instance.windows) {
|
||||||
|
|
||||||
if (window.currentRenderer != null) {
|
if (window.currentRenderer != null) {
|
||||||
|
|
||||||
var context = window.currentRenderer.context;
|
var context = window.currentRenderer.context;
|
||||||
|
|
||||||
Application.instance.render (context);
|
Application.__instance.render (context);
|
||||||
onRender.dispatch (context);
|
onRender.dispatch (context);
|
||||||
|
|
||||||
window.currentRenderer.flip ();
|
window.currentRenderer.flip ();
|
||||||
@@ -127,7 +131,7 @@ class Renderer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#if (js && stats)
|
#if (js && stats)
|
||||||
Application.instance.windows[0].stats.end ();
|
Application.__instance.windows[0].stats.end ();
|
||||||
#end
|
#end
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,6 +17,9 @@ import flash.Lib;
|
|||||||
#end
|
#end
|
||||||
|
|
||||||
|
|
||||||
|
@:access(lime.app.Application)
|
||||||
|
|
||||||
|
|
||||||
class Window {
|
class Window {
|
||||||
|
|
||||||
|
|
||||||
@@ -178,7 +181,7 @@ class Window {
|
|||||||
if (config.stencilBuffer)
|
if (config.stencilBuffer)
|
||||||
flags |= STENCIL_BUFFER;
|
flags |= STENCIL_BUFFER;
|
||||||
|
|
||||||
handle = lime_window_create (application.handle, flags);
|
handle = lime_window_create (application.__handle, flags);
|
||||||
#end
|
#end
|
||||||
|
|
||||||
MouseEventManager.registerWindow (this);
|
MouseEventManager.registerWindow (this);
|
||||||
|
|||||||
@@ -15,10 +15,11 @@ import lime.Assets;
|
|||||||
#if html5
|
#if html5
|
||||||
@:access(lime.graphics.opengl.GL)
|
@:access(lime.graphics.opengl.GL)
|
||||||
#end
|
#end
|
||||||
|
|
||||||
|
|
||||||
class Main extends Application {
|
class Main extends Application {
|
||||||
|
|
||||||
|
|
||||||
private var image:Image;
|
|
||||||
private var initialized:Bool;
|
private var initialized:Bool;
|
||||||
|
|
||||||
private var shaderProgram:GLProgram;
|
private var shaderProgram:GLProgram;
|
||||||
@@ -31,8 +32,6 @@ class Main extends Application {
|
|||||||
|
|
||||||
super ();
|
super ();
|
||||||
|
|
||||||
image = Assets.getImage ("assets/lime.png");
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -44,7 +43,8 @@ class Main extends Application {
|
|||||||
|
|
||||||
#if js
|
#if js
|
||||||
var image = new js.html.Image ();
|
var image = new js.html.Image ();
|
||||||
image.src = this.image.data.src;
|
image.src = Assets.getPath ("assets/lime.png");
|
||||||
|
element.style.backgroundColor = "#" + StringTools.hex (config.background, 6);
|
||||||
element.appendChild (image);
|
element.appendChild (image);
|
||||||
#end
|
#end
|
||||||
|
|
||||||
@@ -112,6 +112,8 @@ class Main extends Application {
|
|||||||
|
|
||||||
// Create buffers
|
// Create buffers
|
||||||
|
|
||||||
|
var image = Assets.getImage ("assets/lime.png");
|
||||||
|
|
||||||
var vertices = [
|
var vertices = [
|
||||||
|
|
||||||
image.width, image.height, 0,
|
image.width, image.height, 0,
|
||||||
@@ -159,6 +161,8 @@ class Main extends Application {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
initialized = true;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -167,7 +171,6 @@ class Main extends Application {
|
|||||||
if (!initialized) {
|
if (!initialized) {
|
||||||
|
|
||||||
initialize (context);
|
initialize (context);
|
||||||
initialized = true;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -175,6 +178,9 @@ class Main extends Application {
|
|||||||
|
|
||||||
case CANVAS (context):
|
case CANVAS (context):
|
||||||
|
|
||||||
|
var image = Assets.getImage ("assets/lime.png");
|
||||||
|
context.fillStyle = "#" + StringTools.hex (config.background, 6);
|
||||||
|
context.fillRect (0, 0, window.width, window.height);
|
||||||
context.drawImage (image.data, 0, 0, image.width, image.height);
|
context.drawImage (image.data, 0, 0, image.width, image.height);
|
||||||
|
|
||||||
case DOM (element):
|
case DOM (element):
|
||||||
@@ -183,12 +189,18 @@ class Main extends Application {
|
|||||||
|
|
||||||
case FLASH (sprite):
|
case FLASH (sprite):
|
||||||
|
|
||||||
|
var image = Assets.getImage ("assets/lime.png");
|
||||||
sprite.graphics.beginBitmapFill (image.data);
|
sprite.graphics.beginBitmapFill (image.data);
|
||||||
sprite.graphics.drawRect (0, 0, image.width, image.height);
|
sprite.graphics.drawRect (0, 0, image.width, image.height);
|
||||||
|
|
||||||
case OPENGL (gl):
|
case OPENGL (gl):
|
||||||
|
|
||||||
gl.clearColor (0, 1.0, 1.0, 1.0);
|
var r = ((config.background >> 16) & 0xFF) / 0xFF;
|
||||||
|
var g = ((config.background >> 8) & 0xFF) / 0xFF;
|
||||||
|
var b = (config.background & 0xFF) / 0xFF;
|
||||||
|
var a = ((config.background >> 24) & 0xFF) / 0xFF;
|
||||||
|
|
||||||
|
gl.clearColor (r, g, b, a);
|
||||||
gl.clear (gl.COLOR_BUFFER_BIT);
|
gl.clear (gl.COLOR_BUFFER_BIT);
|
||||||
|
|
||||||
var vertexAttribute = gl.getAttribLocation (shaderProgram, "aVertexPosition");
|
var vertexAttribute = gl.getAttribLocation (shaderProgram, "aVertexPosition");
|
||||||
@@ -199,8 +211,8 @@ class Main extends Application {
|
|||||||
|
|
||||||
var positionX = 0;
|
var positionX = 0;
|
||||||
var positionY = 0;
|
var positionY = 0;
|
||||||
var width = config.width;
|
var width = window.width;
|
||||||
var height = config.height;
|
var height = window.height;
|
||||||
|
|
||||||
var projectionMatrix = new Float32Array ([ 2 / width, 0, 0, 0, 0, 2 / height, 0, 0, 0, 0, -0.0001, 0, -1, -1, 1, 1 ]);
|
var projectionMatrix = new Float32Array ([ 2 / width, 0, 0, 0, 0, 2 / height, 0, 0, 0, 0, -0.0001, 0, -1, -1, 1, 1 ]);
|
||||||
|
|
||||||
|
|||||||
@@ -42,6 +42,7 @@ class ApplicationMain {
|
|||||||
config = {
|
config = {
|
||||||
|
|
||||||
antialiasing: Std.int (::WIN_ANTIALIASING::),
|
antialiasing: Std.int (::WIN_ANTIALIASING::),
|
||||||
|
background: Std.int (::WIN_BACKGROUND::),
|
||||||
borderless: ::WIN_BORDERLESS::,
|
borderless: ::WIN_BORDERLESS::,
|
||||||
depthBuffer: ::WIN_DEPTH_BUFFER::,
|
depthBuffer: ::WIN_DEPTH_BUFFER::,
|
||||||
fps: Std.int (::WIN_FPS::),
|
fps: Std.int (::WIN_FPS::),
|
||||||
|
|||||||
Reference in New Issue
Block a user