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
b := float64(cc.B) / math.MaxUint16
a := float64(cc.A) / math.MaxUint16
clr := ebiten.ScaleColor(r, g, b, a)
rt.DrawImageAt(d.textImage, x+1, y, &ebiten.DrawImageOptions{
DstParts: dsts,
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
}
for i := 0; i < 10; i++ {
clr := ebiten.ScaleColor(1.0, 1.0, 1.0, 0.5)
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 {
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{
DstParts: dsts,
SrcParts: srcs,
GeometryMatrix: &geo,
ColorMatrix: &clr,
GeometryMatrix: geo,
ColorMatrix: clr,
})
}

View File

@ -114,10 +114,9 @@ func (s *GameScene) Draw(r *ebiten.Image, images *Images) {
w, h := field.Size()
geo := ebiten.ScaleGeometry(float64(fieldWidth)/float64(w), float64(fieldHeight)/float64(h))
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{
GeometryMatrix: &geo,
ColorMatrix: &clr,
GeometryMatrix: geo,
ColorMatrix: ebiten.ScaleColor(0.0, 0.0, 0.0, 0.5),
})
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)
alpha := float64(s.transitionCount) / float64(transitionMaxCount)
clr := ebiten.ScaleColor(1, 1, 1, alpha)
op := &ebiten.DrawImageOptions{
ColorMatrix: &clr,
ColorMatrix: ebiten.ScaleColor(1, 1, 1, alpha),
}
r.DrawImage(to, op)
}

View File

@ -34,14 +34,11 @@ var (
)
func update(screen *ebiten.Image) error {
geo := ebiten.ScaleGeometry(1.0/mosaicRatio, 1.0/mosaicRatio)
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{
GeometryMatrix: &geo,
GeometryMatrix: ebiten.ScaleGeometry(mosaicRatio, mosaicRatio),
})
return nil
}

View File

@ -46,7 +46,7 @@ func Update(screen *ebiten.Image) error {
theta := 2.0 * math.Pi * float64(count%60) / 60.0
clr.Concat(ebiten.RotateHue(theta))
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{
DstParts: dsts,
SrcParts: srcs,
GeometryMatrix: &geo,
GeometryMatrix: geo,
})
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.TranslateGeometry(screenWidth/2, screenHeight/2))
if err := screen.DrawImage(gophersImage, &ebiten.DrawImageOptions{
GeometryMatrix: &geo,
GeometryMatrix: geo,
}); err != nil {
return err
}

View File

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

View File

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