mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-25 11:18:54 +01:00
ebitenutil: DebugText always returns nil (#331)
This commit is contained in:
parent
a7d844ce5e
commit
283c8d41ca
@ -60,11 +60,14 @@ type debugPrintState struct {
|
|||||||
var defaultDebugPrintState = &debugPrintState{}
|
var defaultDebugPrintState = &debugPrintState{}
|
||||||
|
|
||||||
// DebugPrint draws the string str on the image.
|
// DebugPrint draws the string str on the image.
|
||||||
|
//
|
||||||
|
// DebugPrint always returns nil as of 1.5.0-alpha.
|
||||||
func DebugPrint(image *ebiten.Image, str string) error {
|
func DebugPrint(image *ebiten.Image, str string) error {
|
||||||
return defaultDebugPrintState.DebugPrint(image, str)
|
defaultDebugPrintState.DebugPrint(image, str)
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *debugPrintState) drawText(rt *ebiten.Image, str string, x, y int, c color.Color) error {
|
func (d *debugPrintState) drawText(rt *ebiten.Image, str string, x, y int, c color.Color) {
|
||||||
ur, ug, ub, ua := c.RGBA()
|
ur, ug, ub, ua := c.RGBA()
|
||||||
const max = math.MaxUint16
|
const max = math.MaxUint16
|
||||||
r := float64(ur) / max
|
r := float64(ur) / max
|
||||||
@ -81,37 +84,19 @@ func (d *debugPrintState) drawText(rt *ebiten.Image, str string, x, y int, c col
|
|||||||
}
|
}
|
||||||
op.GeoM.Translate(float64(x+1), float64(y))
|
op.GeoM.Translate(float64(x+1), float64(y))
|
||||||
op.ColorM.Scale(r, g, b, a)
|
op.ColorM.Scale(r, g, b, a)
|
||||||
if err := rt.DrawImage(d.textImage, op); err != nil {
|
_ = rt.DrawImage(d.textImage, op)
|
||||||
return err
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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) error {
|
func (d *debugPrintState) DebugPrint(r *ebiten.Image, str string) {
|
||||||
if d.textImage == nil {
|
if d.textImage == nil {
|
||||||
img, err := assets.TextImage()
|
img := assets.TextImage()
|
||||||
if err != nil {
|
d.textImage, _ = ebiten.NewImageFromImage(img, ebiten.FilterNearest)
|
||||||
return err
|
|
||||||
}
|
|
||||||
d.textImage, err = ebiten.NewImageFromImage(img, ebiten.FilterNearest)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if d.debugPrintRenderTarget == nil {
|
if d.debugPrintRenderTarget == nil {
|
||||||
width, height := 256, 256
|
width, height := 256, 256
|
||||||
var err error
|
d.debugPrintRenderTarget, _ = ebiten.NewImage(width, height, ebiten.FilterNearest)
|
||||||
d.debugPrintRenderTarget, err = ebiten.NewImage(width, height, ebiten.FilterNearest)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if err := d.drawText(r, str, 1, 1, color.NRGBA{0x00, 0x00, 0x00, 0x80}); err != nil {
|
d.drawText(r, str, 1, 1, color.NRGBA{0x00, 0x00, 0x00, 0x80})
|
||||||
return err
|
d.drawText(r, str, 0, 0, color.NRGBA{0xff, 0xff, 0xff, 0xff})
|
||||||
}
|
|
||||||
if err := d.drawText(r, str, 0, 0, color.NRGBA{0xff, 0xff, 0xff, 0xff}); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
@ -19,6 +19,7 @@ package assets
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"fmt"
|
||||||
"image"
|
"image"
|
||||||
_ "image/png"
|
_ "image/png"
|
||||||
)
|
)
|
||||||
@ -30,14 +31,11 @@ const (
|
|||||||
TextImageCharHeight = TextImageHeight / 8
|
TextImageCharHeight = TextImageHeight / 8
|
||||||
)
|
)
|
||||||
|
|
||||||
func TextImage() (image.Image, error) {
|
func TextImage() image.Image {
|
||||||
b, err := Asset("text.png")
|
b := MustAsset("text.png")
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
img, _, err := image.Decode(bytes.NewBuffer(b))
|
img, _, err := image.Decode(bytes.NewBuffer(b))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
panic(fmt.Sprintf("assets: image.Decode failed, %v", err))
|
||||||
}
|
}
|
||||||
return img, nil
|
return img
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user