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