-
Notifications
You must be signed in to change notification settings - Fork 0
/
window.go
66 lines (57 loc) · 1.25 KB
/
window.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
package vgui
type Point struct {
X float32
Y float32
}
type Window struct {
X float32
Y float32
W float32
H float32
}
func NewWindow(x, y, w, h float32) Window {
return Window{x, y, w, h}
}
func (n Window) Inner(l, t, r, b float32) Window {
return Window{n.X + l, n.Y + t, n.W - r - l, n.H - t - b}
}
func (n Window) SplitH(t float32) (top Window, bottom Window) {
top = Window{n.X, n.Y, n.W, t - 1}
bottom = Window{n.X, n.Y + t, n.W, n.H - t}
return
}
func (n Window) SplitV(l float32) (left Window, right Window) {
left = Window{n.X, n.Y, l - 1, n.H}
right = Window{n.X + l, n.Y, n.W - l, n.H}
return
}
func (w Window) AlignedPoint(align Alignment) Point {
// Default is AlignLeft,AlignTop:
x := w.X
y := w.Y
// Respect alignment flags by moving the text point within the window:
if align&AlignCenter != 0 {
x += w.W * 0.5
} else if align&AlignRight != 0 {
x += w.W
}
if align&AlignMiddle != 0 {
y += w.H * 0.5
} else if align&AlignBottom != 0 {
y += w.H
}
return Point{x, y}
}
func (w Window) RadiusMin() float32 {
wr := w.W * 0.5
hr := w.H * 0.5
if wr < hr {
return wr
}
return hr
}
func (w Window) IsPointInside(p Point) bool {
//fmt.Println(p, "in", w)
return p.X >= w.X && p.X <= w.X+w.W &&
p.Y >= w.Y && p.Y <= w.Y+w.H
}