From 73d40903aecad3efcf7c6055c133f0db86558203 Mon Sep 17 00:00:00 2001 From: Florian Fischer Date: Tue, 24 Jan 2023 00:27:50 +0100 Subject: intermediate commit --- go/ui/buffer.go | 39 ++++++++++++--------------------------- 1 file changed, 12 insertions(+), 27 deletions(-) (limited to 'go/ui/buffer.go') diff --git a/go/ui/buffer.go b/go/ui/buffer.go index cc9f2377..e0e6b001 100644 --- a/go/ui/buffer.go +++ b/go/ui/buffer.go @@ -5,6 +5,8 @@ import ( "github.com/hajimehoshi/ebiten/v2" "github.com/hajimehoshi/ebiten/v2/text" + + "muhq.space/muhqs-game/go/font" ) var ( @@ -13,47 +15,30 @@ var ( ) type Buffer struct { - X, Y int - Width, Height int - img *ebiten.Image - lines []string - pos int + WidgetBase + lines []string + pos int } func NewBuffer(x, y int, width, height int) *Buffer { - return &Buffer{x, y, width, height, nil, []string{}, 0} + b := &Buffer{NewWidgetBase(x, y, width, height), []string{}, 0} + b.renderImpl = func() *ebiten.Image { return b.render() } + return b } -func (b *Buffer) render() { +func (b *Buffer) render() *ebiten.Image { img := ebiten.NewImage(b.Width, b.Height) img.Fill(BUFFER_BACKGROUND) y := 0 for _, line := range b.lines[b.pos:] { - bounds := text.BoundString(Font, line) + bounds := text.BoundString(font.Font, line) y += bounds.Dy() if y > b.Height { break } - text.Draw(img, line, Font, 0, y, BUFFER_FOREGROUND) - } - b.img = img -} - -func (b *Buffer) Draw(screen *ebiten.Image) { - if b.img == nil { - b.render() + text.Draw(img, line, font.Font, 0, y, BUFFER_FOREGROUND) } - op := &ebiten.DrawImageOptions{} - op.GeoM.Translate(float64(b.X), float64(b.Y)) - screen.DrawImage(b.img, op) -} - -func (b *Buffer) FindObjectAt(x, y int) interface{} { - return nil -} - -func (b *Buffer) ForceRedraw() { - b.img = nil + return img } func (b *Buffer) AddLines(lines []string) { -- cgit v1.2.3