mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-01-14 13:02:08 +01:00
Change API of graphics.Context
This commit is contained in:
parent
2d6818c81e
commit
562d04cacc
@ -45,7 +45,7 @@ func drawText(context graphics.Context, str string, x, y, scale int, clr color.C
|
|||||||
geoMat.Translate(float64(x), float64(y))
|
geoMat.Translate(float64(x), float64(y))
|
||||||
clrMat := matrix.IdentityColor()
|
clrMat := matrix.IdentityColor()
|
||||||
clrMat.Scale(clr)
|
clrMat.Scale(clr)
|
||||||
context.DrawTextureParts(fontTextureId, parts, geoMat, clrMat)
|
context.Texture(fontTextureId).DrawParts(parts, geoMat, clrMat)
|
||||||
}
|
}
|
||||||
|
|
||||||
func drawTextWithShadow(context graphics.Context, str string, x, y, scale int, clr color.Color) {
|
func drawTextWithShadow(context graphics.Context, str string, x, y, scale int, clr color.Color) {
|
||||||
|
@ -107,7 +107,7 @@ func (s *GameScene) Draw(context graphics.Context) {
|
|||||||
geoMat.Translate(20, 20) // magic number?
|
geoMat.Translate(20, 20) // magic number?
|
||||||
colorMat := matrix.IdentityColor()
|
colorMat := matrix.IdentityColor()
|
||||||
colorMat.Scale(color.RGBA{0, 0, 0, 0x80})
|
colorMat.Scale(color.RGBA{0, 0, 0, 0x80})
|
||||||
context.DrawTexture(field, geoMat, colorMat)
|
context.Texture(field).Draw(geoMat, colorMat)
|
||||||
|
|
||||||
geoMat = matrix.IdentityGeometry()
|
geoMat = matrix.IdentityGeometry()
|
||||||
geoMat.Translate(20, 20)
|
geoMat.Translate(20, 20)
|
||||||
|
@ -144,7 +144,7 @@ func drawBlocks(context graphics.Context, blocks [][]BlockType, geo matrix.Geome
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
blocksTexture := drawInfo.textures["blocks"]
|
blocksTexture := drawInfo.textures["blocks"]
|
||||||
context.DrawTextureParts(blocksTexture, parts, geo, matrix.IdentityColor())
|
context.Texture(blocksTexture).DrawParts(parts, geo, matrix.IdentityColor())
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Piece) InitialPosition() (int, int) {
|
func (p *Piece) InitialPosition() (int, int) {
|
||||||
|
@ -62,11 +62,11 @@ func (s *SceneManager) Draw(context graphics.Context) {
|
|||||||
|
|
||||||
context.ResetOffscreen()
|
context.ResetOffscreen()
|
||||||
color := matrix.IdentityColor()
|
color := matrix.IdentityColor()
|
||||||
context.DrawRenderTarget(from, matrix.IdentityGeometry(), color)
|
context.RenderTarget(from).Draw(matrix.IdentityGeometry(), color)
|
||||||
|
|
||||||
alpha := float64(s.transitionCount) / float64(transitionMaxCount)
|
alpha := float64(s.transitionCount) / float64(transitionMaxCount)
|
||||||
color.Elements[3][3] = alpha
|
color.Elements[3][3] = alpha
|
||||||
context.DrawRenderTarget(to, matrix.IdentityGeometry(), color)
|
context.RenderTarget(to).Draw(matrix.IdentityGeometry(), color)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *SceneManager) GoTo(scene Scene) {
|
func (s *SceneManager) GoTo(scene Scene) {
|
||||||
|
@ -57,7 +57,7 @@ func drawTitleBackground(context graphics.Context, c int) {
|
|||||||
geo := matrix.IdentityGeometry()
|
geo := matrix.IdentityGeometry()
|
||||||
geo.Translate(float64(dx), float64(dy))
|
geo.Translate(float64(dx), float64(dy))
|
||||||
clr := matrix.IdentityColor()
|
clr := matrix.IdentityColor()
|
||||||
context.DrawTextureParts(backgroundTextureId, parts, geo, clr)
|
context.Texture(backgroundTextureId).DrawParts(parts, geo, clr)
|
||||||
}
|
}
|
||||||
|
|
||||||
func drawLogo(context graphics.Context, str string) {
|
func drawLogo(context graphics.Context, str string) {
|
||||||
|
@ -4,24 +4,19 @@ import (
|
|||||||
"github.com/hajimehoshi/go-ebiten/graphics/matrix"
|
"github.com/hajimehoshi/go-ebiten/graphics/matrix"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type Drawer interface {
|
||||||
|
Draw(geometryMatrix matrix.Geometry,
|
||||||
|
colorMatrix matrix.Color)
|
||||||
|
DrawParts(parts []TexturePart,
|
||||||
|
geometryMatrix matrix.Geometry,
|
||||||
|
colorMatrix matrix.Color)
|
||||||
|
}
|
||||||
|
|
||||||
type Context interface {
|
type Context interface {
|
||||||
Clear()
|
Clear()
|
||||||
Fill(r, g, b uint8)
|
Fill(r, g, b uint8)
|
||||||
// TODO: Refacotring
|
Texture(id TextureId) Drawer
|
||||||
DrawTexture(id TextureId,
|
RenderTarget(id RenderTargetId) Drawer
|
||||||
geometryMatrix matrix.Geometry,
|
|
||||||
colorMatrix matrix.Color)
|
|
||||||
DrawRenderTarget(id RenderTargetId,
|
|
||||||
geometryMatrix matrix.Geometry,
|
|
||||||
colorMatrix matrix.Color)
|
|
||||||
DrawTextureParts(id TextureId,
|
|
||||||
parts []TexturePart,
|
|
||||||
geometryMatrix matrix.Geometry,
|
|
||||||
colorMatrix matrix.Color)
|
|
||||||
DrawRenderTargetParts(id RenderTargetId,
|
|
||||||
parts []TexturePart,
|
|
||||||
geometryMatrix matrix.Geometry,
|
|
||||||
colorMatrix matrix.Color)
|
|
||||||
|
|
||||||
ResetOffscreen()
|
ResetOffscreen()
|
||||||
SetOffscreen(id RenderTargetId)
|
SetOffscreen(id RenderTargetId)
|
||||||
|
@ -54,41 +54,25 @@ func (context *Context) Update(draw func(graphics.Context)) {
|
|||||||
scale := float64(context.screenScale)
|
scale := float64(context.screenScale)
|
||||||
geometryMatrix := matrix.IdentityGeometry()
|
geometryMatrix := matrix.IdentityGeometry()
|
||||||
geometryMatrix.Scale(scale, scale)
|
geometryMatrix.Scale(scale, scale)
|
||||||
context.DrawRenderTarget(context.screenId,
|
context.RenderTarget(context.screenId).Draw(geometryMatrix, matrix.IdentityColor())
|
||||||
geometryMatrix, matrix.IdentityColor())
|
|
||||||
|
|
||||||
flush()
|
flush()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (context *Context) Clear() {
|
func (c *Context) Clear() {
|
||||||
context.Fill(0, 0, 0)
|
c.Fill(0, 0, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (context *Context) Fill(r, g, b uint8) {
|
func (c *Context) Fill(r, g, b uint8) {
|
||||||
context.ids.FillRenderTarget(context.currentId, r, g, b)
|
c.ids.FillRenderTarget(c.currentId, r, g, b)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (context *Context) DrawTexture(
|
func (c *Context) Texture(id graphics.TextureId) graphics.Drawer {
|
||||||
id graphics.TextureId, geo matrix.Geometry, color matrix.Color) {
|
return &TextureWithContext{id, c}
|
||||||
context.ids.DrawTexture(context.currentId, id, geo, color)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (context *Context) DrawRenderTarget(
|
func (c *Context) RenderTarget(id graphics.RenderTargetId) graphics.Drawer {
|
||||||
id graphics.RenderTargetId,
|
return &RenderTargetWithContext{id, c}
|
||||||
geo matrix.Geometry, color matrix.Color) {
|
|
||||||
context.ids.DrawRenderTarget(context.currentId, id, geo, color)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (context *Context) DrawTextureParts(
|
|
||||||
id graphics.TextureId, parts []graphics.TexturePart,
|
|
||||||
geometryMatrix matrix.Geometry, colorMatrix matrix.Color) {
|
|
||||||
context.ids.DrawTextureParts(context.currentId, id, parts, geometryMatrix, colorMatrix)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (context *Context) DrawRenderTargetParts(
|
|
||||||
id graphics.RenderTargetId, parts []graphics.TexturePart,
|
|
||||||
geometryMatrix matrix.Geometry, colorMatrix matrix.Color) {
|
|
||||||
context.ids.DrawRenderTargetParts(context.currentId, id, parts, geometryMatrix, colorMatrix)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (context *Context) ResetOffscreen() {
|
func (context *Context) ResetOffscreen() {
|
||||||
@ -98,3 +82,29 @@ func (context *Context) ResetOffscreen() {
|
|||||||
func (context *Context) SetOffscreen(renderTargetId graphics.RenderTargetId) {
|
func (context *Context) SetOffscreen(renderTargetId graphics.RenderTargetId) {
|
||||||
context.currentId = renderTargetId
|
context.currentId = renderTargetId
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type TextureWithContext struct {
|
||||||
|
id graphics.TextureId
|
||||||
|
context *Context
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t *TextureWithContext) Draw(geo matrix.Geometry, color matrix.Color) {
|
||||||
|
t.context.ids.DrawTexture(t.context.currentId, t.id, geo, color)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t *TextureWithContext) DrawParts(parts []graphics.TexturePart, geo matrix.Geometry, color matrix.Color) {
|
||||||
|
t.context.ids.DrawTextureParts(t.context.currentId, t.id, parts, geo, color)
|
||||||
|
}
|
||||||
|
|
||||||
|
type RenderTargetWithContext struct {
|
||||||
|
id graphics.RenderTargetId
|
||||||
|
context *Context
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *RenderTargetWithContext) Draw(geo matrix.Geometry, color matrix.Color) {
|
||||||
|
r.context.ids.DrawRenderTarget(r.context.currentId, r.id, geo, color)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *RenderTargetWithContext) DrawParts(parts []graphics.TexturePart, geo matrix.Geometry, color matrix.Color) {
|
||||||
|
r.context.ids.DrawRenderTargetParts(r.context.currentId, r.id, parts, geo, color)
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user