mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-10 04:57:26 +01:00
Add comments
This commit is contained in:
parent
43fbffebfb
commit
1c52a28a83
@ -4,6 +4,7 @@ import (
|
|||||||
"github.com/hajimehoshi/ebiten/graphics/matrix"
|
"github.com/hajimehoshi/ebiten/graphics/matrix"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// A Rect represents a rectangle.
|
||||||
type Rect struct {
|
type Rect struct {
|
||||||
X int
|
X int
|
||||||
Y int
|
Y int
|
||||||
@ -11,16 +12,19 @@ type Rect struct {
|
|||||||
Height int
|
Height int
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// A TexturePart represents a part of a texture.
|
||||||
type TexturePart struct {
|
type TexturePart struct {
|
||||||
LocationX int
|
LocationX int
|
||||||
LocationY int
|
LocationY int
|
||||||
Source Rect
|
Source Rect
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// A Drawer is the interface that draws itself.
|
||||||
type Drawer interface {
|
type Drawer interface {
|
||||||
Draw(parts []TexturePart, geometryMatrix matrix.Geometry, colorMatrix matrix.Color)
|
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) {
|
func DrawWhole(drawer Drawer, width, height int, geo matrix.Geometry, color matrix.Color) {
|
||||||
parts := []TexturePart{
|
parts := []TexturePart{
|
||||||
{0, 0, Rect{0, 0, width, height}},
|
{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)
|
drawer.Draw(parts, geo, color)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// A Context is the interface that means a context of rendering.
|
||||||
type Context interface {
|
type Context interface {
|
||||||
Clear()
|
Clear()
|
||||||
Fill(r, g, b uint8)
|
Fill(r, g, b uint8)
|
||||||
|
@ -4,6 +4,8 @@ import (
|
|||||||
"image"
|
"image"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Filter represents the type of filter to be used when a texture or a render
|
||||||
|
// target is maginified or minified.
|
||||||
type Filter int
|
type Filter int
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -11,23 +13,30 @@ const (
|
|||||||
FilterLinear
|
FilterLinear
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// TextureID represents an ID of a texture.
|
||||||
type TextureID int
|
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
|
// A render target is essentially same as a texture, but it is assumed that the
|
||||||
// all alpha of a render target is maximum.
|
// all alpha of a render target is maximum.
|
||||||
type RenderTargetID int
|
type RenderTargetID int
|
||||||
|
|
||||||
var currentTextureFactory TextureFactory
|
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 {
|
type TextureFactory interface {
|
||||||
NewRenderTargetID(width, height int, filter Filter) (RenderTargetID, error)
|
NewRenderTargetID(width, height int, filter Filter) (RenderTargetID, error)
|
||||||
NewTextureID(img image.Image, filter Filter) (TextureID, 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) {
|
func SetTextureFactory(textureFactory TextureFactory) {
|
||||||
currentTextureFactory = textureFactory
|
currentTextureFactory = textureFactory
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewRenderTargetID returns an ID of a newly created render target.
|
||||||
func NewRenderTargetID(width, height int, filter Filter) (RenderTargetID, error) {
|
func NewRenderTargetID(width, height int, filter Filter) (RenderTargetID, error) {
|
||||||
if currentTextureFactory == nil {
|
if currentTextureFactory == nil {
|
||||||
panic("graphics.NewRenderTarget: currentTextureFactory is not set.")
|
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)
|
return currentTextureFactory.NewRenderTargetID(width, height, filter)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewRenderTargetID returns an ID of a newly created texture.
|
||||||
func NewTextureID(img image.Image, filter Filter) (TextureID, error) {
|
func NewTextureID(img image.Image, filter Filter) (TextureID, error) {
|
||||||
if currentTextureFactory == nil {
|
if currentTextureFactory == nil {
|
||||||
panic("graphics.NewTexture: currentTextureFactory is not set")
|
panic("graphics.NewTexture: currentTextureFactory is not set")
|
||||||
|
Loading…
Reference in New Issue
Block a user