mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-25 11:18:54 +01:00
Remove the struct DrawImageAt; Add a method (*Image).DrawImageAt
This commit is contained in:
parent
b69dec3f1e
commit
843b0d8621
@ -59,11 +59,11 @@ func (d *debugPrintState) drawText(rt *ebiten.Image, str string, x, y int, c col
|
||||
b := float64(cc.B) / math.MaxUint16
|
||||
a := float64(cc.A) / math.MaxUint16
|
||||
clr := ebiten.ScaleColor(r, g, b, a)
|
||||
op := ebiten.DrawImageAt(x+1, y)
|
||||
op.DstParts = dsts
|
||||
op.SrcParts = srcs
|
||||
op.ColorMatrix = &clr
|
||||
rt.DrawImage(d.textImage, op)
|
||||
rt.DrawImageAt(d.textImage, x+1, y, &ebiten.DrawImageOptions{
|
||||
DstParts: dsts,
|
||||
SrcParts: srcs,
|
||||
ColorMatrix: &clr,
|
||||
})
|
||||
}
|
||||
|
||||
func (d *debugPrintState) DebugPrint(r *ebiten.Image, str string) {
|
||||
|
@ -50,17 +50,17 @@ func update(screen *ebiten.Image) error {
|
||||
}
|
||||
for i := 0; i < 10; i++ {
|
||||
clr := ebiten.ScaleColor(1.0, 1.0, 1.0, 0.5)
|
||||
op := ebiten.DrawImageAt(15+int(float64(i)*diff), 20)
|
||||
op.ColorMatrix = &clr
|
||||
if err := tmpRenderTarget.DrawImage(ebitenImage, op); err != nil {
|
||||
op := &ebiten.DrawImageOptions{
|
||||
ColorMatrix: &clr,
|
||||
}
|
||||
if err := tmpRenderTarget.DrawImageAt(ebitenImage, 15+int(float64(i)*diff), 20, op); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
screen.Fill(color.NRGBA{0x00, 0x00, 0x80, 0xff})
|
||||
for i := 0; i < 10; i++ {
|
||||
op := ebiten.DrawImageAt(0, int(float64(i)*diff))
|
||||
if err := screen.DrawImage(tmpRenderTarget, op); err != nil {
|
||||
if err := screen.DrawImageAt(tmpRenderTarget, 0, int(float64(i)*diff), nil); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
@ -152,10 +152,10 @@ func drawBlocks(r *ebiten.Image, images *Images, blocks [][]BlockType, x, y int)
|
||||
}
|
||||
}
|
||||
blocksImage := images.GetImage("blocks")
|
||||
op := ebiten.DrawImageAt(x, y)
|
||||
op.SrcParts = srcs
|
||||
op.DstParts = dsts
|
||||
r.DrawImage(blocksImage, op)
|
||||
r.DrawImageAt(blocksImage, x, y, &ebiten.DrawImageOptions{
|
||||
SrcParts: srcs,
|
||||
DstParts: dsts,
|
||||
})
|
||||
}
|
||||
|
||||
func (p *Piece) InitialPosition() (int, int) {
|
||||
|
@ -66,10 +66,10 @@ func drawTitleBackground(r *ebiten.Image, images *Images, c int) {
|
||||
|
||||
dx := (-c / 4) % imageWidth
|
||||
dy := (c / 4) % imageHeight
|
||||
op := ebiten.DrawImageAt(dx, dy)
|
||||
op.SrcParts = srcs
|
||||
op.DstParts = dsts
|
||||
r.DrawImage(backgroundImage, op)
|
||||
r.DrawImageAt(backgroundImage, dx, dy, &ebiten.DrawImageOptions{
|
||||
SrcParts: srcs,
|
||||
DstParts: dsts,
|
||||
})
|
||||
}
|
||||
|
||||
func drawLogo(r *ebiten.Image, images *Images, str string) {
|
||||
|
@ -45,9 +45,9 @@ func Update(screen *ebiten.Image) error {
|
||||
clr := ebiten.ScaleColor(1.0, 0.25, 0.25, 1.0)
|
||||
theta := 2.0 * math.Pi * float64(count%60) / 60.0
|
||||
clr.Concat(ebiten.RotateHue(theta))
|
||||
op := ebiten.DrawImageAt(mx, my)
|
||||
op.ColorMatrix = &clr
|
||||
canvasRenderTarget.DrawImage(brushRenderTarget, op)
|
||||
canvasRenderTarget.DrawImageAt(brushRenderTarget, mx, my, &ebiten.DrawImageOptions{
|
||||
ColorMatrix: &clr,
|
||||
})
|
||||
}
|
||||
|
||||
screen.DrawImage(canvasRenderTarget, nil)
|
||||
|
46
image.go
46
image.go
@ -52,12 +52,12 @@ func (i *innerImage) Fill(clr color.Color) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (i *innerImage) drawImage(img *innerImage, option *DrawImageOptions) error {
|
||||
if option == nil {
|
||||
option = &DrawImageOptions{}
|
||||
func (i *innerImage) drawImage(img *innerImage, options *DrawImageOptions) error {
|
||||
if options == nil {
|
||||
options = &DrawImageOptions{}
|
||||
}
|
||||
dsts := option.DstParts
|
||||
srcs := option.SrcParts
|
||||
dsts := options.DstParts
|
||||
srcs := options.SrcParts
|
||||
if srcs == nil || dsts == nil {
|
||||
w, h := img.size()
|
||||
dsts = []image.Rectangle{
|
||||
@ -67,12 +67,12 @@ func (i *innerImage) drawImage(img *innerImage, option *DrawImageOptions) error
|
||||
image.Rect(0, 0, w, h),
|
||||
}
|
||||
}
|
||||
geo := option.GeometryMatrix
|
||||
geo := options.GeometryMatrix
|
||||
if geo == nil {
|
||||
i := GeometryMatrixI()
|
||||
geo = &i
|
||||
}
|
||||
clr := option.ColorMatrix
|
||||
clr := options.ColorMatrix
|
||||
if clr == nil {
|
||||
i := ColorMatrixI()
|
||||
clr = &i
|
||||
@ -155,12 +155,28 @@ func (i *Image) Fill(clr color.Color) (err error) {
|
||||
}
|
||||
|
||||
// DrawImage draws the given image on the receiver image.
|
||||
// This method accepts the parts of the given image at the parts of the destination as the option.
|
||||
// After determining parts to draw, this applies the geometry matrix and the color matrix as the option.
|
||||
// This method accepts the parts of the given image at the parts of the destination as the options.
|
||||
// After determining parts to draw, this applies the geometry matrix and the color matrix as the options.
|
||||
//
|
||||
// If you want to draw a whole image simply, use DrawWholeImage.
|
||||
func (i *Image) DrawImage(image *Image, option *DrawImageOptions) (err error) {
|
||||
return i.drawImage(image.inner, option)
|
||||
func (i *Image) DrawImage(image *Image, options *DrawImageOptions) (err error) {
|
||||
return i.drawImage(image.inner, options)
|
||||
}
|
||||
|
||||
// DrawImageAt draws the given image on the receiver image at the position (x, y).
|
||||
//
|
||||
// If a geometry matrix is specified, the geometry matrix is applied ahead of the image is translated by (x, y).
|
||||
func (i *Image) DrawImageAt(image *Image, x, y int, options *DrawImageOptions) (err error) {
|
||||
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)))
|
||||
}
|
||||
return i.drawImage(image.inner, options)
|
||||
}
|
||||
|
||||
func (i *Image) drawImage(image *innerImage, option *DrawImageOptions) (err error) {
|
||||
@ -202,16 +218,10 @@ func (i *Image) At(x, y int) color.Color {
|
||||
return color.RGBA{r, g, b, a}
|
||||
}
|
||||
|
||||
// A DrawImageOptions presents options to render an image on an image.
|
||||
type DrawImageOptions struct {
|
||||
DstParts []image.Rectangle
|
||||
SrcParts []image.Rectangle
|
||||
GeometryMatrix *GeometryMatrix
|
||||
ColorMatrix *ColorMatrix
|
||||
}
|
||||
|
||||
func DrawImageAt(x, y int) *DrawImageOptions {
|
||||
geo := TranslateGeometry(float64(x), float64(y))
|
||||
return &DrawImageOptions{
|
||||
GeometryMatrix: &geo,
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user