-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdebug_msg.go
145 lines (110 loc) · 2.73 KB
/
debug_msg.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
package fnf
import (
"fmt"
rl "github.com/gen2brain/raylib-go/raylib"
)
type DebugMsg struct {
Key string
Value string
}
var DebugMsgs []DebugMsg
var PersistentDebugMsgs []DebugMsg
func DebugPrint(key, value string) {
for i, msg := range DebugMsgs {
if msg.Key == key {
DebugMsgs[i].Value = value
return
}
}
DebugMsgs = append(DebugMsgs, DebugMsg{
Key: key,
Value: value,
})
}
func DebugPrintPersist(key, value string) {
for i, msg := range PersistentDebugMsgs {
if msg.Key == key {
DebugMsgs[i].Value = value
return
}
}
PersistentDebugMsgs = append(PersistentDebugMsgs, DebugMsg{
Key: key,
Value: value,
})
}
func DrawDebugMsgs() {
type textPos struct {
Text string
Pos rl.Vector2
}
var texts []textPos
const fontSize = 20
const fontSpacing = 3
const keyValueMargin = 10
const msgHozMargin = 10
textRect := rl.Rectangle{}
offsetX := float32(0)
offsetY := float32(0)
defaultFont := rl.GetFontDefault()
// print help message
{
str := fmt.Sprintf("press [%s] to toggle debug panel",
GetKeyName(TheKM[ToggleDebugMsg]))
strSize := rl.MeasureTextEx(defaultFont, str, fontSize, fontSpacing)
textRect = RectUnion(textRect, RectWH(strSize.X, strSize.Y))
texts = append(texts, textPos{
Text: str,
Pos: rl.Vector2{X: offsetY, Y: offsetY},
})
offsetY += strSize.Y + msgHozMargin*2
}
addTextsFromMsgs := func(msgs []DebugMsg) {
for _, kv := range msgs {
k := kv.Key
v := kv.Value
keyText := k + " : "
keySize := rl.MeasureTextEx(defaultFont, keyText, fontSize, fontSpacing)
keyRect := rl.Rectangle{
X: offsetX, Y: offsetY,
Width: keySize.X, Height: keySize.Y,
}
texts = append(texts, textPos{
Text: keyText,
Pos: rl.Vector2{X: keyRect.X, Y: keyRect.Y},
})
valueSize := rl.MeasureTextEx(defaultFont, v, fontSize, fontSpacing)
valueRect := rl.Rectangle{
X: keyRect.X + keyRect.Width + keyValueMargin,
Y: offsetY,
Width: valueSize.X,
Height: valueSize.Y,
}
texts = append(texts, textPos{
Text: v,
Pos: rl.Vector2{X: valueRect.X, Y: valueRect.Y},
})
msgRect := RectUnion(keyRect, valueRect)
textRect = RectUnion(textRect, msgRect)
offsetX = 0
offsetY += msgRect.Height + msgHozMargin
}
}
// print debug key and values
addTextsFromMsgs(PersistentDebugMsgs)
addTextsFromMsgs(DebugMsgs)
bgRect := textRect
bgRect.X -= 10
bgRect.Y -= 10
bgRect.Width += 20
bgRect.Height += 20
rl.DrawRectangleRec(bgRect, ToRlColor(FnfColor{0, 0, 0, 130}))
rl.BeginBlendMode(rl.BlendAlpha)
for _, t := range texts {
rl.DrawTextEx(defaultFont, t.Text, t.Pos, fontSize, fontSpacing, rl.Color{255, 255, 255, 255})
}
FnfEndBlendMode()
}
func ClearDebugMsgs() {
DebugMsgs = DebugMsgs[:0]
}