-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathui.go
177 lines (148 loc) · 3.06 KB
/
ui.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
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
174
175
176
177
package main
import (
"github.com/veandco/go-sdl2/sdl"
)
const (
menuX = 16
menuY = 16
)
type Grid struct {
size F2
cell F2
}
func (g *Grid) GetBounds(n F2, m F2) Bounds {
return Bounds{g.GetLocation(n), g.GetSize(m)}
}
func (g *Grid) Draw(graphics *Graphics) {
// divX := g.size.X / g.cell.X
// for i := 0.0; i < divX; i++ {
// graphics.Color(0.1, 0.08, 0.08, 1)
// graphics.Line(F3{(g.cell.X) * i, 0, 0}, F3{g.cell.X * i, g.size.Y, -1})
// }
// divY := g.size.Y / g.cell.Y
// for i := 0.0; i < divY; i++ {
// graphics.Color(0.1, 0.08, 0.08, 1)
// graphics.Line(F3{0, (g.cell.Y) * i, 0}, F3{g.size.X, g.cell.Y * i, 2})
// }
}
func (g *Grid) GetLocation(point F2) F2 {
return F2{point.X * g.cell.X, point.Y * g.cell.Y}
}
func (g *Grid) GetSize(size F2) F2 {
return F2{size.X * g.cell.X, size.Y * g.cell.Y}
}
type Color struct {
r, g, b, a float64
}
func From32ARGB(r, g, b, a float64) Color {
c := Color{
r: (1 / 255) * r,
g: (1 / 255) * g,
b: (1 / 255) * b,
a: (1 / 255) * a,
}
return c
}
type ListItem interface {
Draw(g *Graphics, size F2)
}
type List struct {
label string
elements []*Item
location F2
size F2
}
func (l *List) GetName() string {
return l.label
}
func NewList(label string, location F2, size F2) List {
return List{
label: label,
elements: nil,
location: location,
size: size,
}
}
func (l *List) GetLocation() F2 {
return l.location
}
func (l *List) GetSize() F2 {
return l.size
}
func (l *List) Configure() {
l.elements = make([]*Item, 0)
}
func (l *List) HandleEvent(event sdl.Event) {
}
func (l *List) Update() {
}
func (l *List) AddItem(item *Item) {
l.elements = append(l.elements, item)
}
func (l *List) Draw(g *Graphics) {
for _, item := range l.elements {
item.Draw(g, F2{l.size.X, float64(28)})
g.Translate(F3{0, 28, 0})
}
}
type Item struct {
label string
value string
graph *[]float64
color Color
indent int
}
func (u *Item) BindGraph(ptr *[]float64) {
u.graph = ptr
}
func DrawWindow(g *Graphics, name string, location F2, size F2) {
g.Color((1/255)*43, (1/255)*45, (1/255)*45, 1)
g.Rect(
F2{
X: 1,
Y: 1,
},
F2{
X: size.X - 2,
Y: size.Y - 2,
})
g.Color((1/255)*43, (1/255)*45, (1/255)*45, 1)
g.FillRect(
F2{
X: 1,
Y: 1,
},
F2{
X: size.X - 2,
Y: 28,
})
g.Text(name, location)
}
func NewItem(label string, value string) *Item {
return &Item{
label: label,
value: value,
indent: 0,
}
}
func (u *Item) Draw(g *Graphics, size F2) {
color := 1 / 255.0
if u.graph != nil {
for i, p := range *u.graph {
if float64(i) <= size.X-4 {
g.Color(color*128, color*128, color*128, 0.6)
g.Line(F3{float64(i)*0.5 + 2, size.Y, 0}, F3{float64(i)*0.5 + 2, size.Y - p*size.Y, 0})
}
}
}
g.Color(color*66, color*66, color*66, 1)
g.Line(F3{1, size.Y, 0}, F3{size.X - 2, size.Y, 0})
g.Color(color*255, color*255, color*255, 1)
g.Text(u.label, F2{8, 6})
length, _, _ := g.font.SizeUTF8(u.value)
g.Color(color*255, color*255, color*255, 1)
g.Text(u.value, F2{size.X - float64(length/2) - 8, 6})
}
func (u *Item) Indent() {
u.indent++
}