aboutsummaryrefslogtreecommitdiff
path: root/go/ui/textBox.go
diff options
context:
space:
mode:
Diffstat (limited to 'go/ui/textBox.go')
-rw-r--r--go/ui/textBox.go42
1 files changed, 16 insertions, 26 deletions
diff --git a/go/ui/textBox.go b/go/ui/textBox.go
index e07440b5..5e2d140b 100644
--- a/go/ui/textBox.go
+++ b/go/ui/textBox.go
@@ -6,31 +6,30 @@ import (
"github.com/hajimehoshi/ebiten/v2"
"github.com/hajimehoshi/ebiten/v2/text"
+ "muhq.space/muhqs-game/go/font"
"muhq.space/muhqs-game/go/game"
)
var (
TEXTBOX_BACKGROUND = gray
TEXTBOX_FOREGROUND = color.White
+
+ TEXTBOX_AUTO_BORDER = 3
)
type TextBox struct {
- X, Y int
- Width, Height int
- img *ebiten.Image
- text string
+ WidgetBase
+ Text string
}
func NewFixedTextBox(x, y int, width, height int, t string) *TextBox {
- tb := &TextBox{x, y, width, height, nil, t}
- tb.render()
+ tb := &TextBox{NewWidgetBase(x, y, width, height), t}
+ tb.renderImpl = func() *ebiten.Image { return tb.render() }
return tb
}
func NewAutoTextBox(x, y int, t string) *TextBox {
- tb := &TextBox{x, y, -1, -1, nil, t}
- tb.render()
- return tb
+ return NewFixedTextBox(x, y, -1, -1, t)
}
func NewUnitInfo(x, y int, u *game.Unit) *TextBox {
@@ -45,23 +44,14 @@ func NewPermInfo(x, y int, p game.Permanent) *TextBox {
return NewAutoTextBox(x, y, info)
}
-func (tb *TextBox) render() {
- b := text.BoundString(Font, tb.text)
+func (tb *TextBox) render() *ebiten.Image {
+ b := text.BoundString(font.Font, tb.Text)
if tb.Width == -1 || tb.Height == -1 {
- tb.Width = b.Dx()
- tb.Height = b.Dy()
+ tb.Width = b.Dx() + 2*TEXTBOX_AUTO_BORDER
+ tb.Height = b.Dy() + 2*TEXTBOX_AUTO_BORDER
}
- tb.img = ebiten.NewImage(tb.Width, tb.Height)
- tb.img.Fill(TEXTBOX_BACKGROUND)
- text.Draw(tb.img, tb.text, Font, b.Min.X, -b.Min.Y, TEXTBOX_FOREGROUND)
-}
-
-func (tb *TextBox) Draw(screen *ebiten.Image) {
- op := &ebiten.DrawImageOptions{}
- op.GeoM.Translate(float64(tb.X), float64(tb.Y))
- screen.DrawImage(tb.img, op)
-}
-
-func (tb TextBox) FindObjectAt(x, y int) interface{} {
- return nil
+ img := ebiten.NewImage(tb.Width, tb.Height)
+ img.Fill(TEXTBOX_BACKGROUND)
+ text.Draw(img, tb.Text, font.Font, TEXTBOX_AUTO_BORDER+b.Min.X, TEXTBOX_AUTO_BORDER-b.Min.Y, TEXTBOX_FOREGROUND)
+ return img
}