ebiten: deprecate (*Image).Size

Closes #2351
This commit is contained in:
Hajime Hoshi 2023-01-19 23:42:35 +09:00
parent 8d61d43371
commit f054a7634a
43 changed files with 111 additions and 114 deletions

View File

@ -42,7 +42,6 @@ func DrawImage(dst, src *ebiten.Image, colorM ColorM, op *DrawImageOptions) {
op = &DrawImageOptions{}
}
w, h := src.Size()
opShader := &ebiten.DrawRectShaderOptions{}
opShader.GeoM = op.GeoM
opShader.CompositeMode = ebiten.CompositeModeCustom
@ -50,7 +49,7 @@ func DrawImage(dst, src *ebiten.Image, colorM ColorM, op *DrawImageOptions) {
opShader.Uniforms = uniforms(colorM)
opShader.Images[0] = src
s := builtinShader(builtinshader.Filter(op.Filter), builtinshader.AddressUnsafe)
dst.DrawRectShader(w, h, s, opShader)
dst.DrawRectShader(src.Bounds().Dx(), src.Bounds().Dy(), s, opShader)
}
// DrawTrianglesOptions represents options for DrawTriangles.

View File

@ -59,7 +59,7 @@ func drawDebugText(rt *ebiten.Image, str string, ox, oy int) {
op := &ebiten.DrawImageOptions{}
x := 0
y := 0
w, _ := debugPrintTextImage.Size()
w := debugPrintTextImage.Bounds().Dx()
for _, c := range str {
const (
cw = 6

View File

@ -16,6 +16,7 @@ package ebitenutil_test
import (
"embed"
"image"
// `NewImageFromFileSystem` works without this importing, but this is not an expected thing (#2336).
_ "image/png"
"testing"
@ -31,11 +32,7 @@ func TestNewImageFromFileSystem(t *testing.T) {
if err != nil {
t.Fatal(err)
}
w, h := img.Size()
if got, want := w, 192; got != want {
t.Errorf("got: %d, want: %d", got, want)
}
if got, want := h, 128; got != want {
t.Errorf("got: %d, want: %d", got, want)
if got, want := img.Bounds().Size(), image.Pt(192, 128); got != want {
t.Errorf("got: %v, want: %v", got, want)
}
}

View File

@ -68,14 +68,13 @@ func (g *Game) Update() error {
// Draw draws the current game to the given screen.
func (g *Game) Draw(screen *ebiten.Image) {
if g.boardImage == nil {
w, h := g.board.Size()
g.boardImage = ebiten.NewImage(w, h)
g.boardImage = ebiten.NewImage(g.board.Size())
}
screen.Fill(backgroundColor)
g.board.Draw(g.boardImage)
op := &ebiten.DrawImageOptions{}
sw, sh := screen.Size()
bw, bh := g.boardImage.Size()
sw, sh := screen.Bounds().Dx(), screen.Bounds().Dy()
bw, bh := g.boardImage.Bounds().Dx(), g.boardImage.Bounds().Dy()
x := (sw - bw) / 2
y := (sh - bh) / 2
op.GeoM.Translate(float64(x), float64(y))

View File

@ -56,7 +56,7 @@ func (g *Game) Draw(screen *ebiten.Image) {
// Draw the image with 'Lighter (a.k.a Additive)' blend mode.
op = &ebiten.DrawImageOptions{}
w, _ := ebitenImage.Size()
w := ebitenImage.Bounds().Dx()
op.GeoM.Translate(ox+float64(w), oy)
op.Blend = ebiten.BlendLighter
screen.DrawImage(ebitenImage, op)

View File

@ -54,7 +54,7 @@ func init() {
xrepeat = 7
yrepeat = 8
)
w, h := gophersImage.Size()
w, h := gophersImage.Bounds().Dx(), gophersImage.Bounds().Dy()
repeatedGophersImage = ebiten.NewImage(w*xrepeat, h*yrepeat)
for j := 0; j < yrepeat; j++ {
for i := 0; i < xrepeat; i++ {
@ -87,7 +87,7 @@ func round(x float64) float64 {
// MoveForward moves the player p forward.
func (p *player) MoveForward() {
w, h := gophersImage.Size()
w, h := gophersImage.Bounds().Dx(), gophersImage.Bounds().Dy()
mx := w * 16
my := h * 16
s, c := math.Sincos(float64(p.angle) * 2 * math.Pi / maxAngle)
@ -157,8 +157,8 @@ func (g *Game) updateGroundImage(ground *ebiten.Image) {
x16, y16 := g.player.Position()
a := g.player.Angle()
rw, rh := repeatedGophersImage.Size()
gw, gh := ground.Size()
rw, rh := repeatedGophersImage.Bounds().Dx(), repeatedGophersImage.Bounds().Dy()
gw, gh := ground.Bounds().Dx(), ground.Bounds().Dy()
op := &ebiten.DrawImageOptions{}
op.GeoM.Translate(float64(-x16)/16, float64(-y16)/16)
op.GeoM.Translate(float64(-rw)/2, float64(-rh)/2)
@ -170,8 +170,8 @@ func (g *Game) updateGroundImage(ground *ebiten.Image) {
// drawGroundImage draws the ground image to the given screen image.
func (g *Game) drawGroundImage(screen *ebiten.Image, ground *ebiten.Image) {
g.perspectiveGroundImage.Clear()
gw, _ := ground.Size()
pw, ph := g.perspectiveGroundImage.Size()
gw := ground.Bounds().Dx()
pw, ph := g.perspectiveGroundImage.Bounds().Dx(), g.perspectiveGroundImage.Bounds().Dy()
for j := 0; j < ph; j++ {
// z is in [2, -1]
rate := float64(j) / float64(ph)
@ -217,7 +217,7 @@ func NewGame() *Game {
}
const fogHeight = 16
w, _ := g.perspectiveGroundImage.Size()
w := g.perspectiveGroundImage.Bounds().Dx()
fogRGBA := image.NewRGBA(image.Rect(0, 0, w, fogHeight))
for j := 0; j < fogHeight; j++ {
a := uint32(float64(fogHeight-1-j) * 0xff / (fogHeight - 1))

View File

@ -162,7 +162,7 @@ func NewPlayer(game *Game, audioContext *audio.Context, musicType musicType) (*P
}
const buttonPadding = 16
w, _ := playButtonImage.Size()
w := playButtonImage.Bounds().Dx()
player.playButtonPosition.X = (screenWidth - w*2 + buttonPadding*1) / 2
player.playButtonPosition.Y = screenHeight - 160
@ -226,7 +226,7 @@ func (p *Player) shouldPlaySE() bool {
}
r := image.Rectangle{
Min: p.alertButtonPosition,
Max: p.alertButtonPosition.Add(image.Pt(alertButtonImage.Size())),
Max: p.alertButtonPosition.Add(alertButtonImage.Bounds().Size()),
}
if image.Pt(ebiten.CursorPosition()).In(r) {
if inpututil.IsMouseButtonJustPressed(ebiten.MouseButtonLeft) {
@ -271,7 +271,7 @@ func (p *Player) shouldSwitchPlayStateIfNeeded() bool {
}
r := image.Rectangle{
Min: p.playButtonPosition,
Max: p.playButtonPosition.Add(image.Pt(playButtonImage.Size())),
Max: p.playButtonPosition.Add(playButtonImage.Bounds().Size()),
}
if image.Pt(ebiten.CursorPosition()).In(r) {
if inpututil.IsMouseButtonJustPressed(ebiten.MouseButtonLeft) {

View File

@ -170,7 +170,7 @@ func init() {
func (s *GameScene) drawBackground(r *ebiten.Image) {
r.Fill(color.White)
w, h := imageGameBG.Size()
w, h := imageGameBG.Bounds().Dx(), imageGameBG.Bounds().Dy()
scaleW := ScreenWidth / float64(w)
scaleH := ScreenHeight / float64(h)
scale := scaleW

View File

@ -94,7 +94,7 @@ func (s *TitleScene) Draw(r *ebiten.Image) {
}
func (s *TitleScene) drawTitleBackground(r *ebiten.Image, c int) {
w, h := imageBackground.Size()
w, h := imageBackground.Bounds().Dx(), imageBackground.Bounds().Dy()
op := &ebiten.DrawImageOptions{}
for i := 0; i < (ScreenWidth/w+1)*(ScreenHeight/h+2); i++ {
op.GeoM.Reset()

View File

@ -44,7 +44,7 @@ func (g *Game) Update() error {
}
func (g *Game) Draw(screen *ebiten.Image) {
w, h := gophersImage.Size()
w, h := gophersImage.Bounds().Dx(), gophersImage.Bounds().Dy()
op := &ebiten.DrawImageOptions{}
// Move the image's center to the screen's upper-left corner.

View File

@ -64,11 +64,11 @@ func (g *Game) Draw(screen *ebiten.Image) {
return
}
w, h := gophersImage.Size()
s := gophersImage.Bounds().Size()
op := &ebiten.DrawImageOptions{}
// For the details, see examples/rotate.
op.GeoM.Translate(-float64(w)/2, -float64(h)/2)
op.GeoM.Translate(-float64(s.X)/2, -float64(s.Y)/2)
op.GeoM.Rotate(float64(g.count%360) * 2 * math.Pi / 360)
op.GeoM.Translate(screenWidth/2, screenHeight/2)
screen.DrawImage(gophersImage, op)

View File

@ -58,7 +58,7 @@ func (s *Sprite) In(x, y int) bool {
// MoveBy moves the sprite by (x, y).
func (s *Sprite) MoveBy(x, y int) {
w, h := s.image.Size()
w, h := s.image.Bounds().Dx(), s.image.Bounds().Dy()
s.x += x
s.y += y
@ -200,7 +200,7 @@ func init() {
func NewGame() *Game {
// Initialize the sprites.
sprites := []*Sprite{}
w, h := ebitenImage.Size()
w, h := ebitenImage.Bounds().Dx(), ebitenImage.Bounds().Dy()
for i := 0; i < 50; i++ {
s := &Sprite{
image: ebitenImage,

View File

@ -353,7 +353,7 @@ func (g *Game) hit() bool {
gopherWidth = 30
gopherHeight = 60
)
w, h := gopherImage.Size()
w, h := gopherImage.Bounds().Dx(), gopherImage.Bounds().Dy()
x0 := floorDiv(g.x16, 16) + (w-gopherWidth)/2
y0 := floorDiv(g.y16, 16) + (h-gopherHeight)/2
x1 := x0 + gopherWidth
@ -437,7 +437,7 @@ func (g *Game) drawTiles(screen *ebiten.Image) {
func (g *Game) drawGopher(screen *ebiten.Image) {
op := &ebiten.DrawImageOptions{}
w, h := gopherImage.Size()
w, h := gopherImage.Bounds().Dx(), gopherImage.Bounds().Dy()
op.GeoM.Translate(-float64(w)/2.0, -float64(h)/2.0)
op.GeoM.Rotate(float64(g.vy16) / 96.0 * math.Pi / 6)
op.GeoM.Translate(float64(w)/2.0, float64(h)/2.0)
@ -461,12 +461,12 @@ func (g *GameWithCRTEffect) DrawFinalScreen(screen ebiten.FinalScreen, offscreen
g.crtShader = s
}
ow, oh := offscreen.Size()
os := offscreen.Bounds().Size()
op := &ebiten.DrawRectShaderOptions{}
op.Images[0] = offscreen
op.GeoM = geoM
screen.DrawRectShader(ow, oh, g.crtShader, op)
screen.DrawRectShader(os.X, os.Y, g.crtShader, op)
}
func main() {

View File

@ -86,13 +86,13 @@ func (g *Game) Update() error {
func (g *Game) Draw(screen *ebiten.Image) {
scale := ebiten.DeviceScaleFactor()
w, h := gophersImage.Size()
w, h := gophersImage.Bounds().Dx(), gophersImage.Bounds().Dy()
op := &ebiten.DrawImageOptions{}
op.GeoM.Translate(-float64(w)/2, -float64(h)/2)
op.GeoM.Scale(scale, scale)
op.GeoM.Rotate(float64(g.count%360) * 2 * math.Pi / 360)
sw, sh := screen.Size()
sw, sh := screen.Bounds().Dx(), screen.Bounds().Dy()
op.GeoM.Translate(float64(sw)/2, float64(sh)/2)
op.Filter = ebiten.FilterLinear
screen.DrawImage(gophersImage, op)

View File

@ -71,9 +71,9 @@ func (g *Game) Draw(screen *ebiten.Image) {
return
}
sw, sh := screen.Size()
sw, sh := screen.Bounds().Dx(), screen.Bounds().Dy()
w, h := g.highDPIImage.Size()
w, h := g.highDPIImage.Bounds().Dx(), g.highDPIImage.Bounds().Dy()
op := &ebiten.DrawImageOptions{}
// Move the images's center to the upper left corner.

View File

@ -100,9 +100,9 @@ func (g *Game) Update() error {
func (g *Game) Draw(screen *ebiten.Image) {
// Center the image on the screen.
w, h := gophersImage.Size()
s := gophersImage.Bounds().Size()
op := &colorm.DrawImageOptions{}
op.GeoM.Translate(-float64(w)/2, -float64(h)/2)
op.GeoM.Translate(-float64(s.X)/2, -float64(s.Y)/2)
op.GeoM.Scale(2, 2)
op.GeoM.Translate(float64(screenWidth)/2, float64(screenHeight)/2)

View File

@ -46,9 +46,9 @@ func (g *Game) Update() error {
func (g *Game) Draw(screen *ebiten.Image) {
// Center the image on the screen.
w, h := gophersImage.Size()
s := gophersImage.Bounds().Size()
op := &colorm.DrawImageOptions{}
op.GeoM.Translate(-float64(w)/2, -float64(h)/2)
op.GeoM.Translate(-float64(s.X)/2, -float64(s.Y)/2)
op.GeoM.Scale(2, 2)
op.GeoM.Translate(float64(screenWidth)/2, float64(screenHeight)/2)

View File

@ -50,12 +50,12 @@ type viewport struct {
}
func (p *viewport) Move() {
w, h := bgImage.Size()
maxX16 := w * 16
maxY16 := h * 16
s := bgImage.Bounds().Size()
maxX16 := s.X * 16
maxY16 := s.Y * 16
p.x16 += w / 32
p.y16 += h / 32
p.x16 += s.X / 32
p.y16 += s.Y / 32
p.x16 %= maxX16
p.y16 %= maxY16
}
@ -79,7 +79,7 @@ func (g *Game) Draw(screen *ebiten.Image) {
// Draw bgImage on the screen repeatedly.
const repeat = 3
w, h := bgImage.Size()
w, h := bgImage.Bounds().Dx(), bgImage.Bounds().Dy()
for j := 0; j < repeat; j++ {
for i := 0; i < repeat; i++ {
op := &ebiten.DrawImageOptions{}

View File

@ -191,15 +191,14 @@ func (g *Game) renderLevel(screen *ebiten.Image) {
// To avoid them, render the result on an offscreen first and then scale it later.
if scaleLater {
if g.offscreen != nil {
w, h := g.offscreen.Size()
sw, sh := screen.Size()
if w != sw || h != sh {
if g.offscreen.Bounds().Size() != screen.Bounds().Size() {
g.offscreen.Dispose()
g.offscreen = nil
}
}
if g.offscreen == nil {
g.offscreen = ebiten.NewImage(screen.Size())
s := screen.Bounds().Size()
g.offscreen = ebiten.NewImage(s.X, s.Y)
}
target = g.offscreen
target.Clear()

View File

@ -87,7 +87,7 @@ func (g *Game) Draw(screen *ebiten.Image) {
vector.LineCapSquare,
}
ow, oh := target.Size()
ow, oh := target.Bounds().Dx(), target.Bounds().Dy()
size := min(ow/(len(joins)+1), oh/(len(caps)+1))
offsetX, offsetY := (ow-size*len(joins))/2, (oh-size*len(caps))/2

View File

@ -102,8 +102,8 @@ func (g *Game) Update() error {
g.spotLightY = -g.spotLightY
g.spotLightVY = -g.spotLightVY
}
w, h := spotLightImage.Size()
maxX, maxY := screenWidth-w, screenHeight-h
s := spotLightImage.Bounds().Size()
maxX, maxY := screenWidth-s.X, screenHeight-s.Y
if maxX < g.spotLightX {
g.spotLightX = -g.spotLightX + 2*maxX
g.spotLightVX = -g.spotLightVX

View File

@ -66,7 +66,7 @@ func (g *Game) Draw(screen *ebiten.Image) {
clippedGophersImage := gophersImage.SubImage(image.Rect(100, 100, 200, 200)).(*ebiten.Image)
for i, f := range []ebiten.Filter{ebiten.FilterNearest, ebiten.FilterLinear} {
w, h := gophersImage.Size()
w, h := gophersImage.Bounds().Dx(), gophersImage.Bounds().Dy()
op := &ebiten.DrawImageOptions{}
if g.rotate {

View File

@ -90,7 +90,8 @@ func (g *game) Update() error {
}
func (g *game) Draw(screen *ebiten.Image) {
screen.WritePixels(getDots(screen.Size()))
s := screen.Bounds().Size()
screen.WritePixels(getDots(s.X, s.Y))
}
func main() {

View File

@ -70,7 +70,7 @@ func (g *Game) Layout(outsideWidth, outsideHeight int) (int, int) {
}
func main() {
w, h := gophersImage.Size()
w, h := gophersImage.Bounds().Dx(), gophersImage.Bounds().Dy()
g := &Game{
gophersRenderTarget: ebiten.NewImage(w/mosaicRatio, h/mosaicRatio),
}

View File

@ -87,7 +87,7 @@ func (s *sprite) draw(screen *ebiten.Image) {
op := &ebiten.DrawImageOptions{}
sx, sy := s.img.Size()
sx, sy := s.img.Bounds().Dx(), s.img.Bounds().Dy()
op.GeoM.Translate(-float64(sx)/2, -float64(sy)/2)
op.GeoM.Rotate(s.angle)
op.GeoM.Scale(s.scale, s.scale)

View File

@ -42,7 +42,7 @@ func (g *Game) Update() error {
func (g *Game) Draw(screen *ebiten.Image) {
// Split the image into horizontal lines and draw them with different scales.
op := &ebiten.DrawImageOptions{}
w, h := gophersImage.Size()
w, h := gophersImage.Bounds().Dx(), gophersImage.Bounds().Dy()
for i := 0; i < h; i++ {
op.GeoM.Reset()

View File

@ -44,13 +44,13 @@ func (g *Game) Update() error {
}
func (g *Game) Draw(screen *ebiten.Image) {
w, h := gophersImage.Size()
s := gophersImage.Bounds().Size()
op := &ebiten.DrawImageOptions{}
// Move the image's center to the screen's upper-left corner.
// This is a preparation for rotating. When geometry matrices are applied,
// the origin point is the upper-left corner.
op.GeoM.Translate(-float64(w)/2, -float64(h)/2)
op.GeoM.Translate(-float64(s.X)/2, -float64(s.Y)/2)
// Rotate the image. As a result, the anchor point of this rotate is
// the center of the image.

View File

@ -45,9 +45,9 @@ func NewGame() *Game {
}
func (g *Game) Update() error {
w, h := g.offscreen.Size()
x := rand.Intn(w)
y := rand.Intn(h)
s := g.offscreen.Bounds().Size()
x := rand.Intn(s.X)
y := rand.Intn(s.Y)
c := color.RGBA{
byte(rand.Intn(256)),
byte(rand.Intn(256)),

View File

@ -141,7 +141,7 @@ func (g *Game) Draw(screen *ebiten.Image) {
return
}
w, h := screen.Size()
w, h := screen.Bounds().Dx(), screen.Bounds().Dy()
cx, cy := ebiten.CursorPosition()
op := &ebiten.DrawRectShaderOptions{}

View File

@ -61,13 +61,13 @@ func (g *Game) Draw(screen *ebiten.Image) {
screen.Clear()
w, h := gophersImage.Size()
s := gophersImage.Bounds().Size()
op := &ebiten.DrawImageOptions{}
// Move the image's center to the screen's upper-left corner.
// This is a preparation for rotating. When geometry matrices are applied,
// the origin point is the upper-left corner.
op.GeoM.Translate(-float64(w)/2, -float64(h)/2)
op.GeoM.Translate(-float64(s.X)/2, -float64(s.Y)/2)
// Rotate the image. As a result, the anchor point of this rotate is
// the center of the image.

View File

@ -46,8 +46,8 @@ func init() {
}
origEbitenImage := ebiten.NewImageFromImage(img)
w, h := origEbitenImage.Size()
ebitenImage = ebiten.NewImage(w, h)
s := origEbitenImage.Bounds().Size()
ebitenImage = ebiten.NewImage(s.X, s.Y)
op := &ebiten.DrawImageOptions{}
op.ColorScale.ScaleAlpha(0.5)
@ -118,7 +118,7 @@ func (g *Game) init() {
g.sprites.sprites = make([]*Sprite, MaxSprites)
g.sprites.num = 500
for i := range g.sprites.sprites {
w, h := ebitenImage.Size()
w, h := ebitenImage.Bounds().Dx(), ebitenImage.Bounds().Dy()
x, y := rand.Intn(screenWidth-w), rand.Intn(screenHeight-h)
vx, vy := 2*rand.Intn(2)-1, 2*rand.Intn(2)-1
a := rand.Intn(maxAngle)
@ -187,7 +187,7 @@ func (g *Game) Draw(screen *ebiten.Image) {
// some conditions e.g. all the rendering sources and targets are same.
// For more detail, see:
// https://pkg.go.dev/github.com/hajimehoshi/ebiten/v2#Image.DrawImage
w, h := ebitenImage.Size()
w, h := ebitenImage.Bounds().Dx(), ebitenImage.Bounds().Dy()
for i := 0; i < g.sprites.num; i++ {
s := g.sprites.sprites[i]
g.op.GeoM.Reset()

View File

@ -47,8 +47,8 @@ func init() {
}
origEbitenImage := ebiten.NewImageFromImage(img)
w, h := origEbitenImage.Size()
ebitenImage = ebiten.NewImage(w, h)
s := origEbitenImage.Bounds().Size()
ebitenImage = ebiten.NewImage(s.X, s.Y)
op := &ebiten.DrawImageOptions{}
op.ColorScale.ScaleAlpha(0.5)
@ -116,7 +116,7 @@ func (g *Game) init() {
g.sprites.sprites = make([]*Sprite, MaxSprites)
g.sprites.num = 500
for i := range g.sprites.sprites {
w, h := ebitenImage.Size()
w, h := ebitenImage.Bounds().Dx(), ebitenImage.Bounds().Dy()
x, y := rand.Intn(screenWidth-w), rand.Intn(screenHeight-h)
vx, vy := 2*rand.Intn(2)-1, 2*rand.Intn(2)-1
a := rand.Intn(maxAngle)
@ -168,7 +168,7 @@ func (g *Game) Draw(screen *ebiten.Image) {
// some conditions e.g. all the rendering sources and targets are same.
// For more detail, see:
// https://pkg.go.dev/github.com/hajimehoshi/ebiten/v2#Image.DrawImage
w, h := ebitenImage.Size()
w, h := ebitenImage.Bounds().Dx(), ebitenImage.Bounds().Dy()
for i := 0; i < g.sprites.num; i++ {
s := g.sprites.sprites[i]
g.op.GeoM.Reset()

View File

@ -40,12 +40,13 @@ func (g *Game) Update() error {
func (g *Game) Draw(screen *ebiten.Image) {
if g.offscreen == nil {
g.offscreen = ebiten.NewImage(screen.Size())
s := screen.Bounds().Size()
g.offscreen = ebiten.NewImage(s.X, s.Y)
}
// Use various sub-images as rendering destination.
// This is a proof-of-concept of efficient rendering with sub-images (#2232).
sw, sh := screen.Size()
sw, sh := screen.Bounds().Dx(), screen.Bounds().Dy()
cw := sw / cx
ch := sh / cy
for j := 0; j < cy; j++ {

View File

@ -57,7 +57,7 @@ func (g *Game) Update() error {
}
func (g *Game) Draw(screen *ebiten.Image) {
w, _ := tilesImage.Size()
w := tilesImage.Bounds().Dx()
tileXCount := w / tileSize
// Draw each tile with each DrawImage call.

View File

@ -213,7 +213,7 @@ func (g *Game) Draw(screen *ebiten.Image) {
op.GeoM.Translate(g.x, g.y)
// Center the image (corrected by the current zoom).
w, h := gophersImage.Size()
w, h := gophersImage.Bounds().Dx(), gophersImage.Bounds().Dy()
op.GeoM.Translate(float64(-w)/2*g.zoom, float64(-h)/2*g.zoom)
screen.DrawImage(gophersImage, op)

View File

@ -340,7 +340,7 @@ func (t *TextBox) Draw(dst *ebiten.Image) {
if t.contentBuf != nil {
vw, vh := t.viewSize()
w, h := t.contentBuf.Size()
w, h := t.contentBuf.Bounds().Dx(), t.contentBuf.Bounds().Dy()
if vw > w || vh > h {
t.contentBuf.Dispose()
t.contentBuf = nil

View File

@ -308,8 +308,8 @@ func (g *game) Update() error {
}
func (g *game) Draw(screen *ebiten.Image) {
w, h := gophersImage.Size()
w2, h2 := screen.Size()
w, h := gophersImage.Bounds().Dx(), gophersImage.Bounds().Dy()
w2, h2 := screen.Bounds().Dx(), screen.Bounds().Dy()
op := &ebiten.DrawImageOptions{}
op.GeoM.Translate(float64(-w+w2)/2, float64(-h+h2)/2)
dx := math.Cos(2*math.Pi*float64(g.count)/360) * 20

View File

@ -193,7 +193,7 @@ func (g *gameForUI) DrawFinalScreen(scale, offsetX, offsetY float64) {
op := &DrawRectShaderOptions{}
op.Images[0] = g.offscreen
op.GeoM = geoM
w, h := g.offscreen.Size()
w, h := g.offscreen.Bounds().Dx(), g.offscreen.Bounds().Dy()
g.screen.DrawRectShader(w, h, g.screenShader, op)
}
}

View File

@ -55,6 +55,8 @@ func (i *Image) copyCheck() {
}
// Size returns the size of the image.
//
// Deprecated: as of v2.5. Use Bounds().Dx() and Bounds().Dy() or Bounds().Size() instead.
func (i *Image) Size() (width, height int) {
s := i.Bounds().Size()
return s.X, s.Y
@ -606,7 +608,7 @@ func (i *Image) DrawTrianglesShader(vertices []Vertex, indices []uint16, shader
copy(is, indices)
var imgs [graphics.ShaderImageCount]*ui.Image
var imgw, imgh int
var imgSize image.Point
for i, img := range options.Images {
if img == nil {
continue
@ -615,10 +617,10 @@ func (i *Image) DrawTrianglesShader(vertices []Vertex, indices []uint16, shader
panic("ebiten: the given image to DrawTrianglesShader must not be disposed")
}
if i == 0 {
imgw, imgh = img.Size()
imgSize = img.Bounds().Size()
} else {
// TODO: Check imgw > 0 && imgh > 0
if w, h := img.Size(); imgw != w || imgh != h {
if img.Bounds().Size() != imgSize {
panic("ebiten: all the source images must be the same size with the rectangle")
}
}
@ -723,7 +725,7 @@ func (i *Image) DrawRectShader(width, height int, shader *Shader, options *DrawR
if img.isDisposed() {
panic("ebiten: the given image to DrawRectShader must not be disposed")
}
if w, h := img.Size(); width != w || height != h {
if img.Bounds().Size() != image.Pt(width, height) {
panic("ebiten: all the source images must be the same size with the rectangle")
}
imgs[i] = img.image

View File

@ -103,7 +103,7 @@ func TestImagePixels(t *testing.T) {
t.Fatalf("img size: got %d; want %d", got, img.Bounds().Size())
}
w, h := img0.Bounds().Size().X, img0.Bounds().Size().Y
w, h := img0.Bounds().Dx(), img0.Bounds().Dy()
// Check out of range part
w2, h2 := graphics.InternalImageSize(w), graphics.InternalImageSize(h)
for j := -100; j < h2+100; j++ {
@ -141,7 +141,7 @@ func TestImageComposition(t *testing.T) {
return
}
w, h := img1.Bounds().Size().X, img1.Bounds().Size().Y
w, h := img1.Bounds().Dx(), img1.Bounds().Dy()
img2 := ebiten.NewImage(w, h)
img3 := ebiten.NewImage(w, h)
@ -199,7 +199,7 @@ func TestImageScale(t *testing.T) {
t.Fatal(err)
return
}
w, h := img0.Size()
w, h := img0.Bounds().Dx(), img0.Bounds().Dy()
img1 := ebiten.NewImage(w*scale, h*scale)
op := &ebiten.DrawImageOptions{}
op.GeoM.Scale(float64(scale), float64(scale))
@ -224,7 +224,7 @@ func TestImage90DegreeRotate(t *testing.T) {
t.Fatal(err)
return
}
w, h := img0.Size()
w, h := img0.Bounds().Dx(), img0.Bounds().Dy()
img1 := ebiten.NewImage(h, w)
op := &ebiten.DrawImageOptions{}
op.GeoM.Rotate(math.Pi / 2)
@ -248,7 +248,7 @@ func TestImageDotByDotInversion(t *testing.T) {
t.Fatal(err)
return
}
w, h := img0.Size()
w, h := img0.Bounds().Dx(), img0.Bounds().Dy()
img1 := ebiten.NewImage(w, h)
op := &ebiten.DrawImageOptions{}
op.GeoM.Rotate(math.Pi)
@ -284,8 +284,8 @@ func TestImageWritePixels(t *testing.T) {
img0 := ebiten.NewImage(size.X, size.Y)
img0.WritePixels(img.Pix)
for j := 0; j < img0.Bounds().Size().Y; j++ {
for i := 0; i < img0.Bounds().Size().X; i++ {
for j := 0; j < img0.Bounds().Dy(); j++ {
for i := 0; i < img0.Bounds().Dx(); i++ {
got := img0.At(i, j)
want := img.At(i, j)
if got != want {
@ -303,8 +303,8 @@ func TestImageWritePixels(t *testing.T) {
for i := range p {
p[i] = 0
}
for j := 0; j < img0.Bounds().Size().Y; j++ {
for i := 0; i < img0.Bounds().Size().X; i++ {
for j := 0; j < img0.Bounds().Dy(); j++ {
for i := 0; i < img0.Bounds().Dx(); i++ {
got := img0.At(i, j)
want := color.RGBA{0x80, 0x80, 0x80, 0x80}
if got != want {
@ -354,14 +354,14 @@ func TestImageBlendLighter(t *testing.T) {
return
}
w, h := img0.Size()
w, h := img0.Bounds().Dx(), img0.Bounds().Dy()
img1 := ebiten.NewImage(w, h)
img1.Fill(color.RGBA{0x01, 0x02, 0x03, 0x04})
op := &ebiten.DrawImageOptions{}
op.Blend = ebiten.BlendLighter
img1.DrawImage(img0, op)
for j := 0; j < img1.Bounds().Size().Y; j++ {
for i := 0; i < img1.Bounds().Size().X; i++ {
for j := 0; j < img1.Bounds().Dy(); j++ {
for i := 0; i < img1.Bounds().Dx(); i++ {
got := img1.At(i, j).(color.RGBA)
want := img0.At(i, j).(color.RGBA)
want.R = uint8(min(0xff, int(want.R)+1))
@ -394,7 +394,7 @@ func TestNewImageFromSubImage(t *testing.T) {
subImg := img.(*image.NRGBA).SubImage(image.Rect(1, 1, w-1, h-1))
eimg := ebiten.NewImageFromImage(subImg)
sw, sh := subImg.Bounds().Dx(), subImg.Bounds().Dy()
w2, h2 := eimg.Size()
w2, h2 := eimg.Bounds().Dx(), eimg.Bounds().Dy()
if w2 != sw {
t.Errorf("eimg Width: got %v; want %v", w2, sw)
}
@ -510,7 +510,7 @@ func TestImageEdge(t *testing.T) {
for _, a := range angles {
for _, testDrawTriangles := range []bool{false, true} {
img1.Clear()
w, h := img0.Size()
w, h := img0.Bounds().Dx(), img0.Bounds().Dy()
b := img0.Bounds()
var geo ebiten.GeoM
geo.Translate(-float64(w)/2, -float64(h)/2)
@ -741,7 +741,7 @@ func TestImageSize(t *testing.T) {
h = 31
)
img := ebiten.NewImage(w, h)
gotW, gotH := img.Size()
gotW, gotH := img.Bounds().Dx(), img.Bounds().Dy()
if gotW != w {
t.Errorf("got: %d, want: %d", gotW, w)
}
@ -835,7 +835,7 @@ loop:
}
src.WritePixels(pix)
_, dh := dst.Size()
dh := dst.Bounds().Dy()
for i := 0; i < dh; {
dst.Clear()
op := &ebiten.DrawImageOptions{}
@ -902,7 +902,7 @@ func Disabled_TestImageMipmap(t *testing.T) {
t.Fatal(err)
return
}
w, h := src.Size()
w, h := src.Bounds().Dx(), src.Bounds().Dy()
l1 := ebiten.NewImage(w/2, h/2)
op := &ebiten.DrawImageOptions{}
@ -910,7 +910,7 @@ func Disabled_TestImageMipmap(t *testing.T) {
op.Filter = ebiten.FilterLinear
l1.DrawImage(src, op)
l1w, l1h := l1.Size()
l1w, l1h := l1.Bounds().Dx(), l1.Bounds().Dy()
l2 := ebiten.NewImage(l1w/2, l1h/2)
op = &ebiten.DrawImageOptions{}
op.GeoM.Scale(1/2.0, 1/2.0)
@ -947,7 +947,7 @@ func Disabled_TestImageMipmapNegativeDet(t *testing.T) {
t.Fatal(err)
return
}
w, h := src.Size()
w, h := src.Bounds().Dx(), src.Bounds().Dy()
l1 := ebiten.NewImage(w/2, h/2)
op := &ebiten.DrawImageOptions{}
@ -955,7 +955,7 @@ func Disabled_TestImageMipmapNegativeDet(t *testing.T) {
op.Filter = ebiten.FilterLinear
l1.DrawImage(src, op)
l1w, l1h := l1.Size()
l1w, l1h := l1.Bounds().Dx(), l1.Bounds().Dy()
l2 := ebiten.NewImage(l1w/2, l1h/2)
op = &ebiten.DrawImageOptions{}
op.GeoM.Scale(1/2.0, 1/2.0)
@ -1091,7 +1091,7 @@ func TestImageMiamapAndDrawTriangle(t *testing.T) {
op.Filter = ebiten.FilterLinear
img0.DrawImage(img1, op)
w, h := img0.Size()
w, h := img0.Bounds().Dx(), img0.Bounds().Dy()
for j := 0; j < h; j++ {
for i := 0; i < w; i++ {
c := img0.At(i, j).(color.RGBA)
@ -1123,7 +1123,7 @@ func TestImageSubImageSize(t *testing.T) {
img := ebiten.NewImage(16, 16)
img.Fill(color.RGBA{0xff, 0, 0, 0xff})
got, _ := img.SubImage(image.Rect(1, 1, 16, 16)).(*ebiten.Image).Size()
got := img.SubImage(image.Rect(1, 1, 16, 16)).Bounds().Dx()
want := 15
if got != want {
t.Errorf("got: %v, want: %v", got, want)

View File

@ -65,7 +65,7 @@ func (g *Game) Draw(screen *ebiten.Image) {
screen.DrawImage(srcInit, nil)
if g.dst == nil {
g.dst = ebiten.NewImage(screen.Size())
g.dst = ebiten.NewImage(screen.Bounds().Dx(), screen.Bounds().Dy())
return
}

1
run.go
View File

@ -96,7 +96,6 @@ type LayoutFer interface {
// FinalScreen implements a part of Image functions.
type FinalScreen interface {
Bounds() image.Rectangle
Size() (int, int)
DrawImage(img *Image, options *DrawImageOptions)
DrawTriangles(vertices []Vertex, indices []uint16, img *Image, options *DrawTrianglesOptions)

View File

@ -37,7 +37,7 @@ func TestTextColor(t *testing.T) {
img := ebiten.NewImage(30, 30)
text.Draw(img, "Hello", bitmapfont.Face, 12, 12, clr)
w, h := img.Size()
w, h := img.Bounds().Dx(), img.Bounds().Dy()
allTransparent := true
for j := 0; j < h; j++ {
for i := 0; i < w; i++ {