Change TexturePart int -> float64

This commit is contained in:
Hajime Hoshi 2014-12-18 20:48:36 +09:00
parent 9c18aef725
commit c8007a6252
5 changed files with 19 additions and 20 deletions

View File

@ -45,10 +45,10 @@ func (d *debugPrintState) drawText(gr ebiten.GraphicsContext, str string, x, y i
} }
code := int(c) code := int(c)
const xCharNum = assets.TextImageWidth / assets.TextImageCharWidth const xCharNum = assets.TextImageWidth / assets.TextImageCharWidth
srcX := (code % xCharNum) * assets.TextImageCharWidth srcX := float64(code%xCharNum) * assets.TextImageCharWidth
srcY := (code / xCharNum) * assets.TextImageCharHeight srcY := float64(code/xCharNum) * assets.TextImageCharHeight
parts = append(parts, ebiten.TexturePart{ parts = append(parts, ebiten.TexturePart{
Dst: ebiten.Rect{locationX, locationY, assets.TextImageCharWidth, assets.TextImageCharHeight}, Dst: ebiten.Rect{float64(locationX), float64(locationY), assets.TextImageCharWidth, assets.TextImageCharHeight},
Src: ebiten.Rect{srcX, srcY, assets.TextImageCharWidth, assets.TextImageCharHeight}, Src: ebiten.Rect{srcX, srcY, assets.TextImageCharWidth, assets.TextImageCharHeight},
}) })
locationX += assets.TextImageCharWidth locationX += assets.TextImageCharWidth

View File

@ -36,8 +36,7 @@ func drawText(context ebiten.GraphicsContext, textures *Textures, str string, x,
fontTextureId := textures.GetTexture("font") fontTextureId := textures.GetTexture("font")
parts := []ebiten.TexturePart{} parts := []ebiten.TexturePart{}
locationX := 0 locationX, locationY := 0, 0
locationY := 0
for _, c := range str { for _, c := range str {
if c == '\n' { if c == '\n' {
locationX = 0 locationX = 0
@ -45,10 +44,10 @@ func drawText(context ebiten.GraphicsContext, textures *Textures, str string, x,
continue continue
} }
code := int(c) code := int(c)
x := (code % 16) * charWidth x := float64(code%16) * charWidth
y := ((code - 32) / 16) * charHeight y := float64((code-32)/16) * charHeight
parts = append(parts, ebiten.TexturePart{ parts = append(parts, ebiten.TexturePart{
Dst: ebiten.Rect{locationX, locationY, charWidth, charHeight}, Dst: ebiten.Rect{float64(locationX), float64(locationY), charWidth, charHeight},
Src: ebiten.Rect{x, y, charWidth, charHeight}, Src: ebiten.Rect{x, y, charWidth, charHeight},
}) })
locationX += charWidth locationX += charWidth

View File

@ -145,10 +145,10 @@ func drawBlocks(context ebiten.GraphicsContext, textures *Textures, blocks [][]B
if block == BlockTypeNone { if block == BlockTypeNone {
continue continue
} }
locationX := i * blockWidth locationX := float64(i * blockWidth)
locationY := j * blockHeight locationY := float64(j * blockHeight)
dst := ebiten.Rect{locationX, locationY, blockWidth, blockHeight} dst := ebiten.Rect{locationX, locationY, blockWidth, blockHeight}
src := ebiten.Rect{(int(block) - 1) * blockWidth, 0, blockWidth, blockHeight} src := ebiten.Rect{float64(int(block)-1) * blockWidth, 0, blockWidth, blockHeight}
parts = append(parts, ebiten.TexturePart{dst, src}) parts = append(parts, ebiten.TexturePart{dst, src})
} }
} }

View File

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

View File

@ -23,10 +23,10 @@ import (
// A Rect represents a rectangle. // A Rect represents a rectangle.
type Rect struct { type Rect struct {
X int X float64
Y int Y float64
Width int Width float64
Height int Height float64
} }
// A TexturePart represents a part of a texture. // A TexturePart represents a part of a texture.
@ -44,7 +44,7 @@ type Drawer interface {
func DrawWholeTexture(g GraphicsContext, texture *Texture, geo GeometryMatrix, color ColorMatrix) error { func DrawWholeTexture(g GraphicsContext, texture *Texture, geo GeometryMatrix, color ColorMatrix) error {
w, h := texture.Size() w, h := texture.Size()
parts := []TexturePart{ parts := []TexturePart{
{Rect{0, 0, w, h}, Rect{0, 0, w, h}}, {Rect{0, 0, float64(w), float64(h)}, Rect{0, 0, float64(w), float64(h)}},
} }
return g.Texture(texture).Draw(parts, geo, color) return g.Texture(texture).Draw(parts, geo, color)
} }
@ -53,7 +53,7 @@ func DrawWholeTexture(g GraphicsContext, texture *Texture, geo GeometryMatrix, c
func DrawWholeRenderTarget(g GraphicsContext, renderTarget *RenderTarget, geo GeometryMatrix, color ColorMatrix) error { func DrawWholeRenderTarget(g GraphicsContext, renderTarget *RenderTarget, geo GeometryMatrix, color ColorMatrix) error {
w, h := renderTarget.Size() w, h := renderTarget.Size()
parts := []TexturePart{ parts := []TexturePart{
{Rect{0, 0, w, h}, Rect{0, 0, w, h}}, {Rect{0, 0, float64(w), float64(h)}, Rect{0, 0, float64(w), float64(h)}},
} }
return g.RenderTarget(renderTarget).Draw(parts, geo, color) return g.RenderTarget(renderTarget).Draw(parts, geo, color)
} }
@ -102,11 +102,11 @@ func (r *RenderTarget) Size() (width int, height int) {
return r.glRenderTarget.Width(), r.glRenderTarget.Height() return r.glRenderTarget.Width(), r.glRenderTarget.Height()
} }
func u(x int, width int) float32 { func u(x float64, width int) float32 {
return float32(x) / float32(opengl.AdjustSizeForTexture(width)) return float32(x) / float32(opengl.AdjustSizeForTexture(width))
} }
func v(y int, height int) float32 { func v(y float64, height int) float32 {
return float32(y) / float32(opengl.AdjustSizeForTexture(height)) return float32(y) / float32(opengl.AdjustSizeForTexture(height))
} }