mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-01-26 02:42:02 +01:00
Introduce ImageDrawOption
This commit is contained in:
parent
aee86f7e9c
commit
b39df50979
@ -1,2 +1 @@
|
|||||||
Hello, World!
|
hogehoge
|
||||||
|
|
||||||
|
@ -52,5 +52,11 @@ func DrawImagePartsColor(target *Image, dsts []image.Rectangle, img *Image, srcs
|
|||||||
}
|
}
|
||||||
|
|
||||||
func DrawImagePartsGeometryColor(target *Image, dsts []image.Rectangle, img *Image, srcs []image.Rectangle, geo GeometryMatrix, color ColorMatrix) error {
|
func DrawImagePartsGeometryColor(target *Image, dsts []image.Rectangle, img *Image, srcs []image.Rectangle, geo GeometryMatrix, color ColorMatrix) error {
|
||||||
return target.DrawImage(dsts, img, srcs, geo, color)
|
op := &ImageDrawOption{
|
||||||
|
DstParts: dsts,
|
||||||
|
SrcParts: srcs,
|
||||||
|
GeometryMatrix: &geo,
|
||||||
|
ColorMatrix: &color,
|
||||||
|
}
|
||||||
|
return target.DrawImage(img, op)
|
||||||
}
|
}
|
||||||
|
@ -60,7 +60,12 @@ func drawText(rt *ebiten.Image, images *Images, str string, ox, oy, scale int, c
|
|||||||
b := float64(c2.B) / max
|
b := float64(c2.B) / max
|
||||||
a := float64(c2.A) / max
|
a := float64(c2.A) / max
|
||||||
clr := ebiten.ScaleColor(r, g, b, a)
|
clr := ebiten.ScaleColor(r, g, b, a)
|
||||||
rt.DrawImage(dsts, fontImageId, srcs, geo, clr)
|
rt.DrawImage(fontImageId, &ebiten.ImageDrawOption{
|
||||||
|
DstParts: dsts,
|
||||||
|
SrcParts: srcs,
|
||||||
|
GeometryMatrix: &geo,
|
||||||
|
ColorMatrix: &clr,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func drawTextWithShadow(rt *ebiten.Image, images *Images, str string, x, y, scale int, clr color.Color) {
|
func drawTextWithShadow(rt *ebiten.Image, images *Images, str string, x, y, scale int, clr color.Color) {
|
||||||
|
@ -16,7 +16,6 @@ package ebiten
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/hajimehoshi/ebiten/internal/opengl"
|
"github.com/hajimehoshi/ebiten/internal/opengl"
|
||||||
"image"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func newGraphicsContext(screenWidth, screenHeight, screenScale int) (*graphicsContext, error) {
|
func newGraphicsContext(screenWidth, screenHeight, screenScale int) (*graphicsContext, error) {
|
||||||
@ -69,10 +68,11 @@ func (c *graphicsContext) postUpdate() error {
|
|||||||
scale := float64(c.screenScale)
|
scale := float64(c.screenScale)
|
||||||
geo := ScaleGeometry(scale, scale)
|
geo := ScaleGeometry(scale, scale)
|
||||||
clr := ColorMatrixI()
|
clr := ColorMatrixI()
|
||||||
w, h := c.screen.size()
|
option := &ImageDrawOption{
|
||||||
dsts := []image.Rectangle{image.Rect(0, 0, w, h)}
|
GeometryMatrix: &geo,
|
||||||
srcs := []image.Rectangle{image.Rect(0, 0, w, h)}
|
ColorMatrix: &clr,
|
||||||
if err := c.defaultR.drawImage(dsts, c.screen, srcs, geo, clr); err != nil {
|
}
|
||||||
|
if err := c.defaultR.drawImage(c.screen, option); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
49
image.go
49
image.go
@ -52,14 +52,42 @@ func (i *innerImage) Fill(clr color.Color) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (i *innerImage) drawImage(dsts []image.Rectangle, image *innerImage, srcs []image.Rectangle, geo GeometryMatrix, color ColorMatrix) error {
|
func (i *innerImage) drawImage(img *innerImage, option *ImageDrawOption) error {
|
||||||
|
if option == nil {
|
||||||
|
option = &ImageDrawOption{}
|
||||||
|
}
|
||||||
|
dsts := option.DstParts
|
||||||
|
if dsts == nil {
|
||||||
|
w, h := img.size()
|
||||||
|
dsts = []image.Rectangle{
|
||||||
|
image.Rect(0, 0, w, h),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
srcs := option.SrcParts
|
||||||
|
if srcs == nil {
|
||||||
|
w, h := img.size()
|
||||||
|
srcs = []image.Rectangle{
|
||||||
|
image.Rect(0, 0, w, h),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
geo := option.GeometryMatrix
|
||||||
|
if geo == nil {
|
||||||
|
i := GeometryMatrixI()
|
||||||
|
geo = &i
|
||||||
|
}
|
||||||
|
clr := option.ColorMatrix
|
||||||
|
if clr == nil {
|
||||||
|
i := ColorMatrixI()
|
||||||
|
clr = &i
|
||||||
|
}
|
||||||
|
|
||||||
if err := i.framebuffer.SetAsViewport(); err != nil {
|
if err := i.framebuffer.SetAsViewport(); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
w, h := image.texture.Size()
|
w, h := img.texture.Size()
|
||||||
quads := textureQuads(dsts, srcs, w, h)
|
quads := textureQuads(dsts, srcs, w, h)
|
||||||
projectionMatrix := i.framebuffer.ProjectionMatrix()
|
projectionMatrix := i.framebuffer.ProjectionMatrix()
|
||||||
shader.DrawTexture(image.texture.Native(), projectionMatrix, quads, &geo, &color)
|
shader.DrawTexture(img.texture.Native(), projectionMatrix, quads, geo, clr)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -134,14 +162,14 @@ func (i *Image) Fill(clr color.Color) (err error) {
|
|||||||
// After determining parts to draw, this applies the geometry matrix geo and the color matrix color.
|
// After determining parts to draw, this applies the geometry matrix geo and the color matrix color.
|
||||||
//
|
//
|
||||||
// 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(dsts []image.Rectangle, image *Image, srcs []image.Rectangle, geo GeometryMatrix, color ColorMatrix) (err error) {
|
func (i *Image) DrawImage(image *Image, option *ImageDrawOption) (err error) {
|
||||||
return i.drawImage(dsts, image.inner, srcs, geo, color)
|
return i.drawImage(image.inner, option)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (i *Image) drawImage(dsts []image.Rectangle, image *innerImage, srcs []image.Rectangle, geo GeometryMatrix, color ColorMatrix) (err error) {
|
func (i *Image) drawImage(image *innerImage, option *ImageDrawOption) (err error) {
|
||||||
i.pixels = nil
|
i.pixels = nil
|
||||||
i.syncer.Sync(func() {
|
i.syncer.Sync(func() {
|
||||||
err = i.inner.drawImage(dsts, image, srcs, geo, color)
|
err = i.inner.drawImage(image, option)
|
||||||
})
|
})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -176,3 +204,10 @@ func (i *Image) At(x, y int) color.Color {
|
|||||||
r, g, b, a := i.pixels[idx], i.pixels[idx+1], i.pixels[idx+2], i.pixels[idx+3]
|
r, g, b, a := i.pixels[idx], i.pixels[idx+1], i.pixels[idx+2], i.pixels[idx+3]
|
||||||
return color.RGBA{r, g, b, a}
|
return color.RGBA{r, g, b, a}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type ImageDrawOption struct {
|
||||||
|
DstParts []image.Rectangle
|
||||||
|
SrcParts []image.Rectangle
|
||||||
|
GeometryMatrix *GeometryMatrix
|
||||||
|
ColorMatrix *ColorMatrix
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user