-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathwindow.um
More file actions
307 lines (256 loc) · 6.46 KB
/
Copy pathwindow.um
File metadata and controls
307 lines (256 loc) · 6.46 KB
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
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
import (
"audio.um"
"canvas.um"
"image.um"
"placeholders.um"
"rect.um"
"signal.um"
"std.um"
"th.um"
)
var (
start, clockOffset: real
fpsLimit: int = 60
)
//~~Cursor types
type Cursor* = enum {
system = 0 // Default system cursor
arrow // Normal cursor; Arrow cursor
iBeam // 'I' text cursor; I-Beam
crosshair // '+' cursor; Select region cursor
finger // Index finger pointing cursor; Click cursor
sizeEW // '<->' cursor; Resize width cursor; Resize horizontally cursor; East-West resize cursor
sizeNS // Resize height cursor; Resize vertically cursor; North-South resize cursor
sizeNWSE // Resize width and height from the right side cursor; Northwest-Southeast resize cursor
sizeSWNE // Resize width and height from the left side cursor; Southwest-Northeast resize cursor
sizeAll // Resize all cursor; Move cursor
no // '(/)' cursor; Disabled cursor; Disallowed cursor
count_
}
//~~
//~~Window setup options
type WindowSetupOptions* = struct {
hidden: bool // hide by default
}
//~~Window dimensions
var (
w*, h*: int32
)
//~~
//~~Viewport size
var wp*: th::Vf2
//~~
//~~signal OnFrame
var onFrame*: signal::Signal
//~~
//~~signal OnDestroy
var onDestroy*: signal::Signal
//~~
fn umth_window_setup(title: str, w, h: int)
fn umth_window_set_hidden(hidden: bool)
fn umth_window_get_dimensions(w, h: ^int32)
fn umth_window_set_viewport(dm: th::Vf2)
//~~fn setViewport
// Sets the dimensions of the viewport. The dimensions are saved in the `wp`
// variable.
//
// `dm`
// : dimension of the viewport
fn setViewport*(dm: th::Vf2) {
//~~
wp = dm
umth_window_set_viewport(dm)
}
fn setIcon*(img: image::Image)
fn umth_window_is_dpi_enabled(): bool
//~~fn isDpiEnabled
// Returns true if DPI awareness was enabled
fn isDpiEnabled*(): bool {
//~~
return umth_window_is_dpi_enabled()
}
fn umth_window_get_dpi_scale(): th::fu
//~~fn getDpiScaleFactor
// Returns the DPI scaling of the current window.
// If `dpiAware` was not enabled in window setup, this function will return 1.0 (default scaling).
fn getDpiScaleFactor*(): th::fu {
//~~
return umth_window_get_dpi_scale()
}
// 0 = other/unknown
// 1 = linux
// 2 = windows
// 3 = macos (unsupported currently)
// 4 = emscripten
fn umth_window_get_platform_id(): th::Platform
//~~fn setup
// Sets up the engine and opens a window.
fn setup*(title: str = "tophat game", width: int = 400, height: int32 = 400, options: WindowSetupOptions = {}) {
//~~
w, h = width, height
umth_window_setup(title, width, height)
if options.hidden {
umth_window_set_hidden(true)
}
th::platform = umth_window_get_platform_id()
audio::__setup()
placeholders::__setup()
setIcon(placeholders::icon)
clockOffset = std::clock() * 1000
start = std::clock() * 1000
setViewport({width, height})
}
//~~fn hide
// Hides/shows the window.
fn hide*(hide: bool) {
//~~
umth_window_set_hidden(hide)
}
fn cycle(delta: real) {
umth_window_set_viewport(wp)
th::delta = trunc(delta*1000.0)
if th::delta == 0 {
th::delta = 1
}
start = std::clock()*1000
th::time = round(start - clockOffset)
umth_window_get_dimensions(&w, &h)
audio::__cycle()
canvas::drawRect(th::white, rect::mk(0, 0, wp.x, wp.y))
}
fn setViewportOffset*(s: th::Vf2)
fn getViewportOffset*(): th::Vf2
fn drawClear() {
of := getViewportOffset()
setViewportOffset({})
canvas::drawRect(th::black, rect::mk(-4 * wp.x, 0, 4 * wp.x, wp.y))
canvas::drawRect(th::black, rect::mk(0, -4 * wp.y, wp.x, 4 * wp.y))
canvas::drawRect(th::black, rect::mk(wp.x, 0, 4 * wp.x, wp.y))
canvas::drawRect(th::black, rect::mk(0, wp.y, wp.x, 4 * wp.y))
setViewportOffset(of)
}
fn umth_frame_callback*(delta: real) {
cycle(delta)
onFrame.emit(null)
drawClear()
}
fn umth_destroy_callback*() {
onDestroy.emit(null)
}
fn umth_window_set_fullscreen(fullscreen: bool)
fn umth_window_get_fullscreen(): bool
//~~fn setFullscreen
// Makes window go full screen
fn setFullscreen*(fullscreen: bool) {
//~~
umth_window_set_fullscreen(fullscreen)
}
//~~fn isFullscreen
// Returns true if window is fullscreen
fn isFullscreen*(): bool {
//~~
return umth_window_get_fullscreen()
}
//~~fn getDims
// Returns dimensions of the window in screen pixels.
fn getDims*(): th::Vf2 {
//~~
return {w, h}
}
fn umth_window_set_target_fps(fps: int)
//~~fn setTargetFps
// Sets the fps limit.
//
// `fps`
// : amount of fps the limit should be set to
//
fn setTargetFps*(fps: int) {
//~~
fpsLimit = fps
umth_window_set_target_fps(fps)
}
fn umth_window_set_title(title: str)
//~~fn setTitle
// Sets the title of the window.
fn setTitle*(title: str) {
//~~
umth_window_set_title(title)
}
fn umth_window_set_dims(dm: th::Vf2)
//~~fn setDims
// Sets the dimensions of the window.
//
// `dm`
// : the target dimensions in screen pixels
fn setDims*(dm: th::Vf2) {
//~~
umth_window_set_dims(dm)
}
fn umth_window_set_icon(img: image::Image)
//~~fn setIcon
// Sets the window icon.
fn setIcon*(img: image::Image) {
//~~
if !img.validate() {
th::__error("invalid image")
}
umth_window_set_icon(img)
}
fn umth_window_show_cursor(show: bool)
//~~fn showCursor
// Show or hide the cursor, linux only.
fn showCursor*(show: bool) {
//~~
umth_window_show_cursor(show)
}
fn umth_window_freeze_cursor(freeze: bool)
//~~fn freezeCursor
// Freezes the cursor in place. `input.getMouseDelta` will still report mouse
// movements. The cursor will be automatically hidden.
fn freezeCursor*(freeze: bool) {
//~~
showCursor(freeze)
umth_window_freeze_cursor(freeze)
}
fn umth_window_set_cursor(cursor: Cursor)
//~~fn setCursor
// Allows you to set the displaying cursor. Refer to the cursors section for available cursors.
fn setCursor*(cursor: Cursor) {
//~~
umth_window_set_cursor(cursor);
}
fn umth_window_request_exit()
//~~fn requestExit
// Requests the window to close.
fn requestExit*() {
//~~
umth_window_request_exit()
}
fn umth_window_set_clipboard(s: str)
//~~fn setClipboard
// Puts a string to the system clipboard.
fn setClipboard*(s: str) {
//~~
umth_window_set_clipboard(s)
}
fn umth_window_get_clipboard(): str
//~~fn getClipboard
// Gets a string from the system clipboard.
fn getClipboard*(): str {
//~~
return umth_window_get_clipboard()
}
fn umth_window_set_viewport_offset(s: th::Vf2)
//~~fn setViewportOffset
// Sets the offset of the viewport.
fn setViewportOffset*(s: th::Vf2) {
//~~
umth_window_set_viewport_offset(s)
}
fn umth_window_get_viewport_offset(): th::Vf2
//~~fn getViewportOffset
// Gets the offset of the viewport (as set by `setViewportOffset`)
fn getViewportOffset*(): th::Vf2 {
//~~
return umth_window_get_viewport_offset()
}