move GetFontFace into FontLayout struct
This commit is contained in:
@@ -2,7 +2,6 @@ package engine
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"game/konstructor/entity"
|
||||
"image"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
@@ -10,8 +9,6 @@ import (
|
||||
_ "image/png"
|
||||
|
||||
"github.com/hajimehoshi/ebiten"
|
||||
"golang.org/x/image/font"
|
||||
"golang.org/x/image/font/opentype"
|
||||
)
|
||||
|
||||
func LoadImage(path string) *ebiten.Image {
|
||||
@@ -33,14 +30,3 @@ func LoadImage(path string) *ebiten.Image {
|
||||
|
||||
return out
|
||||
}
|
||||
|
||||
func GetFontFace(layout entity.FontLayout) font.Face {
|
||||
file, _ := ioutil.ReadFile(layout.Path)
|
||||
tt, _ := opentype.Parse(file)
|
||||
face, _ := opentype.NewFace(tt, &opentype.FaceOptions{
|
||||
Size: layout.DPI,
|
||||
DPI: layout.Size,
|
||||
Hinting: font.HintingVertical,
|
||||
})
|
||||
return face
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ func (e *Engine) DialogUpdate() {
|
||||
func (e *Engine) DialogDraw(screen *ebiten.Image) {
|
||||
dialog := e.Domain.GetDialog(e.KContext.ScreenValue)
|
||||
|
||||
face := GetFontFace(dialog.Layout.ChoiceFont)
|
||||
face := dialog.Layout.ChoiceFont.GetFontFace()
|
||||
|
||||
for i, choice := range dialog.Choices {
|
||||
offset := int(dialog.Layout.ChoiceFont.Size) * (i + 1)
|
||||
|
||||
@@ -25,7 +25,7 @@ func (e *Engine) MenuUpdate() {
|
||||
|
||||
func (e *Engine) MenuDraw(screen *ebiten.Image) {
|
||||
menu := e.Domain.GetMenu(e.KContext.ScreenValue)
|
||||
face := GetFontFace(menu.Layout.MenuItemFont)
|
||||
face := menu.Layout.MenuItemFont.GetFontFace()
|
||||
|
||||
for i, menu_item := range menu.MenuItems {
|
||||
color := menu.GetMenuItemColor(i)
|
||||
|
||||
@@ -1,6 +1,12 @@
|
||||
package entity
|
||||
|
||||
import "image/color"
|
||||
import (
|
||||
"image/color"
|
||||
"io/ioutil"
|
||||
|
||||
"golang.org/x/image/font"
|
||||
"golang.org/x/image/font/opentype"
|
||||
)
|
||||
|
||||
type FontLayout struct {
|
||||
Path string
|
||||
@@ -9,3 +15,14 @@ type FontLayout struct {
|
||||
Color color.Color
|
||||
SelectedColor color.Color
|
||||
}
|
||||
|
||||
func (fl *FontLayout) GetFontFace() font.Face {
|
||||
file, _ := ioutil.ReadFile(fl.Path)
|
||||
tt, _ := opentype.Parse(file)
|
||||
face, _ := opentype.NewFace(tt, &opentype.FaceOptions{
|
||||
Size: fl.DPI,
|
||||
DPI: fl.Size,
|
||||
Hinting: font.HintingVertical,
|
||||
})
|
||||
return face
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user