graphics: Refactoring

This commit is contained in:
Hajime Hoshi 2016-05-17 01:06:30 +09:00
parent 7ab2efaa3f
commit 18c14f8897

View File

@ -81,9 +81,7 @@ func (i *images) add(img *imageImpl) (*Image, error) {
} }
i.images[img] = struct{}{} i.images[img] = struct{}{}
eimg := &Image{img} eimg := &Image{img}
runtime.SetFinalizer(eimg, func(i *Image) { runtime.SetFinalizer(eimg, theImages.remove)
theImages.remove(i)
})
return eimg, nil return eimg, nil
} }
@ -140,14 +138,14 @@ type Image struct {
// //
// This function is concurrent-safe. // This function is concurrent-safe.
func (i *Image) Size() (width, height int) { func (i *Image) Size() (width, height int) {
return i.impl.Size() return i.impl.width, i.impl.height
} }
// Clear resets the pixels of the image into 0. // Clear resets the pixels of the image into 0.
// //
// This function is concurrent-safe. // This function is concurrent-safe.
func (i *Image) Clear() error { func (i *Image) Clear() error {
return i.impl.Clear() return i.impl.Fill(color.Transparent)
} }
// Fill fills the image with a solid color. // Fill fills the image with a solid color.
@ -182,14 +180,14 @@ func (i *Image) DrawImage(image *Image, options *DrawImageOptions) error {
// //
// This function is concurrent-safe. // This function is concurrent-safe.
func (i *Image) Bounds() image.Rectangle { func (i *Image) Bounds() image.Rectangle {
return i.impl.Bounds() return image.Rect(0, 0, i.impl.width, i.impl.height)
} }
// ColorModel returns the color model of the image. // ColorModel returns the color model of the image.
// //
// This function is concurrent-safe. // This function is concurrent-safe.
func (i *Image) ColorModel() color.Model { func (i *Image) ColorModel() color.Model {
return i.impl.ColorModel() return color.RGBAModel
} }
// At returns the color of the image at (x, y). // At returns the color of the image at (x, y).
@ -236,23 +234,7 @@ type imageImpl struct {
filter Filter filter Filter
} }
func (i *imageImpl) Size() (width, height int) { func (i *imageImpl) Fill(clr color.Color) error {
return i.width, i.height
}
func (i *imageImpl) Clear() error {
return i.clear()
}
func (i *imageImpl) clear() error {
return i.fill(color.Transparent)
}
func (i *imageImpl) Fill(clr color.Color) (err error) {
return i.fill(clr)
}
func (i *imageImpl) fill(clr color.Color) (err error) {
f := func() error { f := func() error {
imageM.Lock() imageM.Lock()
defer imageM.Unlock() defer imageM.Unlock()
@ -312,14 +294,6 @@ func (i *imageImpl) DrawImage(image *Image, options *DrawImageOptions) error {
return f() return f()
} }
func (i *imageImpl) Bounds() image.Rectangle {
return image.Rect(0, 0, i.width, i.height)
}
func (i *imageImpl) ColorModel() color.Model {
return color.RGBAModel
}
func (i *imageImpl) At(x, y int) color.Color { func (i *imageImpl) At(x, y int) color.Color {
if !currentRunContext.isRunning() { if !currentRunContext.isRunning() {
panic("ebiten: At can't be called when the GL context is not initialized (this panic happens as of version 1.4.0-alpha)") panic("ebiten: At can't be called when the GL context is not initialized (this panic happens as of version 1.4.0-alpha)")