mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-10 04:57:26 +01:00
ebiten: Bug fix: Fill on a sub-image didn't work correctly
Closes #1691
This commit is contained in:
parent
8ab047853e
commit
a6ea4dbb74
8
image.go
8
image.go
@ -89,7 +89,13 @@ func init() {
|
||||
//
|
||||
// When the image is disposed, Fill does nothing.
|
||||
func (i *Image) Fill(clr color.Color) {
|
||||
w, h := i.Size()
|
||||
// Use the original size to cover the entire region (#1691).
|
||||
// DrawImage automatically clips the rendering region.
|
||||
orig := i
|
||||
if i.isSubImage() {
|
||||
orig = i.original
|
||||
}
|
||||
w, h := orig.Size()
|
||||
|
||||
op := &DrawImageOptions{}
|
||||
op.GeoM.Scale(float64(w), float64(h))
|
||||
|
@ -2207,3 +2207,36 @@ func TestImageClip(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Issue #1691
|
||||
func TestImageSubImageFill(t *testing.T) {
|
||||
dst := NewImage(3, 3).SubImage(image.Rect(1, 1, 2, 2)).(*Image)
|
||||
dst.Fill(color.White)
|
||||
for j := 0; j < 3; j++ {
|
||||
for i := 0; i < 3; i++ {
|
||||
got := dst.At(i, j)
|
||||
var want color.RGBA
|
||||
if i == 1 && j == 1 {
|
||||
want = color.RGBA{0xff, 0xff, 0xff, 0xff}
|
||||
}
|
||||
if got != want {
|
||||
t.Errorf("dst.At(%d, %d): got: %v, want: %v", i, j, got, want)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
dst = NewImage(17, 31).SubImage(image.Rect(3, 4, 8, 10)).(*Image)
|
||||
dst.Fill(color.White)
|
||||
for j := 0; j < 31; j++ {
|
||||
for i := 0; i < 17; i++ {
|
||||
got := dst.At(i, j)
|
||||
var want color.RGBA
|
||||
if 3 <= i && i < 8 && 4 <= j && j < 10 {
|
||||
want = color.RGBA{0xff, 0xff, 0xff, 0xff}
|
||||
}
|
||||
if got != want {
|
||||
t.Errorf("dst.At(%d, %d): got: %v, want: %v", i, j, got, want)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user