mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-26 11:48:55 +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
|
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)
|
clr := ebiten.ScaleColor(r, g, b, a)
|
||||||
op := ebiten.DrawImageAt(x+1, y)
|
rt.DrawImageAt(d.textImage, x+1, y, &ebiten.DrawImageOptions{
|
||||||
op.DstParts = dsts
|
DstParts: dsts,
|
||||||
op.SrcParts = srcs
|
SrcParts: srcs,
|
||||||
op.ColorMatrix = &clr
|
ColorMatrix: &clr,
|
||||||
rt.DrawImage(d.textImage, op)
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *debugPrintState) DebugPrint(r *ebiten.Image, str string) {
|
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++ {
|
for i := 0; i < 10; i++ {
|
||||||
clr := ebiten.ScaleColor(1.0, 1.0, 1.0, 0.5)
|
clr := ebiten.ScaleColor(1.0, 1.0, 1.0, 0.5)
|
||||||
op := ebiten.DrawImageAt(15+int(float64(i)*diff), 20)
|
op := &ebiten.DrawImageOptions{
|
||||||
op.ColorMatrix = &clr
|
ColorMatrix: &clr,
|
||||||
if err := tmpRenderTarget.DrawImage(ebitenImage, op); err != nil {
|
}
|
||||||
|
if err := tmpRenderTarget.DrawImageAt(ebitenImage, 15+int(float64(i)*diff), 20, op); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
screen.Fill(color.NRGBA{0x00, 0x00, 0x80, 0xff})
|
screen.Fill(color.NRGBA{0x00, 0x00, 0x80, 0xff})
|
||||||
for i := 0; i < 10; i++ {
|
for i := 0; i < 10; i++ {
|
||||||
op := ebiten.DrawImageAt(0, int(float64(i)*diff))
|
if err := screen.DrawImageAt(tmpRenderTarget, 0, int(float64(i)*diff), nil); err != nil {
|
||||||
if err := screen.DrawImage(tmpRenderTarget, op); err != nil {
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -152,10 +152,10 @@ func drawBlocks(r *ebiten.Image, images *Images, blocks [][]BlockType, x, y int)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
blocksImage := images.GetImage("blocks")
|
blocksImage := images.GetImage("blocks")
|
||||||
op := ebiten.DrawImageAt(x, y)
|
r.DrawImageAt(blocksImage, x, y, &ebiten.DrawImageOptions{
|
||||||
op.SrcParts = srcs
|
SrcParts: srcs,
|
||||||
op.DstParts = dsts
|
DstParts: dsts,
|
||||||
r.DrawImage(blocksImage, op)
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Piece) InitialPosition() (int, int) {
|
func (p *Piece) InitialPosition() (int, int) {
|
||||||
|
@ -66,10 +66,10 @@ func drawTitleBackground(r *ebiten.Image, images *Images, c int) {
|
|||||||
|
|
||||||
dx := (-c / 4) % imageWidth
|
dx := (-c / 4) % imageWidth
|
||||||
dy := (c / 4) % imageHeight
|
dy := (c / 4) % imageHeight
|
||||||
op := ebiten.DrawImageAt(dx, dy)
|
r.DrawImageAt(backgroundImage, dx, dy, &ebiten.DrawImageOptions{
|
||||||
op.SrcParts = srcs
|
SrcParts: srcs,
|
||||||
op.DstParts = dsts
|
DstParts: dsts,
|
||||||
r.DrawImage(backgroundImage, op)
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func drawLogo(r *ebiten.Image, images *Images, str string) {
|
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)
|
clr := ebiten.ScaleColor(1.0, 0.25, 0.25, 1.0)
|
||||||
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))
|
||||||
op := ebiten.DrawImageAt(mx, my)
|
canvasRenderTarget.DrawImageAt(brushRenderTarget, mx, my, &ebiten.DrawImageOptions{
|
||||||
op.ColorMatrix = &clr
|
ColorMatrix: &clr,
|
||||||
canvasRenderTarget.DrawImage(brushRenderTarget, op)
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
screen.DrawImage(canvasRenderTarget, nil)
|
screen.DrawImage(canvasRenderTarget, nil)
|
||||||
|
46
image.go
46
image.go
@ -52,12 +52,12 @@ func (i *innerImage) Fill(clr color.Color) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (i *innerImage) drawImage(img *innerImage, option *DrawImageOptions) error {
|
func (i *innerImage) drawImage(img *innerImage, options *DrawImageOptions) error {
|
||||||
if option == nil {
|
if options == nil {
|
||||||
option = &DrawImageOptions{}
|
options = &DrawImageOptions{}
|
||||||
}
|
}
|
||||||
dsts := option.DstParts
|
dsts := options.DstParts
|
||||||
srcs := option.SrcParts
|
srcs := options.SrcParts
|
||||||
if srcs == nil || dsts == nil {
|
if srcs == nil || dsts == nil {
|
||||||
w, h := img.size()
|
w, h := img.size()
|
||||||
dsts = []image.Rectangle{
|
dsts = []image.Rectangle{
|
||||||
@ -67,12 +67,12 @@ func (i *innerImage) drawImage(img *innerImage, option *DrawImageOptions) error
|
|||||||
image.Rect(0, 0, w, h),
|
image.Rect(0, 0, w, h),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
geo := option.GeometryMatrix
|
geo := options.GeometryMatrix
|
||||||
if geo == nil {
|
if geo == nil {
|
||||||
i := GeometryMatrixI()
|
i := GeometryMatrixI()
|
||||||
geo = &i
|
geo = &i
|
||||||
}
|
}
|
||||||
clr := option.ColorMatrix
|
clr := options.ColorMatrix
|
||||||
if clr == nil {
|
if clr == nil {
|
||||||
i := ColorMatrixI()
|
i := ColorMatrixI()
|
||||||
clr = &i
|
clr = &i
|
||||||
@ -155,12 +155,28 @@ func (i *Image) Fill(clr color.Color) (err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// DrawImage draws the given image on the receiver image.
|
// 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.
|
// 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 option.
|
// 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.
|
// If you want to draw a whole image simply, use DrawWholeImage.
|
||||||
func (i *Image) DrawImage(image *Image, option *DrawImageOptions) (err error) {
|
func (i *Image) DrawImage(image *Image, options *DrawImageOptions) (err error) {
|
||||||
return i.drawImage(image.inner, option)
|
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) {
|
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}
|
return color.RGBA{r, g, b, a}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// A DrawImageOptions presents options to render an image on an image.
|
||||||
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
|
||||||
}
|
}
|
||||||
|
|
||||||
func DrawImageAt(x, y int) *DrawImageOptions {
|
|
||||||
geo := TranslateGeometry(float64(x), float64(y))
|
|
||||||
return &DrawImageOptions{
|
|
||||||
GeometryMatrix: &geo,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
Loading…
Reference in New Issue
Block a user