/
PriApp.hx
162 lines (116 loc) · 3.67 KB
/
PriApp.hx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
package priori.app;
import haxe.ds.StringMap;
import priori.assets.AssetManagerEvent;
import priori.view.container.PriGroup;
import priori.assets.AssetManager;
import jQuery.Event;
import priori.event.PriEvent;
import haxe.Timer;
import priori.geom.PriGeomBox;
import jQuery.JQuery;
import priori.app.PriApp;
import priori.view.PriDisplay;
class PriApp extends PriGroup {
public static var PRIORI_MAP:StringMap<Dynamic> = new StringMap<Dynamic>();
private static var _g:PriApp;
private var _body:JQuery;
private var _window:JQuery;
private var _document:JQuery;
private var _fps:Int;
private var _delta:Float;
private var _timer:Timer;
private var _fullSetupCalled:Bool;
public function new() {
if (_g != null) {
throw "Do not create PriApp instance";
} else {
_g = this;
}
this._fps = 60;
super();
trace("** PRIORI APP **");
this.setupApp();
}
@noCompletion override private function set_width(value:Float) {
return value;
}
@noCompletion override private function get_width():Float {
return this.getAppSize().width;
}
@noCompletion override private function set_height(value:Float):Float {
return value;
}
@noCompletion override private function get_height():Float {
return this.getAppSize().height;
}
@noCompletion override private function set_x(value:Float) {
return 0;
}
@noCompletion override private function get_x():Float {
return 0;
}
@noCompletion override private function set_y(value:Float) {
return 0;
}
@noCompletion override private function get_y():Float {
return 0;
}
public function getMSUptate():Int {
return Std.int(1000 / this._fps);
}
private function setupApp():Void {
var box:PriGeomBox = this.getAppSize();
this.getElement().css("width", "100%");
this.getElement().css("height", "100%");
this.getElement().css("position", "fixed");
this.getWindow().resize(
function(e:Event):Void {
this.dispatchEvent(new PriEvent(PriEvent.RESIZE, false));
}
);
// prevent backspace
this.getDocument().keydown(function (e) {
if (e.which == 8 && !(new JQuery(e.target).is("input:not([readonly]):not([type=radio]):not([type=checkbox]), textarea, [contentEditable], [contentEditable=true]"))) {
e.preventDefault();
}
});
var body:JQuery = this.getBody();
body.css("border", "0px");
body.css("margin", "0px");
body.append(this.getElement());
this.dispatchEvent(new PriEvent(PriEvent.ADDED_TO_APP, true));
this.dispatchEvent(new PriEvent(PriEvent.RESIZE, false));
this.invalidate();
this.validate();
}
public function getAppSize():PriGeomBox {
var b:PriGeomBox = new PriGeomBox();
var e:JQuery = this.getWindow();
b.width = e.width();
b.height = e.height();
b.x = 0;
b.y = 0;
return b;
}
private function getDocument():JQuery {
return new JQuery(js.Browser.document);
}
private function getWindow():JQuery {
if (_window == null) {
_window = new JQuery(js.Browser.window);
}
return _window;
}
public function getBody():JQuery {
if (_body == null) {
_body = new JQuery("body");
}
return _body;
}
public static function g():PriApp {
if (_g == null) {
throw "Application not yet created";
}
return _g;
}
}