diff --git a/graphics/context.go b/graphics/context.go index 165727591..2ef8f7052 100644 --- a/graphics/context.go +++ b/graphics/context.go @@ -4,6 +4,7 @@ import ( "github.com/hajimehoshi/ebiten/graphics/matrix" ) +// A Rect represents a rectangle. type Rect struct { X int Y int @@ -11,16 +12,19 @@ type Rect struct { Height int } +// A TexturePart represents a part of a texture. type TexturePart struct { LocationX int LocationY int Source Rect } +// A Drawer is the interface that draws itself. type Drawer interface { Draw(parts []TexturePart, geometryMatrix matrix.Geometry, colorMatrix matrix.Color) } +// DrawWhole draws the whole texture. func DrawWhole(drawer Drawer, width, height int, geo matrix.Geometry, color matrix.Color) { parts := []TexturePart{ {0, 0, Rect{0, 0, width, height}}, @@ -28,6 +32,7 @@ func DrawWhole(drawer Drawer, width, height int, geo matrix.Geometry, color matr drawer.Draw(parts, geo, color) } +// A Context is the interface that means a context of rendering. type Context interface { Clear() Fill(r, g, b uint8) diff --git a/graphics/texturefactory.go b/graphics/texturefactory.go index c8163adf1..1332eafb4 100644 --- a/graphics/texturefactory.go +++ b/graphics/texturefactory.go @@ -4,6 +4,8 @@ import ( "image" ) +// Filter represents the type of filter to be used when a texture or a render +// target is maginified or minified. type Filter int const ( @@ -11,23 +13,30 @@ const ( FilterLinear ) +// TextureID represents an ID of a texture. type TextureID int +// RenderTargetID represents an ID of a render target. // A render target is essentially same as a texture, but it is assumed that the // all alpha of a render target is maximum. type RenderTargetID int var currentTextureFactory TextureFactory +// A TextureFactory is the interface that creates a render target or a texture. +// This method is for the library and a game developer doesn't have to use this. type TextureFactory interface { NewRenderTargetID(width, height int, filter Filter) (RenderTargetID, error) NewTextureID(img image.Image, filter Filter) (TextureID, error) } +// SetTextureFactory sets the current texture factory. +// This method is for the library and a game developer doesn't have to use this. func SetTextureFactory(textureFactory TextureFactory) { currentTextureFactory = textureFactory } +// NewRenderTargetID returns an ID of a newly created render target. func NewRenderTargetID(width, height int, filter Filter) (RenderTargetID, error) { if currentTextureFactory == nil { panic("graphics.NewRenderTarget: currentTextureFactory is not set.") @@ -35,6 +44,7 @@ func NewRenderTargetID(width, height int, filter Filter) (RenderTargetID, error) return currentTextureFactory.NewRenderTargetID(width, height, filter) } +// NewRenderTargetID returns an ID of a newly created texture. func NewTextureID(img image.Image, filter Filter) (TextureID, error) { if currentTextureFactory == nil { panic("graphics.NewTexture: currentTextureFactory is not set")