Remove graphics.Point and graphics.Size

This commit is contained in:
Hajime Hoshi 2013-06-22 01:52:10 +09:00
parent fad8fb7a98
commit 79a68a425b
5 changed files with 25 additions and 42 deletions

View File

@ -57,10 +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,
graphics.Rectangle{
graphics.Point{0, 0},
graphics.Size{int(tx), int(ty)},
},
graphics.Rect{0, 0, int(tx), int(ty)},
geometryMatrix,
matrix.IdentityColor())
}

View File

@ -110,10 +110,10 @@ func (game *Sprites) Draw(g graphics.GraphicsContext, offscreen graphics.Texture
texture := game.ebitenTexture
for _, sprite := range game.sprites {
location := graphics.TextureLocation{
Location: graphics.Point{sprite.x, sprite.y},
Source: graphics.Rectangle{
graphics.Point{0, 0},
graphics.Size{texture.Width, texture.Height},
LocationX: sprite.x,
LocationY: sprite.y,
Source: graphics.Rect{
0, 0, texture.Width, texture.Height,
},
}
locations = append(locations, location)

View File

@ -11,31 +11,24 @@ type Device interface {
TextureFactory() TextureFactory
}
type Point struct {
X int
Y int
}
type Size struct {
Width int
type Rect struct {
X int
Y int
Width int
Height int
}
type Rectangle struct {
Location Point
Size Size
}
type TextureLocation struct {
Location Point
Source Rectangle
LocationX int
LocationY int
Source Rect
}
type GraphicsContext interface {
Clear()
Fill(color color.Color)
DrawTexture(textureId TextureID,
source Rectangle,
source Rect,
geometryMatrix matrix.Geometry, colorMatrix matrix.Color)
DrawTextures(textureId TextureID,
locations []TextureLocation,

View File

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

View File

@ -66,14 +66,9 @@ func (context *GraphicsContext) DrawRect(x, y, width, height int, clr color.Colo
}
func (context *GraphicsContext) DrawTexture(
textureID graphics.TextureID, source graphics.Rectangle,
textureID graphics.TextureID, source graphics.Rect,
geometryMatrix matrix.Geometry, colorMatrix matrix.Color) {
locations := []graphics.TextureLocation{
{
graphics.Point{0, 0},
source,
},
}
locations := []graphics.TextureLocation{{0, 0, source}}
context.DrawTextures(textureID, locations,
geometryMatrix, colorMatrix)
}
@ -87,7 +82,6 @@ func (context *GraphicsContext) DrawTextures(
context.setShaderProgram(geometryMatrix, colorMatrix)
C.glBindTexture(C.GL_TEXTURE_2D, texture.id)
vertexAttrLocation := getAttributeLocation(context.currentShaderProgram, "vertex")
textureAttrLocation := getAttributeLocation(context.currentShaderProgram, "texture")
@ -96,10 +90,10 @@ func (context *GraphicsContext) DrawTextures(
C.glEnableVertexAttribArray(C.GLuint(vertexAttrLocation))
C.glEnableVertexAttribArray(C.GLuint(textureAttrLocation))
for _, location := range locations {
x1 := float32(location.Location.X)
x2 := float32(location.Location.X + location.Source.Size.Width)
y1 := float32(location.Location.Y)
y2 := float32(location.Location.Y + location.Source.Size.Height)
x1 := float32(location.LocationX)
x2 := float32(location.LocationX + location.Source.Width)
y1 := float32(location.LocationY)
y2 := float32(location.LocationY + location.Source.Height)
vertex := [...]float32{
x1, y1,
x2, y1,
@ -108,10 +102,10 @@ func (context *GraphicsContext) DrawTextures(
}
src := location.Source
tu1 := float32(src.Location.X) / float32(texture.textureWidth)
tu2 := float32(src.Location.X+src.Size.Width) / float32(texture.textureWidth)
tv1 := float32(src.Location.Y) / float32(texture.textureHeight)
tv2 := float32(src.Location.Y+src.Size.Height) / 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,