From 0e673670c00a0cf8a4a63908f5edd63d48dd7f40 Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Wed, 17 Dec 2014 23:06:14 +0900 Subject: [PATCH] Replace DrawWhole with DrawWholeTexture and DrawWholeRenderTarget --- example/blocks/blocks/gamescene.go | 7 +++---- example/blocks/blocks/scenemanager.go | 14 ++------------ example/image/main.go | 2 +- example/paint/main.go | 4 ++-- graphics.go | 18 ++++++++++++++---- graphicscontext.go | 2 +- 6 files changed, 23 insertions(+), 24 deletions(-) diff --git a/example/blocks/blocks/gamescene.go b/example/blocks/blocks/gamescene.go index f980f4ffa..20fb5c8fd 100644 --- a/example/blocks/blocks/gamescene.go +++ b/example/blocks/blocks/gamescene.go @@ -45,8 +45,6 @@ func NewGameScene() *GameScene { } } -const emptyWidth = 16 -const emptyHeight = 16 const fieldWidth = blockWidth * fieldBlockNumX const fieldHeight = blockHeight * fieldBlockNumY @@ -115,10 +113,11 @@ func (s *GameScene) Draw(context ebiten.GraphicsContext, textures *Textures) { context.Fill(0xff, 0xff, 0xff) field := textures.GetTexture("empty") - geoMat := ebiten.ScaleGeometry(float64(fieldWidth)/float64(emptyWidth), float64(fieldHeight)/float64(emptyHeight)) + w, h := field.Size() + geoMat := ebiten.ScaleGeometry(float64(fieldWidth)/float64(w), float64(fieldHeight)/float64(h)) geoMat.Concat(ebiten.TranslateGeometry(20, 20)) // TODO: magic number? colorMat := ebiten.ScaleColor(color.RGBA{0, 0, 0, 0x80}) - ebiten.DrawWhole(context.Texture(field), emptyWidth, emptyHeight, geoMat, colorMat) + ebiten.DrawWholeTexture(context, field, geoMat, colorMat) geoMat = ebiten.GeometryMatrixI() geoMat.Concat(ebiten.TranslateGeometry(20, 20)) diff --git a/example/blocks/blocks/scenemanager.go b/example/blocks/blocks/scenemanager.go index 7b0da3934..9f3283079 100644 --- a/example/blocks/blocks/scenemanager.go +++ b/example/blocks/blocks/scenemanager.go @@ -78,21 +78,11 @@ func (s *SceneManager) Draw(context ebiten.GraphicsContext, textures *Textures) context.PopRenderTarget() color := ebiten.ColorMatrixI() - ebiten.DrawWhole( - context.RenderTarget(from), - ScreenWidth, - ScreenHeight, - ebiten.GeometryMatrixI(), - color) + ebiten.DrawWholeRenderTarget(context, from, ebiten.GeometryMatrixI(), color) alpha := float64(s.transitionCount) / float64(transitionMaxCount) color.Elements[3][3] = alpha - ebiten.DrawWhole( - context.RenderTarget(to), - ScreenWidth, - ScreenHeight, - ebiten.GeometryMatrixI(), - color) + ebiten.DrawWholeRenderTarget(context, to, ebiten.GeometryMatrixI(), color) } func (s *SceneManager) GoTo(scene Scene) { diff --git a/example/image/main.go b/example/image/main.go index d5cea3ea3..e587feda0 100644 --- a/example/image/main.go +++ b/example/image/main.go @@ -42,7 +42,7 @@ func (g *Game) Update(gr ebiten.GraphicsContext) error { geo.Concat(ebiten.ScaleGeometry(0.5, 0.5)) geo.Concat(ebiten.TranslateGeometry(screenWidth/2, screenHeight/2)) clr := ebiten.RotateHue(float64(g.count%180) * 2 * math.Pi / 180) - ebiten.DrawWhole(gr.Texture(g.gophersTexture), w, h, geo, clr) + ebiten.DrawWholeTexture(gr, g.gophersTexture, geo, clr) return nil } diff --git a/example/paint/main.go b/example/paint/main.go index 8bc9804ad..a4d22257c 100644 --- a/example/paint/main.go +++ b/example/paint/main.go @@ -59,11 +59,11 @@ func (g *Game) Update(gr ebiten.GraphicsContext) error { clr := ebiten.ScaleColor(color.RGBA{0xff, 0x40, 0x40, 0xff}) theta := 2.0 * math.Pi * float64(g.count%60) / 60.0 clr.Concat(ebiten.RotateHue(theta)) - ebiten.DrawWhole(gr.RenderTarget(g.brushRenderTarget), 1, 1, geo, clr) + ebiten.DrawWholeRenderTarget(gr, g.brushRenderTarget, geo, clr) gr.PopRenderTarget() } - ebiten.DrawWhole(gr.RenderTarget(g.canvasRenderTarget), screenWidth, screenHeight, ebiten.GeometryMatrixI(), ebiten.ColorMatrixI()) + ebiten.DrawWholeRenderTarget(gr, g.canvasRenderTarget, ebiten.GeometryMatrixI(), ebiten.ColorMatrixI()) ebitenutil.DebugPrint(gr, fmt.Sprintf("(%d, %d)", mx, my)) return nil diff --git a/graphics.go b/graphics.go index 57f7034a7..a30320110 100644 --- a/graphics.go +++ b/graphics.go @@ -41,12 +41,22 @@ type Drawer interface { Draw(parts []TexturePart, geo GeometryMatrix, color ColorMatrix) error } -// DrawWhole draws the whole texture. -func DrawWhole(drawer Drawer, width, height int, geo GeometryMatrix, color ColorMatrix) error { +// DrawWholeTexture draws the whole texture. +func DrawWholeTexture(g GraphicsContext, texture *Texture, geo GeometryMatrix, color ColorMatrix) error { + w, h := texture.Size() parts := []TexturePart{ - {0, 0, Rect{0, 0, width, height}}, + {0, 0, Rect{0, 0, w, h}}, } - return drawer.Draw(parts, geo, color) + return g.Texture(texture).Draw(parts, geo, color) +} + +// DrawWholeRenderTarget draws the whole render target. +func DrawWholeRenderTarget(g GraphicsContext, renderTarget *RenderTarget, geo GeometryMatrix, color ColorMatrix) error { + w, h := renderTarget.Size() + parts := []TexturePart{ + {0, 0, Rect{0, 0, w, h}}, + } + return g.RenderTarget(renderTarget).Draw(parts, geo, color) } // A GraphicsContext is the interface that means a context of rendering. diff --git a/graphicscontext.go b/graphicscontext.go index 44cc1d6c4..348778399 100644 --- a/graphicscontext.go +++ b/graphicscontext.go @@ -103,7 +103,7 @@ func (c *graphicsContext) postUpdate() { scale := float64(c.screenScale) geo := GeometryMatrixI() geo.Concat(ScaleGeometry(scale, scale)) - DrawWhole(c.RenderTarget(c.screen), c.screenWidth, c.screenHeight, geo, ColorMatrixI()) + DrawWholeRenderTarget(c, c.screen, geo, ColorMatrixI()) gl.Flush() }