2023-05-04 19:31:33 +03:00
|
|
|
package gx
|
|
|
|
|
2023-05-22 23:39:01 +03:00
|
|
|
import (
|
|
|
|
"github.com/hajimehoshi/ebiten/v2"
|
|
|
|
//"github.com/hajimehoshi/ebiten/v2/vector"
|
2023-05-23 16:19:55 +03:00
|
|
|
//"fmt"
|
2023-05-22 23:39:01 +03:00
|
|
|
//"image"
|
|
|
|
)
|
|
|
|
|
2023-05-04 19:31:33 +03:00
|
|
|
// 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
|
2023-05-04 19:31:33 +03:00
|
|
|
// 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.
|
2023-05-04 19:31:33 +03:00
|
|
|
W, H Float
|
2023-05-23 16:19:55 +03:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// The type describes rectangle that can be drawn.
|
|
|
|
type DrawableRectangle struct {
|
|
|
|
Rectangle
|
|
|
|
Shader *Shader
|
|
|
|
Color Color
|
|
|
|
Visible bool
|
2023-05-22 23:39:01 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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-04 19:31:33 +03:00
|
|
|
}
|
|
|
|
|
2023-05-23 16:19:55 +03:00
|
|
|
func (r DrawableRectangle) IsVisible() bool {
|
|
|
|
return r.Visible
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r DrawableRectangle) Draw(
|
2023-05-22 23:39:01 +03:00
|
|
|
e *Engine,
|
|
|
|
i *Image,
|
|
|
|
) {
|
2023-05-23 16:25:21 +03:00
|
|
|
t := r.T
|
|
|
|
t.S.X *= r.W
|
|
|
|
t.S.Y *= r.H
|
|
|
|
|
|
|
|
rm := e.Camera().RealMatrix(e, true)
|
|
|
|
m := t.Matrix(e)
|
|
|
|
m.Concat(rm)
|
2023-05-23 16:19:55 +03:00
|
|
|
// Draw solid color if no shader.
|
|
|
|
if r.Shader == nil {
|
2023-05-22 23:39:01 +03:00
|
|
|
img := NewImage(1, 1)
|
2023-05-23 16:19:55 +03:00
|
|
|
img.Set(0, 0, r.Color)
|
2023-05-22 23:39:01 +03:00
|
|
|
|
|
|
|
opts := &ebiten.DrawImageOptions{
|
|
|
|
GeoM: m,
|
|
|
|
}
|
|
|
|
i.DrawImage(img, opts)
|
|
|
|
return
|
|
|
|
}
|
2023-05-23 16:19:55 +03:00
|
|
|
|
2023-05-23 22:42:35 +03:00
|
|
|
v := 1
|
2023-05-22 23:39:01 +03:00
|
|
|
opts := &ebiten.DrawRectShaderOptions{
|
2023-05-23 16:25:21 +03:00
|
|
|
GeoM: m,
|
2023-05-22 23:39:01 +03:00
|
|
|
Images: [4]*Image{
|
2023-05-23 22:42:35 +03:00
|
|
|
NewImage(v, v),
|
2023-05-22 23:39:01 +03:00
|
|
|
nil,
|
|
|
|
nil,
|
|
|
|
nil,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
//w := int(r.W * r.T.S.X)
|
|
|
|
//h := int(r.H * r.T.S.Y)
|
|
|
|
|
2023-05-23 22:42:35 +03:00
|
|
|
i.DrawRectShader(v, v, r.Shader, opts)
|
2023-05-04 19:31:33 +03:00
|
|
|
}
|
|
|
|
|