-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathhome.ts
More file actions
173 lines (165 loc) · 6.17 KB
/
home.ts
File metadata and controls
173 lines (165 loc) · 6.17 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
namespace microcode {
import Screen = user_interface_base.Screen
import CursorScene = user_interface_base.CursorScene
import PickerButtonDef = user_interface_base.PickerButtonDef
import Button = user_interface_base.Button
import ButtonStyles = user_interface_base.ButtonStyles
import AppInterface = user_interface_base.AppInterface
import font = user_interface_base.font
const addSettings = false
const buttonStart = addSettings ? -60 : -40
export class Home extends CursorScene {
constructor(app: AppInterface) {
super(app)
}
/* override */ startup() {
super.startup()
this.navigator.setBtns([
[
new Button({
parent: null,
style: ButtonStyles.Transparent,
icon: "edit_program",
ariaId: "C0",
x: buttonStart,
y: 30,
onClick: () => {
stopProgram()
this.app.popScene()
this.app.pushScene(new Editor(this.app))
},
}),
new Button({
parent: null,
style: ButtonStyles.Transparent,
icon: "smiley_buttons",
ariaId: "C1",
x: buttonStart + 40,
y: 30,
onClick: () => {
this.app.pushScene(new SamplesGallery(this.app))
},
}),
new Button({
parent: null,
style: ButtonStyles.Transparent,
icon: "largeDisk",
ariaId: "load",
x: buttonStart + 80,
y: 30,
onClick: () => {
this.pickDiskSLot()
},
}),
].concat(
addSettings
? [
new Button({
parent: null,
style: ButtonStyles.Transparent,
icon: "largeSettingsGear",
ariaId: "settings",
x: buttonStart + 120,
y: 30,
onClick: () => {
const gcs = new MicroCodeSettings(
this.app
)
this.app.pushScene(gcs)
},
}),
]
: []
),
])
}
private pickDiskSLot() {
const btns: PickerButtonDef[] = diskSlots().map(slot => {
return {
icon: slot,
}
})
this.picker.setGroup(btns)
this.picker.show({
title: accessibility.ariaToTooltip("load"),
onClick: index => {
let buf = settings.readBuffer(btns[index].icon)
if (!buf) {
// handles case where nothing is in slot
buf = Buffer.create(6)
for (let i = 0; i < 5; ++i) buf[i] = Tid.END_OF_PAGE
buf[5] = Tid.END_OF_PROG
}
settings.writeBuffer(SAVESLOT_AUTO, buf)
this.app.popScene()
this.app.pushScene(new Editor(this.app))
},
})
}
/* override */ activate() {
super.activate()
this.backgroundColor = 15
// docs.setup(this.app)
}
private drawVersion() {
const font = bitmaps.font5
Screen.print(
microcode.VERSION,
Screen.RIGHT_EDGE - font.charWidth * microcode.VERSION.length,
Screen.BOTTOM_EDGE - font.charHeight - 1,
0xb,
font
)
}
private yOffset = -Screen.HEIGHT >> 1
draw() {
Screen.fillRect(
Screen.LEFT_EDGE,
Screen.TOP_EDGE,
Screen.WIDTH,
Screen.HEIGHT,
0xc
)
this.yOffset = Math.min(0, this.yOffset + 2)
const t = control.millis()
const dy = this.yOffset == 0 ? (Math.idiv(t, 800) & 1) - 1 : 0
const margin = 2
const OFFSET = (Screen.HEIGHT >> 1) - wordLogo.height - margin
const y = Screen.TOP_EDGE + OFFSET + dy
Screen.drawTransparentImage(
wordLogo,
Screen.LEFT_EDGE + ((Screen.WIDTH - wordLogo.width) >> 1) + dy,
y + this.yOffset
)
Screen.drawTransparentImage(
icondb.microbitLogo,
Screen.LEFT_EDGE +
((Screen.WIDTH - icondb.microbitLogo.width) >> 1) +
dy,
y - wordLogo.height + this.yOffset + margin
)
if (!this.yOffset) {
const tagline = resolveTooltip("tagline")
// const tagline = "" // TODO: fix this
Screen.print(
tagline,
Screen.LEFT_EDGE +
((Screen.WIDTH + wordLogo.width) >> 1) +
dy -
font.charWidth * tagline.length,
Screen.TOP_EDGE +
OFFSET +
wordLogo.height +
dy +
this.yOffset +
1,
0xb,
font
)
}
this.navigator.drawComponents()
this.drawVersion()
super.draw()
}
}
}