Add comments

This commit is contained in:
Hajime Hoshi 2014-12-08 01:07:39 +09:00
parent 43fbffebfb
commit 1c52a28a83
2 changed files with 15 additions and 0 deletions

View File

@ -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)

View File

@ -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")