From d4112004b0d8a26094054af79c0827e45b0ff999 Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Fri, 2 Mar 2018 12:20:44 +0900 Subject: [PATCH] graphics: Move calculating source region from restorable package --- image.go | 21 ++++++++++++++++++++- internal/restorable/vertices.go | 16 ---------------- 2 files changed, 20 insertions(+), 17 deletions(-) diff --git a/image.go b/image.go index d47c6ad6f..34259fae0 100644 --- a/image.go +++ b/image.go @@ -20,6 +20,7 @@ import ( "image/color" "runtime" + "github.com/hajimehoshi/ebiten/internal/affine" "github.com/hajimehoshi/ebiten/internal/graphics" "github.com/hajimehoshi/ebiten/internal/opengl" "github.com/hajimehoshi/ebiten/internal/restorable" @@ -202,6 +203,24 @@ func (i *Image) DrawImage(img *Image, options *DrawImageOptions) error { sy1 = r.Max.Y } } + geom := options.GeoM.impl + if sx0 < 0 || sy0 < 0 { + dx := 0.0 + dy := 0.0 + if sx0 < 0 { + dx = -float64(sx0) + sx0 = 0 + } + if sy0 < 0 { + dy = -float64(sy0) + sy0 = 0 + } + var g *affine.GeoM + g = g.Translate(dx, dy) + g = g.Concat(geom) + geom = g + } + mode := opengl.CompositeMode(options.CompositeMode) filter := graphics.FilterNearest @@ -211,7 +230,7 @@ func (i *Image) DrawImage(img *Image, options *DrawImageOptions) error { filter = graphics.Filter(img.filter) } - i.restorable.DrawImage(img.restorable, sx0, sy0, sx1, sy1, options.GeoM.impl, options.ColorM.impl, mode, filter) + i.restorable.DrawImage(img.restorable, sx0, sy0, sx1, sy1, geom, options.ColorM.impl, mode, filter) return nil } diff --git a/internal/restorable/vertices.go b/internal/restorable/vertices.go index f020c7896..1e7570841 100644 --- a/internal/restorable/vertices.go +++ b/internal/restorable/vertices.go @@ -54,22 +54,6 @@ func (i *Image) vertices(sx0, sy0, sx1, sy1 int, geo *affine.GeoM) []float32 { // TODO: This function should be in graphics package? vs := theVerticesBackend.get() - if sx0 < 0 || sy0 < 0 { - dx := 0.0 - dy := 0.0 - if sx0 < 0 { - dx = -float64(sx0) - sx0 = 0 - } - if sy0 < 0 { - dy = -float64(sy0) - sy0 = 0 - } - var g *affine.GeoM - g = g.Translate(dx, dy) - g = g.Concat(geo) - geo = g - } x0, y0 := 0.0, 0.0 x1, y1 := float64(sx1-sx0), float64(sy1-sy0)