-
Notifications
You must be signed in to change notification settings - Fork 0
/
focusrect.go
94 lines (68 loc) · 1.82 KB
/
focusrect.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
package glui
import (
"github.com/veandco/go-sdl2/sdl"
)
type FocusRect struct {
t int
anchor Element
tris []uint32 // 8 tris
Root *Frame
}
func newFocusRect(frame *Frame) *FocusRect {
tris := frame.P1.Alloc(9*2) // the center quad is hidden, but allows for easy indexing
e := &FocusRect{0, nil, tris, frame}
e.setTypesAndTCoords()
return e
}
func (e *FocusRect) setTypesAndTCoords() {
x0, y0 := e.Root.P1.Skin.FocusOrigin()
e.t = e.Root.P1.Skin.FocusThickness()
e.Root.P1.setBorderedElementTypesAndTCoords(e.tris, x0, y0, e.t, sdl.Color{0xff, 0xff, 0xff, 0xff})
for _, tri := range e.tris {
e.Root.P1.SetTriType(tri, VTYPE_HIDDEN)
}
tri0 := e.tris[8]
tri1 := e.tris[9]
e.Root.P1.SetTriType(tri0, VTYPE_HIDDEN)
e.Root.P1.SetTriType(tri1, VTYPE_HIDDEN)
}
func (e *FocusRect) Show(anchor Element) {
e.anchor = anchor
for i, tri := range e.tris {
if i < 8 || i > 9 {
e.Root.P1.SetTriType(tri, VTYPE_SKIN)
}
}
}
func (e *FocusRect) Hide() {
e.anchor = nil
for _, tri := range e.tris {
e.Root.P1.SetTriType(tri, VTYPE_HIDDEN)
}
}
func (e *FocusRect) CalcPos(maxWidth, maxHeight, maxZIndex int) {
if e.anchor == nil || e.anchor.Deleted() {
e.Hide()
return
}
// z should be pretty high
zId := e.anchor.ZIndex()
zId = e.Root.Menu.ZIndex() - 1
z := normalizeZIndex(zId, maxZIndex)
r := e.anchor.Rect()
e.Root.P1.setBorderedElementPos(e.tris, r.W + e.t*2, r.H + e.t*2, e.t, z)
for _, tri := range e.tris {
e.Root.P1.TranslateTri(tri, r.X - e.t, r.Y - e.t, 0.0)
}
}
func (e *FocusRect) Translate(dx, dy int) {
for _, tri := range e.tris {
e.Root.P1.TranslateTri(tri, dx, dy, 0.0)
}
}
func (e *FocusRect) Animate(tick uint64) {
// doesnt do anything yet
}
func (e *FocusRect) IsOwnedBy(el Element) bool {
return e.anchor == el
}