Change TexturePart

This commit is contained in:
Hajime Hoshi 2014-12-18 20:04:40 +09:00
parent 87d49546f3
commit 9c18aef725
6 changed files with 23 additions and 32 deletions

View File

@ -48,9 +48,8 @@ func (d *debugPrintState) drawText(gr ebiten.GraphicsContext, str string, x, y i
srcX := (code % xCharNum) * assets.TextImageCharWidth
srcY := (code / xCharNum) * assets.TextImageCharHeight
parts = append(parts, ebiten.TexturePart{
LocationX: locationX,
LocationY: locationY,
Source: ebiten.Rect{srcX, srcY, assets.TextImageCharWidth, assets.TextImageCharHeight},
Dst: ebiten.Rect{locationX, locationY, assets.TextImageCharWidth, assets.TextImageCharHeight},
Src: ebiten.Rect{srcX, srcY, assets.TextImageCharWidth, assets.TextImageCharHeight},
})
locationX += assets.TextImageCharWidth
}

View File

@ -48,9 +48,8 @@ func drawText(context ebiten.GraphicsContext, textures *Textures, str string, x,
x := (code % 16) * charWidth
y := ((code - 32) / 16) * charHeight
parts = append(parts, ebiten.TexturePart{
LocationX: locationX,
LocationY: locationY,
Source: ebiten.Rect{x, y, charWidth, charHeight},
Dst: ebiten.Rect{locationX, locationY, charWidth, charHeight},
Src: ebiten.Rect{x, y, charWidth, charHeight},
})
locationX += charWidth
}

View File

@ -147,15 +147,9 @@ func drawBlocks(context ebiten.GraphicsContext, textures *Textures, blocks [][]B
}
locationX := i * blockWidth
locationY := j * blockHeight
source := ebiten.Rect{
(int(block) - 1) * blockWidth, 0,
blockWidth, blockHeight}
parts = append(parts,
ebiten.TexturePart{
LocationX: locationX,
LocationY: locationY,
Source: source,
})
dst := ebiten.Rect{locationX, locationY, blockWidth, blockHeight}
src := ebiten.Rect{(int(block) - 1) * blockWidth, 0, blockWidth, blockHeight}
parts = append(parts, ebiten.TexturePart{dst, src})
}
}
blocksTexture := textures.GetTexture("blocks")

View File

@ -59,9 +59,8 @@ func drawTitleBackground(context ebiten.GraphicsContext, textures *Textures, c i
for j := -1; j < ScreenHeight/textureHeight+1; j++ {
for i := 0; i < ScreenWidth/textureWidth+1; i++ {
parts = append(parts, ebiten.TexturePart{
LocationX: i * textureWidth,
LocationY: j * textureHeight,
Source: ebiten.Rect{0, 0, textureWidth, textureHeight},
Dst: ebiten.Rect{i * textureWidth, j * textureHeight, textureWidth, textureHeight},
Src: ebiten.Rect{0, 0, textureWidth, textureHeight},
})
}
}

View File

@ -58,7 +58,8 @@ func (g *Game) Update(gr ebiten.GraphicsContext) error {
geo.Concat(ebiten.ScaleGeometry(scaleX, scaleY))
geo.Concat(ebiten.RotateGeometry(float64(g.count%720) * 2 * math.Pi / 720))
geo.Concat(ebiten.TranslateGeometry(screenWidth/2, screenHeight/2))
clr := ebiten.RotateHue(float64(g.count%180) * 2 * math.Pi / 180)
//clr := ebiten.RotateHue(float64(g.count%180) * 2 * math.Pi / 180)
clr := ebiten.ColorMatrixI()
ebiten.DrawWholeTexture(gr, g.gophersTexture, geo, clr)
return nil
}

View File

@ -31,9 +31,8 @@ type Rect struct {
// A TexturePart represents a part of a texture.
type TexturePart struct {
LocationX int
LocationY int
Source Rect
Dst Rect
Src Rect
}
// A Drawer is the interface that draws itself.
@ -45,7 +44,7 @@ type Drawer interface {
func DrawWholeTexture(g GraphicsContext, texture *Texture, geo GeometryMatrix, color ColorMatrix) error {
w, h := texture.Size()
parts := []TexturePart{
{0, 0, Rect{0, 0, w, h}},
{Rect{0, 0, w, h}, Rect{0, 0, w, h}},
}
return g.Texture(texture).Draw(parts, geo, color)
}
@ -54,7 +53,7 @@ func DrawWholeTexture(g GraphicsContext, texture *Texture, geo GeometryMatrix, c
func DrawWholeRenderTarget(g GraphicsContext, renderTarget *RenderTarget, geo GeometryMatrix, color ColorMatrix) error {
w, h := renderTarget.Size()
parts := []TexturePart{
{0, 0, Rect{0, 0, w, h}},
{Rect{0, 0, w, h}, Rect{0, 0, w, h}},
}
return g.RenderTarget(renderTarget).Draw(parts, geo, color)
}
@ -114,14 +113,14 @@ func v(y int, height int) float32 {
func textureQuads(parts []TexturePart, width, height int) []shader.TextureQuad {
quads := make([]shader.TextureQuad, 0, len(parts))
for _, part := range parts {
x1 := float32(part.LocationX)
x2 := float32(part.LocationX + part.Source.Width)
y1 := float32(part.LocationY)
y2 := float32(part.LocationY + part.Source.Height)
u1 := u(part.Source.X, width)
u2 := u(part.Source.X+part.Source.Width, width)
v1 := v(part.Source.Y, height)
v2 := v(part.Source.Y+part.Source.Height, height)
x1 := float32(part.Dst.X)
x2 := float32(part.Dst.X + part.Dst.Width)
y1 := float32(part.Dst.Y)
y2 := float32(part.Dst.Y + part.Dst.Height)
u1 := u(part.Src.X, width)
u2 := u(part.Src.X+part.Src.Width, width)
v1 := v(part.Src.Y, height)
v2 := v(part.Src.Y+part.Src.Height, height)
quad := shader.TextureQuad{x1, x2, y1, y2, u1, u2, v1, v2}
quads = append(quads, quad)
}