-
Notifications
You must be signed in to change notification settings - Fork 18
/
Window.hx
195 lines (159 loc) · 5.22 KB
/
Window.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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
package defold;
/**
Functions and constants to access the window, window event listeners
and screen dimming.
**/
@:native("_G.window")
extern final class Window
{
/**
Returns the current dimming mode set on a mobile device.
The dimming mode specifies whether or not a mobile device should dim the screen after a period without user interaction.
On platforms that does not support dimming, `DIMMING_UNKNOWN` is always returned.
@return The mode for screen dimming
**/
@:pure
@:native('get_dim_mode')
static function getDimMode():WindowDimmingMode;
/**
This returns the current window size (width and height).
@return The size of the window.
**/
@:pure
@:native('get_size')
static function getSize():WindowSize;
/**
Sets the dimming mode on a mobile device.
The dimming mode specifies whether or not a mobile device should dim the screen after a period without user interaction.
The dimming mode will only affect the mobile device while the game is in focus on the device, but not when the game is running in the background.
This function has no effect on platforms that does not support dimming.
@param mode The mode for screen dimming
**/
@:native('set_dim_mode')
static function setDimMode(mode:WindowDimmingMode):Void;
/**
Sets a window event listener.
@param callback A callback which receives info about window events. Can be null.
**/
static inline function setListener(callback:(event:WindowEvent, data:WindowEventData)->Void):Void
{
// 1. hide the reall callback parameter which expects a function with a "self" argument
// 2. ensure that the global self reference is present for the callback
setListener_((self, event, data) ->
{
untyped __lua__('_G._hxdefold_self_ = {0}', self);
callback(event, data);
untyped __lua__('_G._hxdefold_self_ = nil');
});
}
@:native('set_listener') private static function setListener_(callback:(Any, WindowEvent, WindowEventData)->Void):Void;
/**
Set the locking state for current mouse cursor on a PC platform.
This function locks or unlocks the mouse cursor to the center point of the window.
While the cursor is locked, mouse position updates will still be sent to the scripts as usual.
@param flag The lock state for the mouse cursor
**/
@:native('set_mouse_lock')
static function setMouseLock(flag:Bool):Void;
/**
This returns the current lock state of the mouse cursor.
@return The lock state
**/
@:pure
@:native('get_mouse_lock')
static function getMouseLock():Bool;
}
/**
Dimming mode is used to control whether or not a mobile device
should dim the screen after a period without user interaction.
**/
@:native("_G.window")
extern enum abstract WindowDimmingMode({})
{
/**
Dimming off
**/
@:native('DIMMING_OFF')
var Off;
/**
Dimming on
**/
@:native('DIMMING_ON')
var On;
/**
This mode indicates that the dim mode can't be determined,
or that the platform doesn't support dimming.
**/
@:native('DIMMING_UNKNOWN')
var Unknown;
}
/**
Window events, used in `Window.set_listener` callbacks.
**/
@:native("_G.window")
extern enum abstract WindowEvent({})
{
/**
Deiconified window event.
This event is sent to a window event listener when the game window or app screen
is restored after being iconified.
**/
@:native('WINDOW_EVENT_DEICONIFIED')
var Deiconified;
/**
Iconify window event.
This event is sent to a window event listener when the game window or app screen
is iconified (reduced to an application icon in a toolbar, application tray or similar).
**/
@:native('WINDOW_EVENT_ICONFIED')
var Iconified;
/**
Focus gained window event.
This event is sent to a window event listener when the game window or app screen has
gained focus.
This event is also sent at game startup and the engine gives focus to the game.
**/
@:native('WINDOW_EVENT_FOCUS_GAINED')
var FocusGained;
/**
Focus lost window event.
This event is sent to a window event listener when the game window or app screen has lost focus.
**/
@:native('WINDOW_EVENT_FOCUS_LOST')
var FocusLost;
/**
Resized window event.
This event is sent to a window event listener when the game window or app screen is resized.
The new size is passed along in the data field to the event listener.
**/
@:native('WINDOW_EVENT_RESIZED')
var Resized;
}
/**
Window event data, used in `Window.set_listener` callbacks.
**/
typedef WindowEventData =
{
/**
The width of a resize event. null otherwise.
**/
var ?width:Int;
/**
The height of a resize event. null otherwise.
**/
var ?height:Int;
}
/**
Window size data, returned from `Window.get_size()`.
**/
@:multiReturn extern final class WindowSize
{
/**
The window width.
**/
var width:Int;
/**
The window height.
**/
var height:Int;
}