-
Notifications
You must be signed in to change notification settings - Fork 0
/
skin.go
57 lines (41 loc) · 1.19 KB
/
skin.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
package glui
import (
"math"
"github.com/veandco/go-sdl2/sdl"
)
// each skin type returns a matrix of pixel colors (i.e. a bitmap)
// the byte order is row major, col minor, then color channels
type Skin interface {
BGColor() sdl.Color
SelColor() sdl.Color
Button() []byte // len(Button()) = N => 2*n+1 = sqrt(N)
ButtonPressed() []byte // same length as Button()
Corner() []byte // for tab lips
Input() []byte
Focus() []byte
Inset() []byte
Bar() []byte // vertical bar, transposed to form horizontal bar
RadioOff() []byte // square shape
RadioOn() []byte // square shape
Tick() []byte // square shape, determines size of checbox
ScrollbarTrack() []byte // 1xn
}
func calcSquareSkinSize(d []byte) int {
sqrtN := math.Sqrt(float64(len(d)/4))
if math.Mod(sqrtN, 1.0) != 0.0 {
panic("incorrect skin size")
}
return int(sqrtN)
}
func calcSkinThickness(d []byte) int {
sqrtN := calcSquareSkinSize(d)
t := (sqrtN - 1)/2
return t
}
func calcSkinThicknessCheckRef(d []byte, tRef int) int {
t := calcSkinThickness(d)
if t != tRef {
panic("skin border not equal to reference")
}
return t
}