blooblib/font.go

33 lines
687 B
Go
Raw Normal View History

2024-03-23 05:15:23 +01:00
package bloob
import _ "embed"
type ch struct {
xForward int
image *Image
}
type Font struct {
chars []ch
lineHeight int
}
//go:embed "font.png"
var fontdata []byte
var DefaultFont = LoadTilesetFontBytes(fontdata, Vec2i{X: 8, Y: 14})
//go:embed "font-thin.png"
var fontdataThin []byte
var DefaultFontThin = LoadTilesetFontBytes(fontdataThin, Vec2i{X: 6, Y: 8})
func LoadTilesetFontBytes(data []byte, tilesize Vec2i) *Font {
tiles := LoadImageBytes(data).MakeTileset(tilesize)
var font Font
for i := 0; i < len(tiles); i += 1 {
c := ch{xForward: tilesize.X, image: tiles[i]}
font.chars = append(font.chars, c)
}
font.lineHeight = tilesize.Y + 2
return &font
}