forked from dmitmel/CCUpdaterUI
/
uiLibTest.go
68 lines (60 loc) · 2.11 KB
/
uiLibTest.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
package framework
import (
"fmt"
"github.com/20kdc/CCUpdaterUI/frenyard"
)
// UIEventDebugger is a simple test element to debug events.
type UIEventDebugger struct {
UIElementComponent
_mousePos frenyard.Vec2i
}
// NewUIEventDebuggerPtr creates a UIEventDebugger
func NewUIEventDebuggerPtr(size frenyard.Vec2i) *UIEventDebugger {
return &UIEventDebugger{NewUIElementComponent(size), frenyard.Vec2i{-8, -8}}
}
// FyENormalEvent implements UIElement.FyENormalEvent
func (cr *UIEventDebugger) FyENormalEvent(ev frenyard.NormalEvent) {
fmt.Printf("%+v\n", ev)
}
// FyEMouseEvent implements UIElement.FyEMouseEvent
func (cr *UIEventDebugger) FyEMouseEvent(ev frenyard.MouseEvent) {
fmt.Printf("%+v\n", ev)
cr._mousePos = ev.Pos
}
// FyETick implements UIElement.FyETick
func (cr *UIEventDebugger) FyETick(deltaTime float64) {
}
// FyEDraw implements UIElement.FyEDraw
func (cr *UIEventDebugger) FyEDraw(target frenyard.Renderer, under bool) {
if !under {
target.DrawRect(frenyard.DrawRectCommand{
Colour: 0xFF3F51B5,
Target: frenyard.Area2iOfSize(cr.FyESize()),
})
} else {
target.DrawRect(frenyard.DrawRectCommand{
Colour: 0x40000000,
Target: frenyard.Area2iOfSize(cr.FyESize()).Expand(frenyard.Area2iFromVecs(frenyard.Vec2i{-4, -4}, frenyard.Vec2i{4, 4})),
})
target.DrawRect(frenyard.DrawRectCommand{
Colour: 0x40000000,
Target: frenyard.Area2iOfSize(cr.FyESize()).Expand(frenyard.Area2iFromVecs(frenyard.Vec2i{-8, -8}, frenyard.Vec2i{8, 8})),
})
}
var cursorRect frenyard.Area2i
if !under {
cursorRect = frenyard.Area2iOfSize(frenyard.Vec2i{8, 8}).Translate(frenyard.Vec2i{-4, -4})
} else {
cursorRect = frenyard.Area2iOfSize(frenyard.Vec2i{16, 16}).Translate(frenyard.Vec2i{-8, -8})
}
target.Translate(cr._mousePos)
target.DrawRect(frenyard.DrawRectCommand{
Colour: 0x80FF0000,
Target: cursorRect,
})
target.Translate(cr._mousePos.Negate())
}
// NewDebugWrapPtr wraps in an interior layout.
func NewDebugWrapPtr(inner UILayoutElement) UILayoutElement {
return NewUIOverlayContainerPtr(nil, []UILayoutElement{ConvertElementToLayout(NewColouredRectPtr(0xFF200000, frenyard.Vec2i{})), inner})
}