gg/src/gx/rect.go

87 lines
1.5 KiB
Go
Raw Normal View History

package gx
2023-05-22 23:39:01 +03:00
import (
"github.com/hajimehoshi/ebiten/v2"
//"github.com/hajimehoshi/ebiten/v2/vector"
"fmt"
//"image"
)
// The type describes rectangle geometry.
2023-05-22 23:39:01 +03:00
type Rectangle struct {
// Position of up left corner
// and the point to
// rotate around(relatively of position, not absolute).
T Transform
// Width and height.
2023-05-22 23:39:01 +03:00
// In fact are needed only to specify
// relation of width and height.
// Change transform to actually change things.
W, H Float
2023-05-22 23:39:01 +03:00
S *Shader
C Color
}
// Return points of corners of the rectangle.
func (r Rectangle) Corners() []Point {
return []Point{}
}
// Get 2 triangles that the rectangle consists of.
func (r Rectangle) Triangles() Triangles {
return Triangles{}
}
/*func MustNewImage(w, h int) (*Image) {
img, err := NewImage(w, h)
if err != nil {
panic(err)
}
return img
}*/
func NewImage(w, h int) (*Image) {
return ebiten.NewImage(w, h)
}
2023-05-22 23:39:01 +03:00
func (r Rectangle) Draw(
e *Engine,
i *Image,
) {
2023-05-22 23:51:14 +03:00
fmt.Println("drawing the rectangle:", r)
2023-05-22 23:39:01 +03:00
if r.S == nil {
img := NewImage(1, 1)
img.Set(0, 0, r.C)
t := r.T
t.S.X *= r.W
t.S.Y *= r.H
2023-05-22 23:51:14 +03:00
rm := e.Camera().RealMatrix(e, true)
2023-05-22 23:39:01 +03:00
m := t.Matrix(e)
2023-05-22 23:51:14 +03:00
m.Concat(rm)
2023-05-22 23:39:01 +03:00
opts := &ebiten.DrawImageOptions{
GeoM: m,
}
i.DrawImage(img, opts)
fmt.Println("done")
return
}
opts := &ebiten.DrawRectShaderOptions{
GeoM: r.T.Matrix(e),
Images: [4]*Image{
NewImage(1000, 1000),
nil,
nil,
nil,
},
}
//w := int(r.W * r.T.S.X)
//h := int(r.H * r.T.S.Y)
i.DrawRectShader(1000, 1000, r.S, opts)
}