Use value-type values for some of DrawImageOption's members

This commit is contained in:
Hajime Hoshi 2014-12-26 11:29:44 +09:00
parent d764afcb8f
commit ec6dc4b7ec
11 changed files with 16 additions and 39 deletions

View File

@ -58,11 +58,10 @@ func (d *debugPrintState) drawText(rt *ebiten.Image, str string, x, y int, c col
g := float64(cc.G) / math.MaxUint16 g := float64(cc.G) / math.MaxUint16
b := float64(cc.B) / math.MaxUint16 b := float64(cc.B) / math.MaxUint16
a := float64(cc.A) / math.MaxUint16 a := float64(cc.A) / math.MaxUint16
clr := ebiten.ScaleColor(r, g, b, a)
rt.DrawImageAt(d.textImage, x+1, y, &ebiten.DrawImageOptions{ rt.DrawImageAt(d.textImage, x+1, y, &ebiten.DrawImageOptions{
DstParts: dsts, DstParts: dsts,
SrcParts: srcs, SrcParts: srcs,
ColorMatrix: &clr, ColorMatrix: ebiten.ScaleColor(r, g, b, a),
}) })
} }

View File

@ -49,9 +49,8 @@ func update(screen *ebiten.Image) error {
return err return err
} }
for i := 0; i < 10; i++ { for i := 0; i < 10; i++ {
clr := ebiten.ScaleColor(1.0, 1.0, 1.0, 0.5)
op := &ebiten.DrawImageOptions{ op := &ebiten.DrawImageOptions{
ColorMatrix: &clr, ColorMatrix: 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.DrawImageAt(ebitenImage, 15+int(float64(i)*diff), 20, op); err != nil {
return err return err

View File

@ -63,8 +63,8 @@ func drawText(rt *ebiten.Image, images *Images, str string, ox, oy, scale int, c
rt.DrawImage(fontImageId, &ebiten.DrawImageOptions{ rt.DrawImage(fontImageId, &ebiten.DrawImageOptions{
DstParts: dsts, DstParts: dsts,
SrcParts: srcs, SrcParts: srcs,
GeometryMatrix: &geo, GeometryMatrix: geo,
ColorMatrix: &clr, ColorMatrix: clr,
}) })
} }

View File

@ -114,10 +114,9 @@ func (s *GameScene) Draw(r *ebiten.Image, images *Images) {
w, h := field.Size() w, h := field.Size()
geo := ebiten.ScaleGeometry(float64(fieldWidth)/float64(w), float64(fieldHeight)/float64(h)) geo := ebiten.ScaleGeometry(float64(fieldWidth)/float64(w), float64(fieldHeight)/float64(h))
geo.Concat(ebiten.TranslateGeometry(20, 20)) // TODO: magic number? geo.Concat(ebiten.TranslateGeometry(20, 20)) // TODO: magic number?
clr := ebiten.ScaleColor(0.0, 0.0, 0.0, 0.5)
r.DrawImage(field, &ebiten.DrawImageOptions{ r.DrawImage(field, &ebiten.DrawImageOptions{
GeometryMatrix: &geo, GeometryMatrix: geo,
ColorMatrix: &clr, ColorMatrix: ebiten.ScaleColor(0.0, 0.0, 0.0, 0.5),
}) })
s.field.Draw(r, images, 20, 20) s.field.Draw(r, images, 20, 20)

View File

@ -74,9 +74,8 @@ func (s *SceneManager) Draw(r *ebiten.Image, images *Images) {
r.DrawImage(from, nil) r.DrawImage(from, nil)
alpha := float64(s.transitionCount) / float64(transitionMaxCount) alpha := float64(s.transitionCount) / float64(transitionMaxCount)
clr := ebiten.ScaleColor(1, 1, 1, alpha)
op := &ebiten.DrawImageOptions{ op := &ebiten.DrawImageOptions{
ColorMatrix: &clr, ColorMatrix: ebiten.ScaleColor(1, 1, 1, alpha),
} }
r.DrawImage(to, op) r.DrawImage(to, op)
} }

View File

@ -34,14 +34,11 @@ var (
) )
func update(screen *ebiten.Image) error { func update(screen *ebiten.Image) error {
geo := ebiten.ScaleGeometry(1.0/mosaicRatio, 1.0/mosaicRatio)
gophersRenderTarget.DrawImage(gophersImage, &ebiten.DrawImageOptions{ gophersRenderTarget.DrawImage(gophersImage, &ebiten.DrawImageOptions{
GeometryMatrix: &geo, GeometryMatrix: ebiten.ScaleGeometry(1.0/mosaicRatio, 1.0/mosaicRatio),
}) })
geo = ebiten.ScaleGeometry(mosaicRatio, mosaicRatio)
screen.DrawImage(gophersRenderTarget, &ebiten.DrawImageOptions{ screen.DrawImage(gophersRenderTarget, &ebiten.DrawImageOptions{
GeometryMatrix: &geo, GeometryMatrix: ebiten.ScaleGeometry(mosaicRatio, mosaicRatio),
}) })
return nil return nil
} }

View File

@ -46,7 +46,7 @@ func Update(screen *ebiten.Image) error {
theta := 2.0 * math.Pi * float64(count%60) / 60.0 theta := 2.0 * math.Pi * float64(count%60) / 60.0
clr.Concat(ebiten.RotateHue(theta)) clr.Concat(ebiten.RotateHue(theta))
canvasRenderTarget.DrawImageAt(brushRenderTarget, mx, my, &ebiten.DrawImageOptions{ canvasRenderTarget.DrawImageAt(brushRenderTarget, mx, my, &ebiten.DrawImageOptions{
ColorMatrix: &clr, ColorMatrix: clr,
}) })
} }

View File

@ -46,7 +46,7 @@ func update(screen *ebiten.Image) error {
screen.DrawImage(gophersImage, &ebiten.DrawImageOptions{ screen.DrawImage(gophersImage, &ebiten.DrawImageOptions{
DstParts: dsts, DstParts: dsts,
SrcParts: srcs, SrcParts: srcs,
GeometryMatrix: &geo, GeometryMatrix: geo,
}) })
return nil return nil
} }

View File

@ -57,7 +57,7 @@ func update(screen *ebiten.Image) error {
geo.Concat(ebiten.RotateGeometry(float64(count%720) * 2 * math.Pi / 720)) geo.Concat(ebiten.RotateGeometry(float64(count%720) * 2 * math.Pi / 720))
geo.Concat(ebiten.TranslateGeometry(screenWidth/2, screenHeight/2)) geo.Concat(ebiten.TranslateGeometry(screenWidth/2, screenHeight/2))
if err := screen.DrawImage(gophersImage, &ebiten.DrawImageOptions{ if err := screen.DrawImage(gophersImage, &ebiten.DrawImageOptions{
GeometryMatrix: &geo, GeometryMatrix: geo,
}); err != nil { }); err != nil {
return err return err
} }

View File

@ -66,11 +66,8 @@ func (c *graphicsContext) postUpdate() error {
} }
scale := float64(c.screenScale) scale := float64(c.screenScale)
geo := ScaleGeometry(scale, scale)
clr := NewColorMatrix()
option := &DrawImageOptions{ option := &DrawImageOptions{
GeometryMatrix: &geo, GeometryMatrix: ScaleGeometry(scale, scale),
ColorMatrix: &clr,
} }
if err := c.defaultR.drawImage(c.screen, option); err != nil { if err := c.defaultR.drawImage(c.screen, option); err != nil {
return err return err

View File

@ -68,15 +68,7 @@ func (i *innerImage) drawImage(img *innerImage, options *DrawImageOptions) error
} }
} }
geo := options.GeometryMatrix geo := options.GeometryMatrix
if geo == nil {
i := NewGeometryMatrix()
geo = &i
}
clr := options.ColorMatrix clr := options.ColorMatrix
if clr == nil {
i := NewColorMatrix()
clr = &i
}
if err := i.framebuffer.SetAsViewport(); err != nil { if err := i.framebuffer.SetAsViewport(); err != nil {
return err return err
@ -176,12 +168,7 @@ func (i *Image) DrawImageAt(image *Image, x, y int, options *DrawImageOptions) (
if options == nil { if options == nil {
options = &DrawImageOptions{} options = &DrawImageOptions{}
} }
if options.GeometryMatrix == nil { options.GeometryMatrix.Concat(TranslateGeometry(float64(x), float64(y)))
geo := TranslateGeometry(float64(x), float64(y))
options.GeometryMatrix = &geo
} else {
options.GeometryMatrix.Concat(TranslateGeometry(float64(x), float64(y)))
}
return i.drawImage(image.inner, options) return i.drawImage(image.inner, options)
} }
@ -228,6 +215,6 @@ func (i *Image) At(x, y int) color.Color {
type DrawImageOptions struct { type DrawImageOptions struct {
DstParts []image.Rectangle DstParts []image.Rectangle
SrcParts []image.Rectangle SrcParts []image.Rectangle
GeometryMatrix *GeometryMatrix GeometryMatrix GeometryMatrix
ColorMatrix *ColorMatrix ColorMatrix ColorMatrix
} }