mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-25 11:18:54 +01:00
graphics: Refactoring: Remove (*sharedImagePart).region() usages from *Image
This commit is contained in:
parent
26f4999ddd
commit
9d0ea5c241
22
image.go
22
image.go
@ -15,7 +15,6 @@
|
||||
package ebiten
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"image"
|
||||
"image/color"
|
||||
"runtime"
|
||||
@ -71,8 +70,7 @@ func (i *Image) copyCheck() {
|
||||
|
||||
// Size returns the size of the image.
|
||||
func (i *Image) Size() (width, height int) {
|
||||
_, _, w, h := i.sharedImagePart.region()
|
||||
return w, h
|
||||
return i.sharedImagePart.Size()
|
||||
}
|
||||
|
||||
// Clear resets the pixels of the image into 0.
|
||||
@ -231,12 +229,6 @@ func (i *Image) DrawImage(img *Image, options *DrawImageOptions) error {
|
||||
geom = g
|
||||
}
|
||||
|
||||
dx, dy, _, _ := img.sharedImagePart.region()
|
||||
sx0 += dx
|
||||
sy0 += dy
|
||||
sx1 += dx
|
||||
sy1 += dy
|
||||
|
||||
mode := opengl.CompositeMode(options.CompositeMode)
|
||||
|
||||
filter := graphics.FilterNearest
|
||||
@ -272,11 +264,7 @@ func (i *Image) At(x, y int) color.Color {
|
||||
if i.isDisposed() {
|
||||
return color.RGBA{}
|
||||
}
|
||||
ox, oy, w, h := i.sharedImagePart.region()
|
||||
if x < 0 || y < 0 || x >= w || y >= h {
|
||||
return color.RGBA{}
|
||||
}
|
||||
clr, err := i.sharedImagePart.At(x+ox, y+oy)
|
||||
clr, err := i.sharedImagePart.At(x, y)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
@ -317,11 +305,7 @@ func (i *Image) ReplacePixels(p []byte) error {
|
||||
if i.isDisposed() {
|
||||
return nil
|
||||
}
|
||||
x, y, w, h := i.sharedImagePart.region()
|
||||
if l := 4 * w * h; len(p) != l {
|
||||
panic(fmt.Sprintf("ebiten: len(p) was %d but must be %d", len(p), l))
|
||||
}
|
||||
i.sharedImagePart.ReplacePixels(p, x, y, w, h)
|
||||
i.sharedImagePart.ReplacePixels(p)
|
||||
return nil
|
||||
}
|
||||
|
||||
|
25
shared.go
25
shared.go
@ -15,6 +15,7 @@
|
||||
package ebiten
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"image/color"
|
||||
|
||||
"github.com/hajimehoshi/ebiten/internal/affine"
|
||||
@ -64,16 +65,34 @@ func (s *sharedImagePart) region() (x, y, width, height int) {
|
||||
return s.node.Region()
|
||||
}
|
||||
|
||||
func (s *sharedImagePart) Size() (width, height int) {
|
||||
_, _, w, h := s.region()
|
||||
return w, h
|
||||
}
|
||||
|
||||
func (s *sharedImagePart) DrawImage(img *sharedImagePart, sx0, sy0, sx1, sy1 int, geom *affine.GeoM, colorm *affine.ColorM, mode opengl.CompositeMode, filter graphics.Filter) {
|
||||
dx, dy, _, _ := img.region()
|
||||
sx0 += dx
|
||||
sy0 += dy
|
||||
sx1 += dx
|
||||
sy1 += dy
|
||||
s.sharedImage.restorable.DrawImage(img.sharedImage.restorable, sx0, sy0, sx1, sy1, geom, colorm, mode, filter)
|
||||
}
|
||||
|
||||
func (s *sharedImagePart) ReplacePixels(pixels []byte, x, y, width, height int) {
|
||||
s.sharedImage.restorable.ReplacePixels(pixels, x, y, width, height)
|
||||
func (s *sharedImagePart) ReplacePixels(p []byte) {
|
||||
x, y, w, h := s.region()
|
||||
if l := 4 * w * h; len(p) != l {
|
||||
panic(fmt.Sprintf("ebiten: len(p) was %d but must be %d", len(p), l))
|
||||
}
|
||||
s.sharedImage.restorable.ReplacePixels(p, x, y, w, h)
|
||||
}
|
||||
|
||||
func (s *sharedImagePart) At(x, y int) (color.Color, error) {
|
||||
return s.sharedImage.restorable.At(x, y)
|
||||
ox, oy, w, h := s.region()
|
||||
if x < 0 || y < 0 || x >= w || y >= h {
|
||||
return color.RGBA{}, nil
|
||||
}
|
||||
return s.sharedImage.restorable.At(x+ox, y+oy)
|
||||
}
|
||||
|
||||
func (s *sharedImagePart) isDisposed() bool {
|
||||
|
Loading…
Reference in New Issue
Block a user