-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathmain.um
102 lines (86 loc) · 1.67 KB
/
main.um
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
import (
"canvas.um"
"font.um"
"image.um"
"input.um"
"rect.um"
"signal.um"
"std.um"
"th.um"
"window.um"
)
var (
logo: image::Image
fg: uint32
bg: uint32
lines: []str
loadedFont: font::Font
)
fn onFrame(args: []any) {
canvas::drawRect(bg, rect::mk(0, 0, window::wp.x, window::wp.y))
p := th::Vf2{ 0, 1 }
if !input::isPressed(input::Key.leftAlt) {
for i in lines {
s := 1
if i == 1 {
s = 2
}
canvas::drawText(
lines[i],
th::Vf2{
(window::wp.x - canvas::textSize(lines[i], s).x) / 2,
p.y},
fg, s)
p.y += 6 * s
}
} else {
for i in lines {
s := 1*(1/4.0)
if i == 1 {
s = 2*(1/4.0)
}
loadedFont.draw(
lines[i],
th::Vf2{
(window::wp.x - loadedFont.measure(lines[i]).x * s) / 2,
p.y},
fg, s)
p.y += 16 * s
}
}
if input::isJustPressed(input::Key.enter) {
if th::platform == th::Platform.windows {
std::system("explorer \"https://tophat2d.dev/\"")
} else if th::platform == th::Platform.linux {
std::system("xdg-open https://tophat2d.dev/")
}
}
const s = 1.5
logo.draw(th::Transform{
p: p.add(window::wp.sub(p).sub(logo.getDims().mulf(s)).divf(2)),
s: th::vf2f(s)})
}
fn init*() {
window::setup("Hello world", 600, 600)
window::setViewport(th::Vf2{ 100, 100 })
var err: std::Err
loadedFont, err = font::load("res://etc/roboto.ttf", 16)
std::exitif(err)
logo, err = image::load("res://etc/logo/logo-normal-white.png")
std::exitif(err)
fg = 0xadadd5ff
bg = 0x262626ff
lines = []str {
"WELCOME TO",
"TOPHAT",
"",
"EXAMPLES ARE IN",
"THE examples/",
"DIRECTORY",
"",
"PRESS ENTER TO",
"OPEN THE",
"HOMEPAGE"
}
window::onFrame.register(onFrame)
}