Skip to content

Commit

Permalink
ebiten: deprecate (*Image).Size
Browse files Browse the repository at this point in the history
  • Loading branch information
hajimehoshi committed Jan 19, 2023
1 parent 8d61d43 commit f054a76
Show file tree
Hide file tree
Showing 43 changed files with 111 additions and 114 deletions.
3 changes: 1 addition & 2 deletions colorm/draw.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,14 @@ 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
opShader.Blend = op.Blend
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.
Expand Down
2 changes: 1 addition & 1 deletion ebitenutil/debugprint.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 3 additions & 6 deletions ebitenutil/fs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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)
}
}
7 changes: 3 additions & 4 deletions examples/2048/2048/game.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
2 changes: 1 addition & 1 deletion examples/additive/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
14 changes: 7 additions & 7 deletions examples/airship/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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++ {
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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))
Expand Down
6 changes: 3 additions & 3 deletions examples/audio/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion examples/blocks/blocks/gamescene.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion examples/blocks/blocks/titlescene.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion examples/clip/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions examples/contextlost/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions examples/drag/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down
8 changes: 4 additions & 4 deletions examples/flappy/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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() {
Expand Down
4 changes: 2 additions & 2 deletions examples/fullscreen/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions examples/highdpi/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions examples/hsv/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
4 changes: 2 additions & 2 deletions examples/hue/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
12 changes: 6 additions & 6 deletions examples/infinitescroll/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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{}
Expand Down
7 changes: 3 additions & 4 deletions examples/isometric/game.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion examples/lines/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions examples/masking/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion examples/minify/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
3 changes: 2 additions & 1 deletion examples/moire/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
2 changes: 1 addition & 1 deletion examples/mosaic/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
}
Expand Down
2 changes: 1 addition & 1 deletion examples/particles/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading

0 comments on commit f054a76

Please sign in to comment.