Expose Application.window, and define config.background for all platforms

This commit is contained in:
Joshua Granick
2014-06-20 13:51:18 -07:00
parent 22ebfee143
commit ef4f191464
5 changed files with 56 additions and 31 deletions

View File

@@ -17,30 +17,29 @@ class Application {
public static var onUpdate = new Event<Int->Void> ();
private static var eventInfo = new UpdateEventInfo ();
private static var instance:Application;
private static var registered:Bool;
private static var __eventInfo = new UpdateEventInfo ();
private static var __instance:Application;
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 lastUpdate:Int;
private var windows:Array<Window>;
private var __handle:Dynamic;
public function new () {
instance = this;
__instance = this;
lastUpdate = 0;
windows = new Array ();
if (!registered) {
if (!__registered) {
registered = true;
__registered = true;
#if (cpp || neko)
lime_update_event_manager_register (__dispatch, eventInfo);
lime_update_event_manager_register (__dispatch, __eventInfo);
#end
}
@@ -98,7 +97,7 @@ class Application {
this.config = config;
#if (cpp || neko)
handle = lime_application_create (null);
__handle = lime_application_create (null);
#end
KeyEventManager.create ();
@@ -137,7 +136,7 @@ class Application {
public function exec ():Int {
#if (cpp || neko)
return lime_application_exec (handle);
return lime_application_exec (__handle);
#else
return 0;
#end
@@ -177,16 +176,15 @@ class Application {
windows[0].stats.begin ();
#end
instance.update (eventInfo.deltaTime);
onUpdate.dispatch (eventInfo.deltaTime);
__instance.update (__eventInfo.deltaTime);
onUpdate.dispatch (__eventInfo.deltaTime);
}
@:noCompletion private function __triggerFrame (?_):Void {
eventInfo.deltaTime = 16; //TODO
__eventInfo.deltaTime = 16; //TODO
__dispatch ();
Renderer.dispatch ();
@@ -198,6 +196,13 @@ class Application {
}
private inline function get_window ():Window {
return windows[0];
}
#if (cpp || neko)
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);

View File

@@ -15,7 +15,11 @@ import flash.Lib;
#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 {
@@ -111,13 +115,13 @@ class Renderer {
private static function dispatch ():Void {
for (window in Application.instance.windows) {
for (window in Application.__instance.windows) {
if (window.currentRenderer != null) {
var context = window.currentRenderer.context;
Application.instance.render (context);
Application.__instance.render (context);
onRender.dispatch (context);
window.currentRenderer.flip ();
@@ -127,7 +131,7 @@ class Renderer {
}
#if (js && stats)
Application.instance.windows[0].stats.end ();
Application.__instance.windows[0].stats.end ();
#end
}

View File

@@ -17,6 +17,9 @@ import flash.Lib;
#end
@:access(lime.app.Application)
class Window {
@@ -178,7 +181,7 @@ class Window {
if (config.stencilBuffer)
flags |= STENCIL_BUFFER;
handle = lime_window_create (application.handle, flags);
handle = lime_window_create (application.__handle, flags);
#end
MouseEventManager.registerWindow (this);

View File

@@ -15,10 +15,11 @@ import lime.Assets;
#if html5
@:access(lime.graphics.opengl.GL)
#end
class Main extends Application {
private var image:Image;
private var initialized:Bool;
private var shaderProgram:GLProgram;
@@ -31,8 +32,6 @@ class Main extends Application {
super ();
image = Assets.getImage ("assets/lime.png");
}
@@ -44,7 +43,8 @@ class Main extends Application {
#if js
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);
#end
@@ -112,6 +112,8 @@ class Main extends Application {
// Create buffers
var image = Assets.getImage ("assets/lime.png");
var vertices = [
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) {
initialize (context);
initialized = true;
}
@@ -175,6 +178,9 @@ class Main extends Application {
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);
case DOM (element):
@@ -183,12 +189,18 @@ class Main extends Application {
case FLASH (sprite):
var image = Assets.getImage ("assets/lime.png");
sprite.graphics.beginBitmapFill (image.data);
sprite.graphics.drawRect (0, 0, image.width, image.height);
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);
var vertexAttribute = gl.getAttribLocation (shaderProgram, "aVertexPosition");
@@ -199,8 +211,8 @@ class Main extends Application {
var positionX = 0;
var positionY = 0;
var width = config.width;
var height = config.height;
var width = window.width;
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 ]);

View File

@@ -42,6 +42,7 @@ class ApplicationMain {
config = {
antialiasing: Std.int (::WIN_ANTIALIASING::),
background: Std.int (::WIN_BACKGROUND::),
borderless: ::WIN_BORDERLESS::,
depthBuffer: ::WIN_DEPTH_BUFFER::,
fps: Std.int (::WIN_FPS::),