From 55fcb205eeaf99867ed64f77cdb157f54cea3558 Mon Sep 17 00:00:00 2001 From: iegod Date: Thu, 31 Aug 2023 17:05:53 -0400 Subject: [PATCH] Moved fonts into their own file.' --- examples/splashmenu/fonts/splashfonts.go | 72 ++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 examples/splashmenu/fonts/splashfonts.go diff --git a/examples/splashmenu/fonts/splashfonts.go b/examples/splashmenu/fonts/splashfonts.go new file mode 100644 index 0000000..6808511 --- /dev/null +++ b/examples/splashmenu/fonts/splashfonts.go @@ -0,0 +1,72 @@ +package splashmenu + +import ( + "log" + + "github.com/hajimehoshi/ebiten/v2/examples/resources/fonts" + "golang.org/x/image/font" + "golang.org/x/image/font/opentype" +) + +type FontBase struct { + Title font.Face + Menu font.Face + Splash font.Face + BigTitle font.Face +} + +var ( + SplashFont *FontBase +) + +func init() { + + const dpi = 72 + SplashFont = &FontBase{} + + tt, err := opentype.Parse(fonts.PressStart2P_ttf) + if err != nil { + log.Fatal(err) + } + + SplashFont.Title, err = opentype.NewFace(tt, &opentype.FaceOptions{ + Size: 16, + DPI: dpi, + Hinting: font.HintingVertical, + }) + if err != nil { + log.Fatal(err) + } + + SplashFont.Menu, err = opentype.NewFace(tt, &opentype.FaceOptions{ + Size: 10, + DPI: dpi, + Hinting: font.HintingVertical, + }) + if err != nil { + log.Fatal(err) + } + tt, err = opentype.Parse(fonts.PressStart2P_ttf) + if err != nil { + log.Fatal(err) + } + + SplashFont.Splash, err = opentype.NewFace(tt, &opentype.FaceOptions{ + Size: 12, + DPI: dpi, + Hinting: font.HintingVertical, + }) + if err != nil { + log.Fatal(err) + } + + SplashFont.BigTitle, err = opentype.NewFace(tt, &opentype.FaceOptions{ + Size: 40, + DPI: dpi, + Hinting: font.HintingVertical, + }) + if err != nil { + log.Fatal(err) + } + +}