mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-26 03:38:55 +01:00
parent
cec8017ebe
commit
a749f6fbc3
@ -22,13 +22,11 @@ import (
|
|||||||
_ "image/png"
|
_ "image/png"
|
||||||
"log"
|
"log"
|
||||||
|
|
||||||
"golang.org/x/image/font"
|
|
||||||
"golang.org/x/image/font/inconsolata"
|
"golang.org/x/image/font/inconsolata"
|
||||||
"golang.org/x/image/math/fixed"
|
|
||||||
|
|
||||||
"github.com/hajimehoshi/ebiten/v2"
|
"github.com/hajimehoshi/ebiten/v2"
|
||||||
"github.com/hajimehoshi/ebiten/v2/examples/resources/images/blend"
|
"github.com/hajimehoshi/ebiten/v2/examples/resources/images/blend"
|
||||||
"github.com/hajimehoshi/ebiten/v2/text"
|
"github.com/hajimehoshi/ebiten/v2/text/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -36,6 +34,10 @@ const (
|
|||||||
screenHeight = 800
|
screenHeight = 800
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
inconsolataFace = text.NewStdFace(inconsolata.Bold8x16)
|
||||||
|
)
|
||||||
|
|
||||||
// mode is a blend mode with description.
|
// mode is a blend mode with description.
|
||||||
type mode struct {
|
type mode struct {
|
||||||
blend ebiten.Blend
|
blend ebiten.Blend
|
||||||
@ -176,17 +178,14 @@ func maxSide(a, b *ebiten.Image) int {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
func fixed26_6ToFloat64(x fixed.Int26_6) float64 {
|
|
||||||
return float64(x>>6) + float64(x&((1<<6)-1))/float64(1<<6)
|
|
||||||
}
|
|
||||||
|
|
||||||
// drawCenteredText is a util function for drawing blend mode description.
|
// drawCenteredText is a util function for drawing blend mode description.
|
||||||
func drawCenteredText(screen *ebiten.Image, cx, cy float64, s string) {
|
func drawCenteredText(screen *ebiten.Image, cx, cy float64, s string) {
|
||||||
advance := font.MeasureString(inconsolata.Bold8x16, s)
|
op := &text.DrawOptions{}
|
||||||
m := inconsolata.Bold8x16.Metrics()
|
op.GeoM.Translate(cx, cy)
|
||||||
height := m.Ascent + m.Descent
|
op.ColorScale.ScaleWithColor(color.Black)
|
||||||
x, y := int(cx-fixed26_6ToFloat64(advance)/2), int(cy-fixed26_6ToFloat64(height)/2+fixed26_6ToFloat64(m.Ascent))
|
op.PrimaryAlign = text.AlignCenter
|
||||||
text.Draw(screen, s, inconsolata.Bold8x16, x, y, color.Black)
|
op.SecondaryAlign = text.AlignCenter
|
||||||
|
text.Draw(screen, s, inconsolataFace, op)
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
Loading…
Reference in New Issue
Block a user