Refactored for consistency. Removed font dependency.
This commit is contained in:
@@ -2,37 +2,13 @@ package splashmenu
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"cosmos/diego/groovy"
|
"cosmos/diego/groovy"
|
||||||
|
splashmenu "cosmos/diego/groovy/examples/splashmenu/fonts"
|
||||||
"image/color"
|
"image/color"
|
||||||
"log"
|
|
||||||
|
|
||||||
"github.com/hajimehoshi/ebiten/v2"
|
"github.com/hajimehoshi/ebiten/v2"
|
||||||
"github.com/hajimehoshi/ebiten/v2/examples/resources/fonts"
|
|
||||||
"github.com/hajimehoshi/ebiten/v2/text"
|
"github.com/hajimehoshi/ebiten/v2/text"
|
||||||
"golang.org/x/image/font"
|
|
||||||
"golang.org/x/image/font/opentype"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
|
||||||
splashFont font.Face
|
|
||||||
)
|
|
||||||
|
|
||||||
func init() {
|
|
||||||
tt, err := opentype.Parse(fonts.PressStart2P_ttf)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
const dpi = 72
|
|
||||||
splashFont, err = opentype.NewFace(tt, &opentype.FaceOptions{
|
|
||||||
Size: 12,
|
|
||||||
DPI: dpi,
|
|
||||||
Hinting: font.HintingVertical,
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
type Splash struct {
|
type Splash struct {
|
||||||
Dimensions groovy.Area
|
Dimensions groovy.Area
|
||||||
bgcolor color.RGBA
|
bgcolor color.RGBA
|
||||||
@@ -40,11 +16,6 @@ type Splash struct {
|
|||||||
events map[groovy.SceneEvent]func()
|
events map[groovy.SceneEvent]func()
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetSceneEvents implements groovy.Scene.
|
|
||||||
func (*Splash) GetSceneEvents() []groovy.SceneEvent {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewSplash() Splash {
|
func NewSplash() Splash {
|
||||||
return Splash{
|
return Splash{
|
||||||
bgcolor: color.RGBA{0xFF, 0xFF, 0xFF, 0xFF},
|
bgcolor: color.RGBA{0xFF, 0xFF, 0xFF, 0xFF},
|
||||||
@@ -52,11 +23,6 @@ func NewSplash() Splash {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Splash) Draw(screen *ebiten.Image) {
|
|
||||||
screen.Fill(s.bgcolor)
|
|
||||||
text.Draw(screen, "splash", splashFont, 40, 40, color.White)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *Splash) Update() error {
|
func (s *Splash) Update() error {
|
||||||
s.increment++
|
s.increment++
|
||||||
|
|
||||||
@@ -74,11 +40,16 @@ func (s *Splash) Update() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *Splash) Draw(screen *ebiten.Image) {
|
||||||
|
screen.Fill(s.bgcolor)
|
||||||
|
text.Draw(screen, "splash", splashmenu.SplashFont.Splash, 40, 40, color.White)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *Splash) SetEventHandler(event groovy.SceneEvent, f func()) {
|
||||||
|
s.events[event] = f
|
||||||
|
}
|
||||||
|
|
||||||
// sets sene dimensions
|
// sets sene dimensions
|
||||||
func (s *Splash) SetDimensions(a groovy.Area) {
|
func (s *Splash) SetDimensions(a groovy.Area) {
|
||||||
s.Dimensions = a
|
s.Dimensions = a
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s Splash) SetEventHandler(event groovy.SceneEvent, f func()) {
|
|
||||||
s.events[event] = f
|
|
||||||
}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user