diff --git a/colorm/draw.go b/colorm/draw.go index aa60a105a..e51b7052c 100644 --- a/colorm/draw.go +++ b/colorm/draw.go @@ -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. diff --git a/ebitenutil/debugprint.go b/ebitenutil/debugprint.go index 900a567ff..c55988e99 100644 --- a/ebitenutil/debugprint.go +++ b/ebitenutil/debugprint.go @@ -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 diff --git a/ebitenutil/fs_test.go b/ebitenutil/fs_test.go index d37cf97c1..250f5a646 100644 --- a/ebitenutil/fs_test.go +++ b/ebitenutil/fs_test.go @@ -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) } } diff --git a/examples/2048/2048/game.go b/examples/2048/2048/game.go index cd62f4160..dcb1ec482 100644 --- a/examples/2048/2048/game.go +++ b/examples/2048/2048/game.go @@ -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)) diff --git a/examples/additive/main.go b/examples/additive/main.go index f0a021fbd..463d6d8a0 100644 --- a/examples/additive/main.go +++ b/examples/additive/main.go @@ -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) diff --git a/examples/airship/main.go b/examples/airship/main.go index f3361bcec..1565b0f6f 100644 --- a/examples/airship/main.go +++ b/examples/airship/main.go @@ -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)) diff --git a/examples/audio/main.go b/examples/audio/main.go index d6ccdea32..e62572b13 100644 --- a/examples/audio/main.go +++ b/examples/audio/main.go @@ -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) { diff --git a/examples/blocks/blocks/gamescene.go b/examples/blocks/blocks/gamescene.go index d4129ba8b..fab944cd3 100644 --- a/examples/blocks/blocks/gamescene.go +++ b/examples/blocks/blocks/gamescene.go @@ -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 diff --git a/examples/blocks/blocks/titlescene.go b/examples/blocks/blocks/titlescene.go index f6bfaff9b..d3d8f151f 100644 --- a/examples/blocks/blocks/titlescene.go +++ b/examples/blocks/blocks/titlescene.go @@ -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() diff --git a/examples/clip/main.go b/examples/clip/main.go index e4da10419..d6de71f87 100644 --- a/examples/clip/main.go +++ b/examples/clip/main.go @@ -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. diff --git a/examples/contextlost/main.go b/examples/contextlost/main.go index 958f324b9..180ea237a 100644 --- a/examples/contextlost/main.go +++ b/examples/contextlost/main.go @@ -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) diff --git a/examples/drag/main.go b/examples/drag/main.go index f83e05bbc..8cb05b5f7 100644 --- a/examples/drag/main.go +++ b/examples/drag/main.go @@ -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, diff --git a/examples/flappy/main.go b/examples/flappy/main.go index df2e03859..7cd5c92bb 100644 --- a/examples/flappy/main.go +++ b/examples/flappy/main.go @@ -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() { diff --git a/examples/fullscreen/main.go b/examples/fullscreen/main.go index 89bf13698..d92cfd7fe 100644 --- a/examples/fullscreen/main.go +++ b/examples/fullscreen/main.go @@ -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) diff --git a/examples/highdpi/main.go b/examples/highdpi/main.go index 696cb156c..240197429 100644 --- a/examples/highdpi/main.go +++ b/examples/highdpi/main.go @@ -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. diff --git a/examples/hsv/main.go b/examples/hsv/main.go index 048624597..236b6be55 100644 --- a/examples/hsv/main.go +++ b/examples/hsv/main.go @@ -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) diff --git a/examples/hue/main.go b/examples/hue/main.go index a253e5f77..675d71f93 100644 --- a/examples/hue/main.go +++ b/examples/hue/main.go @@ -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) diff --git a/examples/infinitescroll/main.go b/examples/infinitescroll/main.go index 2944b19d1..408abe39f 100644 --- a/examples/infinitescroll/main.go +++ b/examples/infinitescroll/main.go @@ -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{} diff --git a/examples/isometric/game.go b/examples/isometric/game.go index 322804f3d..752cc2750 100644 --- a/examples/isometric/game.go +++ b/examples/isometric/game.go @@ -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() diff --git a/examples/lines/main.go b/examples/lines/main.go index 38575d9af..6563fabf4 100644 --- a/examples/lines/main.go +++ b/examples/lines/main.go @@ -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 diff --git a/examples/masking/main.go b/examples/masking/main.go index 24474de93..5fdb53dfd 100644 --- a/examples/masking/main.go +++ b/examples/masking/main.go @@ -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 diff --git a/examples/minify/main.go b/examples/minify/main.go index e924d540f..f8847866b 100644 --- a/examples/minify/main.go +++ b/examples/minify/main.go @@ -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 { diff --git a/examples/moire/main.go b/examples/moire/main.go index e8c78893c..7a53c7ad0 100644 --- a/examples/moire/main.go +++ b/examples/moire/main.go @@ -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() { diff --git a/examples/mosaic/main.go b/examples/mosaic/main.go index f9ad6faf5..16cf747eb 100644 --- a/examples/mosaic/main.go +++ b/examples/mosaic/main.go @@ -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), } diff --git a/examples/particles/main.go b/examples/particles/main.go index d30538a8a..b1b44b71b 100644 --- a/examples/particles/main.go +++ b/examples/particles/main.go @@ -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) diff --git a/examples/perspective/main.go b/examples/perspective/main.go index bc30055d3..0fdc574ff 100644 --- a/examples/perspective/main.go +++ b/examples/perspective/main.go @@ -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() diff --git a/examples/rotate/main.go b/examples/rotate/main.go index 23af2bafc..2ab852901 100644 --- a/examples/rotate/main.go +++ b/examples/rotate/main.go @@ -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. diff --git a/examples/set/main.go b/examples/set/main.go index af97515cb..bb00c50d7 100644 --- a/examples/set/main.go +++ b/examples/set/main.go @@ -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)), diff --git a/examples/shader/main.go b/examples/shader/main.go index a532b8f7d..67e634fa8 100644 --- a/examples/shader/main.go +++ b/examples/shader/main.go @@ -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{} diff --git a/examples/skipdraw/main.go b/examples/skipdraw/main.go index cd9464b68..3cfd18df3 100644 --- a/examples/skipdraw/main.go +++ b/examples/skipdraw/main.go @@ -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. diff --git a/examples/sprites/main.go b/examples/sprites/main.go index 795d015d0..16afb0da6 100644 --- a/examples/sprites/main.go +++ b/examples/sprites/main.go @@ -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() diff --git a/examples/spriteshd/main.go b/examples/spriteshd/main.go index b03fb5582..4d6dd5635 100644 --- a/examples/spriteshd/main.go +++ b/examples/spriteshd/main.go @@ -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() diff --git a/examples/subimage/main.go b/examples/subimage/main.go index adb4c5490..90e287782 100644 --- a/examples/subimage/main.go +++ b/examples/subimage/main.go @@ -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++ { diff --git a/examples/tiles/main.go b/examples/tiles/main.go index fa58dce02..d5d538ac3 100644 --- a/examples/tiles/main.go +++ b/examples/tiles/main.go @@ -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. diff --git a/examples/touch/main.go b/examples/touch/main.go index 9b6df382e..f05b835ca 100644 --- a/examples/touch/main.go +++ b/examples/touch/main.go @@ -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) diff --git a/examples/ui/main.go b/examples/ui/main.go index f6b55404e..bbb8ad43a 100644 --- a/examples/ui/main.go +++ b/examples/ui/main.go @@ -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 diff --git a/examples/windowsize/main.go b/examples/windowsize/main.go index a30e18c98..9e2c8e2ff 100644 --- a/examples/windowsize/main.go +++ b/examples/windowsize/main.go @@ -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 diff --git a/gameforui.go b/gameforui.go index f5c452c4e..76cff965a 100644 --- a/gameforui.go +++ b/gameforui.go @@ -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) } } diff --git a/image.go b/image.go index 0716007c4..df5158d1e 100644 --- a/image.go +++ b/image.go @@ -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 diff --git a/image_test.go b/image_test.go index 458363871..75eef8294 100644 --- a/image_test.go +++ b/image_test.go @@ -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) diff --git a/internal/processtest/testdata/issue2154_1.go b/internal/processtest/testdata/issue2154_1.go index 9073b2103..c35613496 100644 --- a/internal/processtest/testdata/issue2154_1.go +++ b/internal/processtest/testdata/issue2154_1.go @@ -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 } diff --git a/run.go b/run.go index 8fe6e0ed5..aeeed81b5 100644 --- a/run.go +++ b/run.go @@ -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) diff --git a/text/text_test.go b/text/text_test.go index 3602c8e66..adfead0b5 100644 --- a/text/text_test.go +++ b/text/text_test.go @@ -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++ {