move GetFontFace into FontLayout struct

This commit is contained in:
2023-07-05 22:55:37 +02:00
parent 607cf0d44f
commit 41a32a8fe5
4 changed files with 20 additions and 17 deletions

View File

@@ -2,7 +2,6 @@ package engine
import ( import (
"bytes" "bytes"
"game/konstructor/entity"
"image" "image"
"io/ioutil" "io/ioutil"
"log" "log"
@@ -10,8 +9,6 @@ import (
_ "image/png" _ "image/png"
"github.com/hajimehoshi/ebiten" "github.com/hajimehoshi/ebiten"
"golang.org/x/image/font"
"golang.org/x/image/font/opentype"
) )
func LoadImage(path string) *ebiten.Image { func LoadImage(path string) *ebiten.Image {
@@ -33,14 +30,3 @@ func LoadImage(path string) *ebiten.Image {
return out 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
}

View File

@@ -25,7 +25,7 @@ func (e *Engine) DialogUpdate() {
func (e *Engine) DialogDraw(screen *ebiten.Image) { func (e *Engine) DialogDraw(screen *ebiten.Image) {
dialog := e.Domain.GetDialog(e.KContext.ScreenValue) dialog := e.Domain.GetDialog(e.KContext.ScreenValue)
face := GetFontFace(dialog.Layout.ChoiceFont) face := dialog.Layout.ChoiceFont.GetFontFace()
for i, choice := range dialog.Choices { for i, choice := range dialog.Choices {
offset := int(dialog.Layout.ChoiceFont.Size) * (i + 1) offset := int(dialog.Layout.ChoiceFont.Size) * (i + 1)

View File

@@ -25,7 +25,7 @@ func (e *Engine) MenuUpdate() {
func (e *Engine) MenuDraw(screen *ebiten.Image) { func (e *Engine) MenuDraw(screen *ebiten.Image) {
menu := e.Domain.GetMenu(e.KContext.ScreenValue) menu := e.Domain.GetMenu(e.KContext.ScreenValue)
face := GetFontFace(menu.Layout.MenuItemFont) face := menu.Layout.MenuItemFont.GetFontFace()
for i, menu_item := range menu.MenuItems { for i, menu_item := range menu.MenuItems {
color := menu.GetMenuItemColor(i) color := menu.GetMenuItemColor(i)

View File

@@ -1,6 +1,12 @@
package entity package entity
import "image/color" import (
"image/color"
"io/ioutil"
"golang.org/x/image/font"
"golang.org/x/image/font/opentype"
)
type FontLayout struct { type FontLayout struct {
Path string Path string
@@ -9,3 +15,14 @@ type FontLayout struct {
Color color.Color Color color.Color
SelectedColor 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
}