Make a start on font rendering
I was hopeful I could use ebiten/text, but font.Face doesn't seem set up for fixed-colour fonts.
This commit is contained in:
@@ -5,7 +5,6 @@ import (
|
||||
"log"
|
||||
|
||||
"github.com/hajimehoshi/ebiten"
|
||||
"github.com/hajimehoshi/ebiten/ebitenutil"
|
||||
|
||||
"code.ur.gs/lupine/ordoor/internal/menus"
|
||||
)
|
||||
@@ -28,7 +27,8 @@ type noninteractive struct {
|
||||
rect image.Rectangle
|
||||
|
||||
// Some non-interactives, e.g., overlays, are an image + text to be shown
|
||||
textImg *ebiten.Image
|
||||
textImg *ebiten.Image
|
||||
textOffset image.Point
|
||||
|
||||
clickImpl // Alright, alright, it turns out the bridge mission briefing is clickable
|
||||
hoverImpl
|
||||
@@ -102,14 +102,27 @@ func registerOverlay(d *Driver, r *menus.Record) error {
|
||||
}
|
||||
|
||||
if r.Text != "" {
|
||||
// FIXME: we should be rendering the text much more nicely than this
|
||||
textImg, err := ebiten.NewImage(sprite.Rect.Dx(), sprite.Rect.Dy(), ebiten.FilterDefault)
|
||||
// FIXME: is this always right? Seems to make sense for Main.mnu
|
||||
fnt := d.menu.Font(r.FontType/10 - 1)
|
||||
|
||||
textImg, err := fnt.DrawLine(r.Text)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
ebitenutil.DebugPrint(textImg, r.Text)
|
||||
ni.textImg = textImg
|
||||
|
||||
// Centre the image
|
||||
xSlack := ni.rect.Dx() - textImg.Bounds().Dx()
|
||||
if xSlack > 0 {
|
||||
ni.textOffset.X = xSlack / 2
|
||||
}
|
||||
|
||||
ySlack := ni.rect.Dy() - textImg.Bounds().Dy()
|
||||
if ySlack > 0 {
|
||||
ni.textOffset.Y = ySlack / 2
|
||||
}
|
||||
|
||||
} else {
|
||||
log.Printf("Overlay without text detected: %#+v", r)
|
||||
}
|
||||
@@ -189,12 +202,16 @@ func (n *noninteractive) regions(tick int) []region {
|
||||
out := oneRegion(n.bounds().Min, n.frames.image(tick))
|
||||
|
||||
if n.textImg != nil {
|
||||
out = append(out, oneRegion(n.bounds().Min, n.textImg)...)
|
||||
out = append(out, oneRegion(n.textPos(), n.textImg)...)
|
||||
}
|
||||
|
||||
return out
|
||||
}
|
||||
|
||||
func (n *noninteractive) textPos() image.Point {
|
||||
return image.Pt(n.rect.Min.X+n.textOffset.X, n.rect.Min.Y+n.textOffset.Y)
|
||||
}
|
||||
|
||||
func (a *animationHover) regions(tick int) []region {
|
||||
if a.opening || a.closing {
|
||||
var anim animation
|
||||
|
Reference in New Issue
Block a user