diff --git a/ebitenutil/debugprint.go b/ebitenutil/debugprint.go index 2eefa59d3..2e21a609a 100644 --- a/ebitenutil/debugprint.go +++ b/ebitenutil/debugprint.go @@ -48,9 +48,8 @@ func (d *debugPrintState) drawText(gr ebiten.GraphicsContext, str string, x, y i srcX := (code % xCharNum) * assets.TextImageCharWidth srcY := (code / xCharNum) * assets.TextImageCharHeight parts = append(parts, ebiten.TexturePart{ - LocationX: locationX, - LocationY: locationY, - Source: ebiten.Rect{srcX, srcY, assets.TextImageCharWidth, assets.TextImageCharHeight}, + Dst: ebiten.Rect{locationX, locationY, assets.TextImageCharWidth, assets.TextImageCharHeight}, + Src: ebiten.Rect{srcX, srcY, assets.TextImageCharWidth, assets.TextImageCharHeight}, }) locationX += assets.TextImageCharWidth } diff --git a/example/blocks/blocks/font.go b/example/blocks/blocks/font.go index f94a58e96..7ba98ce53 100644 --- a/example/blocks/blocks/font.go +++ b/example/blocks/blocks/font.go @@ -48,9 +48,8 @@ func drawText(context ebiten.GraphicsContext, textures *Textures, str string, x, x := (code % 16) * charWidth y := ((code - 32) / 16) * charHeight parts = append(parts, ebiten.TexturePart{ - LocationX: locationX, - LocationY: locationY, - Source: ebiten.Rect{x, y, charWidth, charHeight}, + Dst: ebiten.Rect{locationX, locationY, charWidth, charHeight}, + Src: ebiten.Rect{x, y, charWidth, charHeight}, }) locationX += charWidth } diff --git a/example/blocks/blocks/piece.go b/example/blocks/blocks/piece.go index b82761398..363f45e48 100644 --- a/example/blocks/blocks/piece.go +++ b/example/blocks/blocks/piece.go @@ -147,15 +147,9 @@ func drawBlocks(context ebiten.GraphicsContext, textures *Textures, blocks [][]B } locationX := i * blockWidth locationY := j * blockHeight - source := ebiten.Rect{ - (int(block) - 1) * blockWidth, 0, - blockWidth, blockHeight} - parts = append(parts, - ebiten.TexturePart{ - LocationX: locationX, - LocationY: locationY, - Source: source, - }) + dst := ebiten.Rect{locationX, locationY, blockWidth, blockHeight} + src := ebiten.Rect{(int(block) - 1) * blockWidth, 0, blockWidth, blockHeight} + parts = append(parts, ebiten.TexturePart{dst, src}) } } blocksTexture := textures.GetTexture("blocks") diff --git a/example/blocks/blocks/titlescene.go b/example/blocks/blocks/titlescene.go index c6aa98b96..6728a07e9 100644 --- a/example/blocks/blocks/titlescene.go +++ b/example/blocks/blocks/titlescene.go @@ -59,9 +59,8 @@ func drawTitleBackground(context ebiten.GraphicsContext, textures *Textures, c i for j := -1; j < ScreenHeight/textureHeight+1; j++ { for i := 0; i < ScreenWidth/textureWidth+1; i++ { parts = append(parts, ebiten.TexturePart{ - LocationX: i * textureWidth, - LocationY: j * textureHeight, - Source: ebiten.Rect{0, 0, textureWidth, textureHeight}, + Dst: ebiten.Rect{i * textureWidth, j * textureHeight, textureWidth, textureHeight}, + Src: ebiten.Rect{0, 0, textureWidth, textureHeight}, }) } } diff --git a/example/image/main.go b/example/image/main.go index e7e9b5c4b..4308cdb3c 100644 --- a/example/image/main.go +++ b/example/image/main.go @@ -58,7 +58,8 @@ func (g *Game) Update(gr ebiten.GraphicsContext) error { geo.Concat(ebiten.ScaleGeometry(scaleX, scaleY)) geo.Concat(ebiten.RotateGeometry(float64(g.count%720) * 2 * math.Pi / 720)) geo.Concat(ebiten.TranslateGeometry(screenWidth/2, screenHeight/2)) - clr := ebiten.RotateHue(float64(g.count%180) * 2 * math.Pi / 180) + //clr := ebiten.RotateHue(float64(g.count%180) * 2 * math.Pi / 180) + clr := ebiten.ColorMatrixI() ebiten.DrawWholeTexture(gr, g.gophersTexture, geo, clr) return nil } diff --git a/graphics.go b/graphics.go index a30320110..e97367c62 100644 --- a/graphics.go +++ b/graphics.go @@ -31,9 +31,8 @@ type Rect struct { // A TexturePart represents a part of a texture. type TexturePart struct { - LocationX int - LocationY int - Source Rect + Dst Rect + Src Rect } // A Drawer is the interface that draws itself. @@ -45,7 +44,7 @@ type Drawer interface { func DrawWholeTexture(g GraphicsContext, texture *Texture, geo GeometryMatrix, color ColorMatrix) error { w, h := texture.Size() parts := []TexturePart{ - {0, 0, Rect{0, 0, w, h}}, + {Rect{0, 0, w, h}, Rect{0, 0, w, h}}, } return g.Texture(texture).Draw(parts, geo, color) } @@ -54,7 +53,7 @@ func DrawWholeTexture(g GraphicsContext, texture *Texture, geo GeometryMatrix, c func DrawWholeRenderTarget(g GraphicsContext, renderTarget *RenderTarget, geo GeometryMatrix, color ColorMatrix) error { w, h := renderTarget.Size() parts := []TexturePart{ - {0, 0, Rect{0, 0, w, h}}, + {Rect{0, 0, w, h}, Rect{0, 0, w, h}}, } return g.RenderTarget(renderTarget).Draw(parts, geo, color) } @@ -114,14 +113,14 @@ func v(y int, height int) float32 { func textureQuads(parts []TexturePart, width, height int) []shader.TextureQuad { quads := make([]shader.TextureQuad, 0, len(parts)) for _, part := range parts { - x1 := float32(part.LocationX) - x2 := float32(part.LocationX + part.Source.Width) - y1 := float32(part.LocationY) - y2 := float32(part.LocationY + part.Source.Height) - u1 := u(part.Source.X, width) - u2 := u(part.Source.X+part.Source.Width, width) - v1 := v(part.Source.Y, height) - v2 := v(part.Source.Y+part.Source.Height, height) + x1 := float32(part.Dst.X) + x2 := float32(part.Dst.X + part.Dst.Width) + y1 := float32(part.Dst.Y) + y2 := float32(part.Dst.Y + part.Dst.Height) + u1 := u(part.Src.X, width) + u2 := u(part.Src.X+part.Src.Width, width) + v1 := v(part.Src.Y, height) + v2 := v(part.Src.Y+part.Src.Height, height) quad := shader.TextureQuad{x1, x2, y1, y2, u1, u2, v1, v2} quads = append(quads, quad) }