33 lines
687 B
Go
33 lines
687 B
Go
|
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
|
||
|
}
|