-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWindow.js
122 lines (106 loc) · 2.66 KB
/
Window.js
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
import * as Vec2 from 'foam-math/Vec2';
import * as Rect from 'foam-geom/Rect';
import EventDispatcher from 'foam-event/EventDispatcher';
/**
* Window
* @class Window
* @classdesc Window representation
* @extends EventDispatcher
*/
function Window(){
EventDispatcher.call(this);
this._bounds = Rect.create();
this._boundsNormalized = Rect.create();
this._center = [0,0];
this._aspectRatio = -1;
this._contentScale = -1;
this._fullscreen = false;
}
Window.prototype = Object.create(EventDispatcher.prototype);
/**
* Returns the window´s bounds.
* @param {number[]} [out] - Optional out
* @returns {number[]}
*/
Window.prototype.getBounds = function(out){
return Rect.set(out || Rect.create(),this._bounds);
};
/**
* Returns the window´s bounds normalized.
* @param {number[]} [out] - Optional out
* @returns {number[]}
*/
Window.prototype.getBoundsNormalized = function(out){
return Rect.set(out || Rect.create(),this._boundsNormalized);
};
/**
* Returns the window´s size.
* @param {number[]} [out] - Optional out
* @returns {number[]}
*/
Window.prototype.getSize = function(out){
return Vec2.set2(out || Vec2.create(),this._bounds[2],this._bounds[3]);
};
/**
* Returns the window´s width.
* @returns {number}
*/
Window.prototype.getWidth = function(){
return this._bounds[2];
};
/**
* Returns the windows´s height.
* @returns {number}
*/
Window.prototype.getHeight = function(){
return this._bounds[3];
};
/**
* Returns the window´s size normalized.
* @param {number[]} [out] - Optional out
* @returns {number[]}
*/
Window.prototype.getSizeNormalized = function(out){
return Vec2.set2(out || Vec2.create(),this._boundsNormalized[2],this._boundsNormalized[3]);
};
/**
* Returns the window´s bounds center.
* @param {number[]} [out] - Optional out
* @returns {number[]}
*/
Window.prototype.getCenter = function(out){
return Vec2.set(out || Vec2.create(),this._center);
};
/**
* Returns the window´s aspect ratio.
* @returns {number}
*/
Window.prototype.getAspectRatio = function(){
return this._aspectRatio;
};
/**
* Returns the window´s content scale.
* @returns {number}
*/
Window.prototype.getContentScale = function(){
return this._contentScale;
};
/**
* Returns true if the window is currently in fullscreen mode.
* @returns {boolean}
*/
Window.prototype.isFullscreen = function(){
return this._fullscreen;
};
Window.prototype.makeShared = function(){
Window.__sharedWindow = this;
};
/**
* Returns the shared window instance.
* @returns {Window|null}
*/
Window.sharedWindow = function(){
return Window.__sharedWindow;
};
Window.__sharedWindow = null;
export default Window;