Fix Windows, minor refactor
This commit is contained in:
committed by
Joshua Granick
parent
d7064bd064
commit
dcad37447e
@@ -6,18 +6,20 @@ import lime.system.*;
|
||||
import lime.ui.*;
|
||||
|
||||
|
||||
class Application implements IKeyEventListener implements IMouseEventListener implements IRenderEventListener implements ITouchEventListener implements IUpdateEventListener implements IWindowEventListener {
|
||||
class Application implements IKeyEventListener implements IMouseEventListener implements ITouchEventListener implements IWindowEventListener {
|
||||
|
||||
|
||||
public var handle:Dynamic;
|
||||
|
||||
private var config:Config;
|
||||
private var delegate:EventDelegate;
|
||||
private var lastUpdate:Int;
|
||||
private var windows:Array<Window>;
|
||||
|
||||
|
||||
public function new () {
|
||||
|
||||
delegate = new EventDelegate (this);
|
||||
lastUpdate = 0;
|
||||
windows = new Array ();
|
||||
|
||||
@@ -47,11 +49,12 @@ class Application implements IKeyEventListener implements IMouseEventListener im
|
||||
new UpdateEventManager ();
|
||||
new WindowEventManager ();
|
||||
|
||||
RenderEventManager.addEventListener (delegate);
|
||||
UpdateEventManager.addEventListener (delegate);
|
||||
|
||||
KeyEventManager.addEventListener (this);
|
||||
MouseEventManager.addEventListener (this);
|
||||
RenderEventManager.addEventListener (this);
|
||||
TouchEventManager.addEventListener (this);
|
||||
UpdateEventManager.addEventListener (this);
|
||||
WindowEventManager.addEventListener (this);
|
||||
|
||||
var window = new Window (this);
|
||||
@@ -85,13 +88,25 @@ class Application implements IKeyEventListener implements IMouseEventListener im
|
||||
public function onMouseDown (event:MouseEvent):Void {}
|
||||
public function onMouseMove (event:MouseEvent):Void {}
|
||||
public function onMouseUp (event:MouseEvent):Void {}
|
||||
public function onRender (event:RenderEvent):Void {}
|
||||
public function onTouchEnd (event:TouchEvent):Void {}
|
||||
public function onTouchMove (event:TouchEvent):Void {}
|
||||
public function onTouchStart (event:TouchEvent):Void {}
|
||||
public function onUpdate (event:UpdateEvent):Void {}
|
||||
public function onWindowActivate (event:WindowEvent):Void {}
|
||||
public function onWindowDeactivate (event:WindowEvent):Void {}
|
||||
public function onWindowDeactivate (event:WindowEvent):Void { }
|
||||
|
||||
|
||||
public function render ():Void {
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
public function update ():Void {
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
#if (cpp || neko)
|
||||
@@ -102,3 +117,44 @@ class Application implements IKeyEventListener implements IMouseEventListener im
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@:access(lime.app.Application)
|
||||
private class EventDelegate implements IRenderEventListener implements IUpdateEventListener {
|
||||
|
||||
|
||||
private var application:Application;
|
||||
|
||||
|
||||
public function new (application:Application) {
|
||||
|
||||
this.application = application;
|
||||
|
||||
}
|
||||
|
||||
|
||||
public function onRender (event:RenderEvent):Void {
|
||||
|
||||
application.render ();
|
||||
|
||||
for (window in application.windows) {
|
||||
|
||||
if (window.currentRenderer != null) {
|
||||
|
||||
window.currentRenderer.flip ();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
public function onUpdate (event:UpdateEvent):Void {
|
||||
|
||||
application.update ();
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -5,23 +5,32 @@ import lime.system.System;
|
||||
import lime.ui.Window;
|
||||
|
||||
|
||||
class Renderer implements IRenderEventListener {
|
||||
class Renderer {
|
||||
|
||||
|
||||
public var handle:Dynamic;
|
||||
|
||||
private var window:Window;
|
||||
|
||||
|
||||
public function new (window:Window) {
|
||||
|
||||
this.window = window;
|
||||
this.window.currentRenderer = this;
|
||||
|
||||
}
|
||||
|
||||
|
||||
public function create ():Void {
|
||||
|
||||
#if (cpp || neko)
|
||||
handle = lime_renderer_create (window.handle);
|
||||
RenderEventManager.addEventListener (this, -99999999);
|
||||
#end
|
||||
|
||||
}
|
||||
|
||||
|
||||
public function onRender (event:RenderEvent):Void {
|
||||
public function flip ():Void {
|
||||
|
||||
#if (cpp || neko)
|
||||
lime_renderer_flip (handle);
|
||||
|
||||
@@ -4,6 +4,7 @@ package lime.ui;
|
||||
import lime.app.Application;
|
||||
import lime.app.Config;
|
||||
import lime.app.UpdateEventManager;
|
||||
import lime.graphics.Renderer;
|
||||
import lime.graphics.RenderEvent;
|
||||
import lime.graphics.RenderEventManager;
|
||||
import lime.system.System;
|
||||
@@ -22,6 +23,7 @@ class Window {
|
||||
|
||||
public static var instance:Window;
|
||||
|
||||
public var currentRenderer:Renderer;
|
||||
#if js
|
||||
public var element:HtmlElement;
|
||||
#end
|
||||
@@ -189,6 +191,12 @@ class Window {
|
||||
UpdateEventManager.registerWindow (this);
|
||||
WindowEventManager.registerWindow (this);
|
||||
|
||||
if (currentRenderer != null) {
|
||||
|
||||
currentRenderer.create ();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -2,12 +2,12 @@
|
||||
#define LIME_UI_WINDOW_H
|
||||
|
||||
|
||||
#include <app/Application.h>
|
||||
|
||||
#ifdef CreateWindow
|
||||
#undef CreateWindow
|
||||
#endif
|
||||
|
||||
#include <app/Application.h>
|
||||
|
||||
|
||||
namespace lime {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user