/
icons.go
96 lines (91 loc) · 3.5 KB
/
icons.go
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
package design
import (
"github.com/20kdc/CCUpdaterUI/frenyard"
"github.com/20kdc/CCUpdaterUI/frenyard/framework"
"github.com/20kdc/CCUpdaterUI/frenyard/integration"
)
// IconID represents a specific icon.
type IconID int32
// BlankIconID should be used when the spacing for an icon must be present but the icon itself mustn't.
const BlankIconID IconID = -1
// NullIconID should be used when no icon should be placed at all.
const NullIconID IconID = 0
// RunIconID is a right-facing triangle.
const RunIconID IconID = 1
// WarningIconID is a rounded triangle with '!' cut into it.
const WarningIconID IconID = 2
// GameIconID is an icon to represent the game.
const GameIconID IconID = 3
// DirectoryIconID is an icon with the 'folder' style.
const DirectoryIconID IconID = 4
// ModIconID is a gear.
const ModIconID IconID = 5
// ToolIconID is a claw hammer.
const ToolIconID IconID = 6
// BackIconID is a back arrow.
const BackIconID IconID = 7
// DriveIconID is a drive.
const DriveIconID IconID = 8
// MenuIconID is a sandwich.
const MenuIconID IconID = 9
// UpdatableIconID is an exclamation symbol (non-warning attention)
const UpdatableIconID IconID = 10
// InstalledIconID is a checkmark (success, correct, present)
const InstalledIconID IconID = 11
// Icons at 18DP
var icons18dp frenyard.Texture
var iconHeight18dp int32
// Icons at 24DP
var icons24dp frenyard.Texture
var iconHeight24dp int32
// Icons at 36DP
var icons36dp frenyard.Texture
var iconHeight36dp int32
func deSetupIcons() {
icons18dpImg := integration.CreateHardcodedPNGImage(icon72B64)
icons36dpImg := icons18dpImg
iconHeight18dp = 72
icons24dpImg := integration.CreateHardcodedPNGImage(icon96B64)
iconHeight24dp = 96
// Pass 1: 18 and 24dp (x4)
iconEffectiveScale := DesignScale / 4
for (iconEffectiveScale <= 0.5) && (iconHeight18dp > 9) {
icons18dpImg = integration.ScaleImageToHalfSize(icons18dpImg)
iconHeight18dp /= 2
icons24dpImg = integration.ScaleImageToHalfSize(icons24dpImg)
iconHeight24dp /= 2
iconEffectiveScale *= 2
}
// Pass 2: 36dp (x2)
iconHeight36dp = 72
iconEffectiveScale = DesignScale / 2
for (iconEffectiveScale <= 0.5) && (iconHeight36dp > 9) {
icons36dpImg = integration.ScaleImageToHalfSize(icons36dpImg)
iconHeight36dp /= 2
iconEffectiveScale *= 2
}
icons18dp = integration.GoImageToTexture(icons18dpImg, []integration.ColourTransform{integration.ColourTransformBlueToStencil});
icons24dp = integration.GoImageToTexture(icons24dpImg, []integration.ColourTransform{integration.ColourTransformBlueToStencil});
icons36dp = integration.GoImageToTexture(icons36dpImg, []integration.ColourTransform{integration.ColourTransformBlueToStencil});
}
// NewIconPtr returns a UILayoutElement for an icon at the given DP size. (Note: Only select values are supported.)
func NewIconPtr(colour uint32, iconID IconID, iconSizeDP int32) framework.UILayoutElement {
var spriteSize int32
var tex frenyard.Texture
if iconSizeDP == 18 {
spriteSize = iconHeight18dp
tex = icons18dp
} else if iconSizeDP == 24 {
spriteSize = iconHeight24dp
tex = icons24dp
} else if iconSizeDP == 36 {
spriteSize = iconHeight36dp
tex = icons36dp
} else {
panic("Unsupported icon height (check NewIconPtr calls)")
}
spriteSize2 := frenyard.Vec2i{X: spriteSize, Y: spriteSize}
index := int32(iconID) - 1
sprite := frenyard.Area2iFromVecs(frenyard.Vec2i{X: spriteSize * (index % 16), Y: spriteSize * (index / 16)}, spriteSize2)
return framework.ConvertElementToLayout(framework.NewTextureRectPtr(colour, tex, sprite, spriteSize2, frenyard.Alignment2i{}))
}