mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-26 03:38:55 +01:00
ebitenutil: Refactoring
This commit is contained in:
parent
eb2f3cf4f9
commit
ae04c2d680
@ -54,15 +54,18 @@ func (d *debugPrintState) drawText(rt *ebiten.Image, str string, ox, oy int, c c
|
|||||||
op.ColorM.Scale(r, g, b, a)
|
op.ColorM.Scale(r, g, b, a)
|
||||||
x := 0
|
x := 0
|
||||||
y := 0
|
y := 0
|
||||||
|
w, _ := d.textImage.Size()
|
||||||
for _, c := range str {
|
for _, c := range str {
|
||||||
const cw = assets.TextImageCharWidth
|
const (
|
||||||
const ch = assets.TextImageCharHeight
|
cw = assets.CharWidth
|
||||||
|
ch = assets.CharHeight
|
||||||
|
)
|
||||||
if c == '\n' {
|
if c == '\n' {
|
||||||
x = 0
|
x = 0
|
||||||
y += ch
|
y += ch
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
const n = assets.TextImageWidth / cw
|
n := w / cw
|
||||||
sx := (int(c) % n) * cw
|
sx := (int(c) % n) * cw
|
||||||
sy := (int(c) / n) * ch
|
sy := (int(c) / n) * ch
|
||||||
r := image.Rect(sx, sy, sx+cw, sy+ch)
|
r := image.Rect(sx, sy, sx+cw, sy+ch)
|
||||||
@ -78,7 +81,7 @@ func (d *debugPrintState) drawText(rt *ebiten.Image, str string, ox, oy int, c c
|
|||||||
// DebugPrint prints the given text str on the given image r.
|
// DebugPrint prints the given text str on the given image r.
|
||||||
func (d *debugPrintState) DebugPrint(r *ebiten.Image, str string) {
|
func (d *debugPrintState) DebugPrint(r *ebiten.Image, str string) {
|
||||||
if d.textImage == nil {
|
if d.textImage == nil {
|
||||||
img := assets.TextImage()
|
img := assets.CreateTextImage()
|
||||||
d.textImage, _ = ebiten.NewImageFromImage(img, ebiten.FilterNearest)
|
d.textImage, _ = ebiten.NewImageFromImage(img, ebiten.FilterNearest)
|
||||||
}
|
}
|
||||||
if d.debugPrintRenderTarget == nil {
|
if d.debugPrintRenderTarget == nil {
|
||||||
|
@ -25,13 +25,11 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
TextImageWidth = 192
|
CharWidth = 6
|
||||||
TextImageHeight = 128
|
CharHeight = 16
|
||||||
TextImageCharWidth = TextImageWidth / 32
|
|
||||||
TextImageCharHeight = TextImageHeight / 8
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func TextImage() image.Image {
|
func CreateTextImage() image.Image {
|
||||||
img, _, err := image.Decode(bytes.NewBuffer(textPng))
|
img, _, err := image.Decode(bytes.NewBuffer(textPng))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(fmt.Sprintf("assets: image.Decode failed, %v", err))
|
panic(fmt.Sprintf("assets: image.Decode failed, %v", err))
|
||||||
|
Loading…
Reference in New Issue
Block a user