From 7849a68cd096f6da57c5bd80e73b65b4c17cd311 Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Fri, 26 Dec 2014 23:01:47 +0900 Subject: [PATCH] Remove DrawImageAt --- ebitenutil/debugprint.go | 3 ++- example/alphablending/main.go | 8 ++++++-- example/blocks/blocks/piece.go | 6 +++--- example/blocks/blocks/titlescene.go | 11 ++++++----- example/paint/main.go | 3 ++- image.go | 11 ----------- 6 files changed, 19 insertions(+), 23 deletions(-) diff --git a/ebitenutil/debugprint.go b/ebitenutil/debugprint.go index f22ea99a8..b87c4630d 100644 --- a/ebitenutil/debugprint.go +++ b/ebitenutil/debugprint.go @@ -58,9 +58,10 @@ func (d *debugPrintState) drawText(rt *ebiten.Image, str string, x, y int, c col g := float64(cc.G) / math.MaxUint16 b := float64(cc.B) / math.MaxUint16 a := float64(cc.A) / math.MaxUint16 - rt.DrawImageAt(d.textImage, x+1, y, &ebiten.DrawImageOptions{ + rt.DrawImage(d.textImage, &ebiten.DrawImageOptions{ DstParts: dsts, SrcParts: srcs, + GeoM: ebiten.TranslateGeo(float64(x+1), float64(y)), ColorM: ebiten.ScaleColor(r, g, b, a), }) } diff --git a/example/alphablending/main.go b/example/alphablending/main.go index cf1fc7ceb..a2c5efdf0 100644 --- a/example/alphablending/main.go +++ b/example/alphablending/main.go @@ -50,16 +50,20 @@ func update(screen *ebiten.Image) error { } for i := 0; i < 10; i++ { op := &ebiten.DrawImageOptions{ + GeoM: ebiten.TranslateGeo(15+float64(i)*diff, 20), ColorM: ebiten.ScaleColor(1.0, 1.0, 1.0, 0.5), } - if err := tmpRenderTarget.DrawImageAt(ebitenImage, 15+int(float64(i)*diff), 20, op); err != nil { + if err := tmpRenderTarget.DrawImage(ebitenImage, op); err != nil { return err } } screen.Fill(color.NRGBA{0x00, 0x00, 0x80, 0xff}) for i := 0; i < 10; i++ { - if err := screen.DrawImageAt(tmpRenderTarget, 0, int(float64(i)*diff), nil); err != nil { + op := &ebiten.DrawImageOptions{ + GeoM: ebiten.TranslateGeo(0, float64(i)*diff), + } + if err := screen.DrawImage(tmpRenderTarget, op); err != nil { return err } } diff --git a/example/blocks/blocks/piece.go b/example/blocks/blocks/piece.go index daef68891..3bbff3f7d 100644 --- a/example/blocks/blocks/piece.go +++ b/example/blocks/blocks/piece.go @@ -144,15 +144,15 @@ func drawBlocks(r *ebiten.Image, images *Images, blocks [][]BlockType, x, y int) if block == BlockTypeNone { continue } - locationX := i * blockWidth - locationY := j * blockHeight + locationX := i*blockWidth + x + locationY := j*blockHeight + y dsts = append(dsts, image.Rect(locationX, locationY, locationX+blockWidth, locationY+blockHeight)) srcX := (int(block) - 1) * blockWidth srcs = append(srcs, image.Rect(srcX, 0, srcX+blockWidth, blockHeight)) } } blocksImage := images.GetImage("blocks") - r.DrawImageAt(blocksImage, x, y, &ebiten.DrawImageOptions{ + r.DrawImage(blocksImage, &ebiten.DrawImageOptions{ SrcParts: srcs, DstParts: dsts, }) diff --git a/example/blocks/blocks/titlescene.go b/example/blocks/blocks/titlescene.go index 21e3c3b86..1ffd0433b 100644 --- a/example/blocks/blocks/titlescene.go +++ b/example/blocks/blocks/titlescene.go @@ -53,20 +53,21 @@ func drawTitleBackground(r *ebiten.Image, images *Images, c int) { const imageWidth = 32 const imageHeight = 32 + dx := (-c / 4) % imageWidth + dy := (c / 4) % imageHeight + backgroundImage := images.GetImage("background") dsts, srcs := []image.Rectangle{}, []image.Rectangle{} for j := -1; j < ScreenHeight/imageHeight+1; j++ { for i := 0; i < ScreenWidth/imageWidth+1; i++ { - dstX := i * imageWidth - dstY := j * imageHeight + dstX := i*imageWidth + dx + dstY := j*imageHeight + dy dsts = append(dsts, image.Rect(dstX, dstY, dstX+imageWidth, dstY+imageHeight)) srcs = append(srcs, image.Rect(0, 0, imageWidth, imageHeight)) } } - dx := (-c / 4) % imageWidth - dy := (c / 4) % imageHeight - r.DrawImageAt(backgroundImage, dx, dy, &ebiten.DrawImageOptions{ + r.DrawImage(backgroundImage, &ebiten.DrawImageOptions{ SrcParts: srcs, DstParts: dsts, }) diff --git a/example/paint/main.go b/example/paint/main.go index d8b3ba623..bedbe2767 100644 --- a/example/paint/main.go +++ b/example/paint/main.go @@ -45,7 +45,8 @@ func Update(screen *ebiten.Image) error { clr := ebiten.ScaleColor(1.0, 0.25, 0.25, 1.0) theta := 2.0 * math.Pi * float64(count%60) / 60.0 clr.Concat(ebiten.RotateHue(theta)) - canvasRenderTarget.DrawImageAt(brushRenderTarget, mx, my, &ebiten.DrawImageOptions{ + canvasRenderTarget.DrawImage(brushRenderTarget, &ebiten.DrawImageOptions{ + GeoM: ebiten.TranslateGeo(float64(mx), float64(my)), ColorM: clr, }) } diff --git a/image.go b/image.go index ad2f2d90d..3b4298b3a 100644 --- a/image.go +++ b/image.go @@ -161,17 +161,6 @@ func (i *Image) DrawImage(image *Image, options *DrawImageOptions) (err error) { return i.drawImage(image.inner, options) } -// DrawImageAt draws the given image on the receiver image at the position (x, y). -// -// If a geometry matrix is specified, the geometry matrix is applied ahead of translating the image by (x, y). -func (i *Image) DrawImageAt(image *Image, x, y int, options *DrawImageOptions) (err error) { - if options == nil { - options = &DrawImageOptions{} - } - options.GeoM.Concat(TranslateGeo(float64(x), float64(y))) - return i.drawImage(image.inner, options) -} - func (i *Image) drawImage(image *innerImage, option *DrawImageOptions) (err error) { i.pixels = nil i.syncer.Sync(func() {