-
Notifications
You must be signed in to change notification settings - Fork 0
/
log.go
52 lines (43 loc) · 959 Bytes
/
log.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
package main
import (
"image/color"
"github.com/hajimehoshi/ebiten/v2"
"github.com/hajimehoshi/ebiten/v2/text"
)
const (
LogSizeX = ScreenSizeX
LogSizeY = 200
)
type Log struct {
Image *ebiten.Image
Width, Height int
Lines []string
}
func NewLog() Log {
image := ebiten.NewImage(LogSizeX, LogSizeY)
return Log{
Image: image,
Width: LogSizeX,
Height: LogSizeY,
}
}
func (l *Log) WriteLine(message string) {
l.Lines = append([]string{message}, l.Lines...)
}
func (l *Log) Draw(screen *ebiten.Image) {
const (
paddingTop = 18
paddingLeft = 8
lineHeight = 28
)
l.Image.Fill(color.Black)
for i, line := range l.Lines {
text.Draw(l.Image, line, DefaultFontFace,
paddingLeft, paddingTop+i*lineHeight,
// color.RGBA{R: 255, G: 255, B: 255, A: uint8(255 - i*50)})
color.White)
}
op := ebiten.DrawImageOptions{}
op.GeoM.Translate(0, float64(ScreenSizeY-l.Height))
screen.DrawImage(l.Image, &op)
}