Add graphics.Rectangle

This commit is contained in:
Hajime Hoshi 2013-06-22 00:03:45 +09:00
parent 88eeb6d65d
commit a374565e37
5 changed files with 18 additions and 12 deletions

View File

@ -57,7 +57,7 @@ func (game *RotatingImage) Draw(g graphics.GraphicsContext, offscreen graphics.T
geometryMatrix.Translate(centerX-tx/2, centerY-ty/2)
g.DrawTexture(game.ebitenTexture.ID,
0, 0, int(tx), int(ty),
graphics.Rectangle{0, 0, int(tx), int(ty)},
geometryMatrix,
matrix.IdentityColor())
}

View File

@ -62,7 +62,7 @@ func (sprite *Sprite) Draw(g graphics.GraphicsContext) {
geometryMatrix.Translate(float64(sprite.x), float64(sprite.y))
g.DrawTexture(sprite.texture.ID,
0, 0, sprite.texture.Width, sprite.texture.Height,
graphics.Rectangle{0, 0, sprite.texture.Width, sprite.texture.Height},
geometryMatrix,
matrix.IdentityColor())
}

View File

@ -11,11 +11,18 @@ type Device interface {
TextureFactory() TextureFactory
}
type Rectangle struct {
X int
Y int
Width int
Height int
}
type GraphicsContext interface {
Clear()
Fill(color color.Color)
DrawTexture(textureId TextureID,
srcX, srcY, srcWidth, srcHeight int,
src Rectangle,
geometryMatrix matrix.Geometry, colorMatrix matrix.Color)
SetOffscreen(textureId TextureID)
}

View File

@ -56,7 +56,7 @@ func (device *Device) Update() {
},
}
g.DrawTexture(device.offscreenTexture.ID,
0, 0, device.screenWidth, device.screenHeight,
graphics.Rectangle{0, 0, device.screenWidth, device.screenHeight},
geometryMatrix, matrix.IdentityColor())
g.flush()
}

View File

@ -66,8 +66,7 @@ func (context *GraphicsContext) DrawRect(x, y, width, height int, clr color.Colo
}
func (context *GraphicsContext) DrawTexture(
textureID graphics.TextureID,
srcX, srcY, srcWidth, srcHeight int,
textureID graphics.TextureID, src graphics.Rectangle,
geometryMatrix matrix.Geometry, colorMatrix matrix.Color) {
texture := context.textures[textureID]
@ -76,9 +75,9 @@ func (context *GraphicsContext) DrawTexture(
C.glBindTexture(C.GL_TEXTURE_2D, texture.id)
x1 := float32(0)
x2 := float32(srcWidth)
x2 := float32(src.Width)
y1 := float32(0)
y2 := float32(srcHeight)
y2 := float32(src.Height)
vertex := [...]float32{
x1, y1,
x2, y1,
@ -86,10 +85,10 @@ func (context *GraphicsContext) DrawTexture(
x2, y2,
}
tu1 := float32(srcX) / float32(texture.textureWidth)
tu2 := float32(srcX+srcWidth) / float32(texture.textureWidth)
tv1 := float32(srcY) / float32(texture.textureHeight)
tv2 := float32(srcY+srcHeight) / float32(texture.textureHeight)
tu1 := float32(src.X) / float32(texture.textureWidth)
tu2 := float32(src.X+src.Width) / float32(texture.textureWidth)
tv1 := float32(src.Y) / float32(texture.textureHeight)
tv2 := float32(src.Y+src.Height) / float32(texture.textureHeight)
texCoord := [...]float32{
tu1, tv1,
tu2, tv1,