mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-26 03:38:55 +01:00
examples/text: use GoTextFace
This commit is contained in:
parent
b2c45a369a
commit
acd5207142
@ -15,14 +15,11 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"image/color"
|
"image/color"
|
||||||
"log"
|
"log"
|
||||||
"math"
|
"math"
|
||||||
|
|
||||||
"golang.org/x/image/font"
|
|
||||||
"golang.org/x/image/font/opentype"
|
|
||||||
"golang.org/x/image/math/fixed"
|
|
||||||
|
|
||||||
"github.com/hajimehoshi/ebiten/v2"
|
"github.com/hajimehoshi/ebiten/v2"
|
||||||
"github.com/hajimehoshi/ebiten/v2/examples/resources/fonts"
|
"github.com/hajimehoshi/ebiten/v2/examples/resources/fonts"
|
||||||
"github.com/hajimehoshi/ebiten/v2/text/v2"
|
"github.com/hajimehoshi/ebiten/v2/text/v2"
|
||||||
@ -38,36 +35,26 @@ const sampleText = ` The quick brown fox jumps
|
|||||||
over the lazy dog.`
|
over the lazy dog.`
|
||||||
|
|
||||||
var (
|
var (
|
||||||
mplusNormalFace *text.StdFace
|
mplusFaceSource *text.GoTextFaceSource
|
||||||
mplusBigFace *text.StdFace
|
mplusNormalFace *text.GoTextFace
|
||||||
|
mplusBigFace *text.GoTextFace
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
tt, err := opentype.Parse(fonts.MPlus1pRegular_ttf)
|
s, err := text.NewGoTextFaceSource(bytes.NewReader(fonts.MPlus1pRegular_ttf))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
mplusFaceSource = s
|
||||||
|
|
||||||
const dpi = 72
|
mplusNormalFace = &text.GoTextFace{
|
||||||
mplusNormalFont, err := opentype.NewFace(tt, &opentype.FaceOptions{
|
Source: mplusFaceSource,
|
||||||
Size: 24,
|
Size: 24,
|
||||||
DPI: dpi,
|
|
||||||
Hinting: font.HintingVertical,
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
}
|
||||||
mplusNormalFace = text.NewStdFace(mplusNormalFont)
|
mplusBigFace = &text.GoTextFace{
|
||||||
|
Source: mplusFaceSource,
|
||||||
mplusBigFont, err := opentype.NewFace(tt, &opentype.FaceOptions{
|
Size: 32,
|
||||||
Size: 32,
|
|
||||||
DPI: dpi,
|
|
||||||
Hinting: font.HintingVertical,
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
}
|
||||||
mplusBigFace = text.NewStdFace(mplusBigFont)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type Game struct {
|
type Game struct {
|
||||||
@ -87,10 +74,6 @@ func (g *Game) Update() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func fixed26_6ToFloat32(x fixed.Int26_6) float32 {
|
|
||||||
return float32(x>>6) + float32(x&((1<<6)-1))/(1<<6)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (g *Game) Draw(screen *ebiten.Image) {
|
func (g *Game) Draw(screen *ebiten.Image) {
|
||||||
gray := color.RGBA{0x80, 0x80, 0x80, 0xff}
|
gray := color.RGBA{0x80, 0x80, 0x80, 0xff}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user