mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-10 04:57:26 +01:00
graphics: Check isDisposed at (*Image).Clear and Fill
This commit is contained in:
parent
ce2168c0d6
commit
008ed26276
14
image.go
14
image.go
@ -61,6 +61,10 @@ func (i *Image) Size() (width, height int) {
|
|||||||
return i.shareableImage.Size()
|
return i.shareableImage.Size()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (i *Image) isDisposed() bool {
|
||||||
|
return i.shareableImage == nil
|
||||||
|
}
|
||||||
|
|
||||||
// Clear resets the pixels of the image into 0.
|
// Clear resets the pixels of the image into 0.
|
||||||
//
|
//
|
||||||
// When the image is disposed, Clear does nothing.
|
// When the image is disposed, Clear does nothing.
|
||||||
@ -68,6 +72,9 @@ func (i *Image) Size() (width, height int) {
|
|||||||
// Clear always returns nil as of 1.5.0-alpha.
|
// Clear always returns nil as of 1.5.0-alpha.
|
||||||
func (i *Image) Clear() error {
|
func (i *Image) Clear() error {
|
||||||
i.copyCheck()
|
i.copyCheck()
|
||||||
|
if i.isDisposed() {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
i.fill(0, 0, 0, 0)
|
i.fill(0, 0, 0, 0)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -79,6 +86,9 @@ func (i *Image) Clear() error {
|
|||||||
// Fill always returns nil as of 1.5.0-alpha.
|
// Fill always returns nil as of 1.5.0-alpha.
|
||||||
func (i *Image) Fill(clr color.Color) error {
|
func (i *Image) Fill(clr color.Color) error {
|
||||||
i.copyCheck()
|
i.copyCheck()
|
||||||
|
if i.isDisposed() {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
r, g, b, a := clr.RGBA()
|
r, g, b, a := clr.RGBA()
|
||||||
i.fill(uint8(r>>8), uint8(g>>8), uint8(b>>8), uint8(a>>8))
|
i.fill(uint8(r>>8), uint8(g>>8), uint8(b>>8), uint8(a>>8))
|
||||||
return nil
|
return nil
|
||||||
@ -103,10 +113,6 @@ func (i *Image) fill(r, g, b, a uint8) {
|
|||||||
_ = i.DrawImage(emptyImage, op)
|
_ = i.DrawImage(emptyImage, op)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (i *Image) isDisposed() bool {
|
|
||||||
return i.shareableImage == nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// DrawImage draws the given image on the image i.
|
// DrawImage draws the given image on the image i.
|
||||||
//
|
//
|
||||||
// DrawImage accepts the options. For details, see the document of DrawImageOptions.
|
// DrawImage accepts the options. For details, see the document of DrawImageOptions.
|
||||||
|
Loading…
Reference in New Issue
Block a user