forked from microsoft/microcode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
iconeditor.ts
47 lines (45 loc) · 1.48 KB
/
iconeditor.ts
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
namespace microcode {
export function iconEditor(
image5x5: Image,
picker: Picker,
onHide: () => void,
onDelete?: () => void
) {
const getColor = (col: number, row: number) => {
return image5x5.getPixel(col, row)
? TID_MODIFIER_COLOR_RED
: TID_MODIFIER_COLOR_DARKPURPLE
}
for (let row = 0; row < 5; row++) {
let btns: PickerButtonDef[] = []
for (let col = 0; col < 5; col++) {
btns.push({ icon: getColor(col, row) })
}
picker.addGroup({ label: row.toString(), btns })
}
picker.show(
{
onClick: (iconId: any, button: PickerButton) => {
let on = button.getIcon() === TID_MODIFIER_COLOR_RED
let row = 0,
col = 0
for (; row < 5; row++) {
let index =
button.picker.groups[row].buttons.indexOf(button)
if (index >= 0) {
col = index
break
}
}
image5x5.setPixel(col, row, on ? 0 : 1)
button.setIcon(getColor(col, row))
picker.draw()
},
onHide,
onDelete,
title: "LEDs",
},
false
)
}
}