mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-01-26 10:42:42 +01:00
Add comments (to pass golint)
This commit is contained in:
parent
c1fa38ebed
commit
ca5bd564a6
@ -21,12 +21,15 @@ import (
|
|||||||
"math"
|
"math"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// ColorMatrixDim is a dimension of a ColorMatrix.
|
||||||
const ColorMatrixDim = 5
|
const ColorMatrixDim = 5
|
||||||
|
|
||||||
|
// A ColorMatrix represents a matrix to transform coloring when rendering a texture or a render target.
|
||||||
type ColorMatrix struct {
|
type ColorMatrix struct {
|
||||||
Elements [ColorMatrixDim - 1][ColorMatrixDim]float64
|
Elements [ColorMatrixDim - 1][ColorMatrixDim]float64
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ColorMatrixI returns an identity color matrix.
|
||||||
func ColorMatrixI() ColorMatrix {
|
func ColorMatrixI() ColorMatrix {
|
||||||
return ColorMatrix{
|
return ColorMatrix{
|
||||||
[ColorMatrixDim - 1][ColorMatrixDim]float64{
|
[ColorMatrixDim - 1][ColorMatrixDim]float64{
|
||||||
@ -42,16 +45,19 @@ func (c *ColorMatrix) dim() int {
|
|||||||
return ColorMatrixDim
|
return ColorMatrixDim
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Element returns a value of a matrix at (i, j).
|
||||||
func (c *ColorMatrix) Element(i, j int) float64 {
|
func (c *ColorMatrix) Element(i, j int) float64 {
|
||||||
return c.Elements[i][j]
|
return c.Elements[i][j]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Concat multiplies a color matrix with the other color matrix.
|
||||||
func (c *ColorMatrix) Concat(other ColorMatrix) {
|
func (c *ColorMatrix) Concat(other ColorMatrix) {
|
||||||
result := ColorMatrix{}
|
result := ColorMatrix{}
|
||||||
mul(&other, c, &result)
|
mul(&other, c, &result)
|
||||||
*c = result
|
*c = result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// IsIdentity returns a boolean indicating whether the color matrix is an identity.
|
||||||
func (c *ColorMatrix) IsIdentity() bool {
|
func (c *ColorMatrix) IsIdentity() bool {
|
||||||
return isIdentity(c)
|
return isIdentity(c)
|
||||||
}
|
}
|
||||||
@ -60,6 +66,7 @@ func (c *ColorMatrix) setElement(i, j int, element float64) {
|
|||||||
c.Elements[i][j] = element
|
c.Elements[i][j] = element
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Monochrome returns a color matrix to make the texture monochrome.
|
||||||
func Monochrome() ColorMatrix {
|
func Monochrome() ColorMatrix {
|
||||||
const r float64 = 6968.0 / 32768.0
|
const r float64 = 6968.0 / 32768.0
|
||||||
const g float64 = 23434.0 / 32768.0
|
const g float64 = 23434.0 / 32768.0
|
||||||
@ -83,6 +90,7 @@ func rgba(clr color.Color) (float64, float64, float64, float64) {
|
|||||||
return rf, gf, bf, af
|
return rf, gf, bf, af
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Scale scales the color matrix by clr.
|
||||||
func (c *ColorMatrix) Scale(clr color.Color) {
|
func (c *ColorMatrix) Scale(clr color.Color) {
|
||||||
rf, gf, bf, af := rgba(clr)
|
rf, gf, bf, af := rgba(clr)
|
||||||
for i, e := range []float64{rf, gf, bf, af} {
|
for i, e := range []float64{rf, gf, bf, af} {
|
||||||
@ -92,6 +100,7 @@ func (c *ColorMatrix) Scale(clr color.Color) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Translate translates the color matrix by clr.
|
||||||
func (c *ColorMatrix) Translate(clr color.Color) {
|
func (c *ColorMatrix) Translate(clr color.Color) {
|
||||||
rf, gf, bf, af := rgba(clr)
|
rf, gf, bf, af := rgba(clr)
|
||||||
c.Elements[0][4] = rf
|
c.Elements[0][4] = rf
|
||||||
|
@ -21,14 +21,17 @@ import (
|
|||||||
"image"
|
"image"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// IsKeyPressed returns a boolean indicating whether key is pressed.
|
||||||
func IsKeyPressed(key Key) bool {
|
func IsKeyPressed(key Key) bool {
|
||||||
return currentUI.input.isKeyPressed(key)
|
return currentUI.input.isKeyPressed(key)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// CursorPosition returns a position of a mouse cursor.
|
||||||
func CursorPosition() (x, y int) {
|
func CursorPosition() (x, y int) {
|
||||||
return currentUI.input.cursorPosition()
|
return currentUI.input.cursorPosition()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// IsMouseButtonPressed returns a boolean indicating whether mouseButton is pressed.
|
||||||
func IsMouseButtonPressed(mouseButton MouseButton) bool {
|
func IsMouseButtonPressed(mouseButton MouseButton) bool {
|
||||||
return currentUI.input.isMouseButtonPressed(mouseButton)
|
return currentUI.input.isMouseButtonPressed(mouseButton)
|
||||||
}
|
}
|
||||||
@ -44,10 +47,12 @@ func glFilter(f Filter) int {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewRenderTargetID returns a new RenderTargetID.
|
||||||
func NewRenderTargetID(width, height int, filter Filter) (RenderTargetID, error) {
|
func NewRenderTargetID(width, height int, filter Filter) (RenderTargetID, error) {
|
||||||
return currentUI.newRenderTargetID(width, height, glFilter(filter))
|
return currentUI.newRenderTargetID(width, height, glFilter(filter))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewTextureID returns a new TextureID.
|
||||||
func NewTextureID(img image.Image, filter Filter) (TextureID, error) {
|
func NewTextureID(img image.Image, filter Filter) (TextureID, error) {
|
||||||
return currentUI.newTextureID(img, glFilter(filter))
|
return currentUI.newTextureID(img, glFilter(filter))
|
||||||
}
|
}
|
||||||
|
@ -20,12 +20,15 @@ import (
|
|||||||
"math"
|
"math"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// GeometryMatrixDim is a dimension of a GeometryMatrix.
|
||||||
const GeometryMatrixDim = 3
|
const GeometryMatrixDim = 3
|
||||||
|
|
||||||
|
// A GeometryMatrix represents a matrix to transform geometry when rendering a texture or a render target.
|
||||||
type GeometryMatrix struct {
|
type GeometryMatrix struct {
|
||||||
Elements [GeometryMatrixDim - 1][GeometryMatrixDim]float64
|
Elements [GeometryMatrixDim - 1][GeometryMatrixDim]float64
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GeometryMatrixI returns an identity geometry matrix.
|
||||||
func GeometryMatrixI() GeometryMatrix {
|
func GeometryMatrixI() GeometryMatrix {
|
||||||
return GeometryMatrix{
|
return GeometryMatrix{
|
||||||
[GeometryMatrixDim - 1][GeometryMatrixDim]float64{
|
[GeometryMatrixDim - 1][GeometryMatrixDim]float64{
|
||||||
@ -39,16 +42,19 @@ func (g *GeometryMatrix) dim() int {
|
|||||||
return GeometryMatrixDim
|
return GeometryMatrixDim
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Element returns a value of a matrix at (i, j).
|
||||||
func (g *GeometryMatrix) Element(i, j int) float64 {
|
func (g *GeometryMatrix) Element(i, j int) float64 {
|
||||||
return g.Elements[i][j]
|
return g.Elements[i][j]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Concat multiplies a geometry matrix with the other geometry matrix.
|
||||||
func (g *GeometryMatrix) Concat(other GeometryMatrix) {
|
func (g *GeometryMatrix) Concat(other GeometryMatrix) {
|
||||||
result := GeometryMatrix{}
|
result := GeometryMatrix{}
|
||||||
mul(&other, g, &result)
|
mul(&other, g, &result)
|
||||||
*g = result
|
*g = result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// IsIdentity returns a boolean indicating whether the geometry matrix is an identity.
|
||||||
func (g *GeometryMatrix) IsIdentity() bool {
|
func (g *GeometryMatrix) IsIdentity() bool {
|
||||||
return isIdentity(g)
|
return isIdentity(g)
|
||||||
}
|
}
|
||||||
@ -57,11 +63,13 @@ func (g *GeometryMatrix) setElement(i, j int, element float64) {
|
|||||||
g.Elements[i][j] = element
|
g.Elements[i][j] = element
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Translate translates the geometry matrix by (tx, ty).
|
||||||
func (g *GeometryMatrix) Translate(tx, ty float64) {
|
func (g *GeometryMatrix) Translate(tx, ty float64) {
|
||||||
g.Elements[0][2] += tx
|
g.Elements[0][2] += tx
|
||||||
g.Elements[1][2] += ty
|
g.Elements[1][2] += ty
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Scale scales the geometry matrix by (x, y).
|
||||||
func (g *GeometryMatrix) Scale(x, y float64) {
|
func (g *GeometryMatrix) Scale(x, y float64) {
|
||||||
g.Elements[0][0] *= x
|
g.Elements[0][0] *= x
|
||||||
g.Elements[0][1] *= x
|
g.Elements[0][1] *= x
|
||||||
@ -71,6 +79,7 @@ func (g *GeometryMatrix) Scale(x, y float64) {
|
|||||||
g.Elements[1][2] *= y
|
g.Elements[1][2] *= y
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Rotate rotates the geometry matrix by theta.
|
||||||
func (g *GeometryMatrix) Rotate(theta float64) {
|
func (g *GeometryMatrix) Rotate(theta float64) {
|
||||||
sin, cos := math.Sincos(theta)
|
sin, cos := math.Sincos(theta)
|
||||||
rotate := GeometryMatrix{
|
rotate := GeometryMatrix{
|
||||||
|
@ -49,7 +49,7 @@ func DrawWhole(drawer Drawer, width, height int, geo GeometryMatrix, color Color
|
|||||||
return drawer.Draw(parts, geo, color)
|
return drawer.Draw(parts, geo, color)
|
||||||
}
|
}
|
||||||
|
|
||||||
// A Context is the interface that means a context of rendering.
|
// A GraphicsContext is the interface that means a context of rendering.
|
||||||
type GraphicsContext interface {
|
type GraphicsContext interface {
|
||||||
Clear() error
|
Clear() error
|
||||||
Fill(r, g, b uint8) error
|
Fill(r, g, b uint8) error
|
||||||
@ -64,6 +64,7 @@ type GraphicsContext interface {
|
|||||||
// target is maginified or minified.
|
// target is maginified or minified.
|
||||||
type Filter int
|
type Filter int
|
||||||
|
|
||||||
|
// Filters
|
||||||
const (
|
const (
|
||||||
FilterNearest Filter = iota
|
FilterNearest Filter = iota
|
||||||
FilterLinear
|
FilterLinear
|
||||||
|
46
ids.go
46
ids.go
@ -29,8 +29,8 @@ type ids struct {
|
|||||||
textures map[TextureID]*opengl.Texture
|
textures map[TextureID]*opengl.Texture
|
||||||
renderTargets map[RenderTargetID]*opengl.RenderTarget
|
renderTargets map[RenderTargetID]*opengl.RenderTarget
|
||||||
renderTargetToTexture map[RenderTargetID]TextureID
|
renderTargetToTexture map[RenderTargetID]TextureID
|
||||||
lastId int
|
lastID int
|
||||||
currentRenderTargetId RenderTargetID
|
currentRenderTargetID RenderTargetID
|
||||||
sync.RWMutex
|
sync.RWMutex
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -38,7 +38,7 @@ var idsInstance = &ids{
|
|||||||
textures: map[TextureID]*opengl.Texture{},
|
textures: map[TextureID]*opengl.Texture{},
|
||||||
renderTargets: map[RenderTargetID]*opengl.RenderTarget{},
|
renderTargets: map[RenderTargetID]*opengl.RenderTarget{},
|
||||||
renderTargetToTexture: map[RenderTargetID]TextureID{},
|
renderTargetToTexture: map[RenderTargetID]TextureID{},
|
||||||
currentRenderTargetId: -1,
|
currentRenderTargetID: -1,
|
||||||
}
|
}
|
||||||
|
|
||||||
func (i *ids) textureAt(id TextureID) *opengl.Texture {
|
func (i *ids) textureAt(id TextureID) *opengl.Texture {
|
||||||
@ -67,10 +67,10 @@ func (i *ids) createTexture(img image.Image, filter int) (TextureID, error) {
|
|||||||
|
|
||||||
i.Lock()
|
i.Lock()
|
||||||
defer i.Unlock()
|
defer i.Unlock()
|
||||||
i.lastId++
|
i.lastID++
|
||||||
textureId := TextureID(i.lastId)
|
textureID := TextureID(i.lastID)
|
||||||
i.textures[textureId] = texture
|
i.textures[textureID] = texture
|
||||||
return textureId, nil
|
return textureID, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (i *ids) createRenderTarget(width, height int, filter int) (RenderTargetID, error) {
|
func (i *ids) createRenderTarget(width, height int, filter int) (RenderTargetID, error) {
|
||||||
@ -80,7 +80,7 @@ func (i *ids) createRenderTarget(width, height int, filter int) (RenderTargetID,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// The current binded framebuffer can be changed.
|
// The current binded framebuffer can be changed.
|
||||||
i.currentRenderTargetId = -1
|
i.currentRenderTargetID = -1
|
||||||
r, err := opengl.NewRenderTargetFromTexture(texture)
|
r, err := opengl.NewRenderTargetFromTexture(texture)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
@ -88,24 +88,24 @@ func (i *ids) createRenderTarget(width, height int, filter int) (RenderTargetID,
|
|||||||
|
|
||||||
i.Lock()
|
i.Lock()
|
||||||
defer i.Unlock()
|
defer i.Unlock()
|
||||||
i.lastId++
|
i.lastID++
|
||||||
textureId := TextureID(i.lastId)
|
textureID := TextureID(i.lastID)
|
||||||
i.lastId++
|
i.lastID++
|
||||||
renderTargetId := RenderTargetID(i.lastId)
|
renderTargetID := RenderTargetID(i.lastID)
|
||||||
|
|
||||||
i.textures[textureId] = texture
|
i.textures[textureID] = texture
|
||||||
i.renderTargets[renderTargetId] = r
|
i.renderTargets[renderTargetID] = r
|
||||||
i.renderTargetToTexture[renderTargetId] = textureId
|
i.renderTargetToTexture[renderTargetID] = textureID
|
||||||
|
|
||||||
return renderTargetId, nil
|
return renderTargetID, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// NOTE: renderTarget can't be used as a texture.
|
// NOTE: renderTarget can't be used as a texture.
|
||||||
func (i *ids) addRenderTarget(renderTarget *opengl.RenderTarget) RenderTargetID {
|
func (i *ids) addRenderTarget(renderTarget *opengl.RenderTarget) RenderTargetID {
|
||||||
i.Lock()
|
i.Lock()
|
||||||
defer i.Unlock()
|
defer i.Unlock()
|
||||||
i.lastId++
|
i.lastID++
|
||||||
id := RenderTargetID(i.lastId)
|
id := RenderTargetID(i.lastID)
|
||||||
i.renderTargets[id] = renderTarget
|
i.renderTargets[id] = renderTarget
|
||||||
|
|
||||||
return id
|
return id
|
||||||
@ -116,15 +116,15 @@ func (i *ids) deleteRenderTarget(id RenderTargetID) {
|
|||||||
defer i.Unlock()
|
defer i.Unlock()
|
||||||
|
|
||||||
renderTarget := i.renderTargets[id]
|
renderTarget := i.renderTargets[id]
|
||||||
textureId := i.renderTargetToTexture[id]
|
textureID := i.renderTargetToTexture[id]
|
||||||
texture := i.textures[textureId]
|
texture := i.textures[textureID]
|
||||||
|
|
||||||
renderTarget.Dispose()
|
renderTarget.Dispose()
|
||||||
texture.Dispose()
|
texture.Dispose()
|
||||||
|
|
||||||
delete(i.renderTargets, id)
|
delete(i.renderTargets, id)
|
||||||
delete(i.renderTargetToTexture, id)
|
delete(i.renderTargetToTexture, id)
|
||||||
delete(i.textures, textureId)
|
delete(i.textures, textureID)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (i *ids) fillRenderTarget(id RenderTargetID, r, g, b uint8) error {
|
func (i *ids) fillRenderTarget(id RenderTargetID, r, g, b uint8) error {
|
||||||
@ -151,11 +151,11 @@ func (i *ids) drawTexture(target RenderTargetID, id TextureID, parts []TexturePa
|
|||||||
|
|
||||||
func (i *ids) setViewportIfNeeded(id RenderTargetID) error {
|
func (i *ids) setViewportIfNeeded(id RenderTargetID) error {
|
||||||
r := i.renderTargetAt(id)
|
r := i.renderTargetAt(id)
|
||||||
if i.currentRenderTargetId != id {
|
if i.currentRenderTargetID != id {
|
||||||
if err := r.SetAsViewport(); err != nil {
|
if err := r.SetAsViewport(); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
i.currentRenderTargetId = id
|
i.currentRenderTargetID = id
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
5
keys.go
5
keys.go
@ -16,9 +16,12 @@ limitations under the License.
|
|||||||
|
|
||||||
package ebiten
|
package ebiten
|
||||||
|
|
||||||
|
// A Key represents a keyboard key.
|
||||||
type Key int
|
type Key int
|
||||||
|
|
||||||
// TODO: Add more keys.
|
// TODO: Add more keys.
|
||||||
|
|
||||||
|
// Keys
|
||||||
const (
|
const (
|
||||||
KeyUp Key = iota
|
KeyUp Key = iota
|
||||||
KeyDown
|
KeyDown
|
||||||
@ -28,8 +31,10 @@ const (
|
|||||||
KeyMax
|
KeyMax
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// A MouseButton represents a mouse button.
|
||||||
type MouseButton int
|
type MouseButton int
|
||||||
|
|
||||||
|
// MouseButtons
|
||||||
const (
|
const (
|
||||||
MouseButtonLeft MouseButton = iota
|
MouseButtonLeft MouseButton = iota
|
||||||
MouseButtonRight
|
MouseButtonRight
|
||||||
|
Loading…
Reference in New Issue
Block a user