holy shit components are rendering whaaaaaaaaaaaaaaaat
This commit is contained in:
57
common/elements/v1/blocks/block.go
Normal file
57
common/elements/v1/blocks/block.go
Normal file
@@ -0,0 +1,57 @@
|
||||
package blocks
|
||||
|
||||
import (
|
||||
"image/color"
|
||||
|
||||
"git.vezzani.net/ben/games/common/elements/v1"
|
||||
"git.vezzani.net/ben/games/common/elements/v1/mouse"
|
||||
"github.com/hajimehoshi/ebiten/v2"
|
||||
"github.com/hajimehoshi/ebiten/v2/vector"
|
||||
)
|
||||
|
||||
func New(ops ...Option) elements.ElementFunc {
|
||||
return func(d elements.Dimensions) elements.Element {
|
||||
b := Block{
|
||||
parentDimensions: d,
|
||||
}
|
||||
for i := range ops {
|
||||
ops[i](&b)
|
||||
}
|
||||
return &b
|
||||
}
|
||||
}
|
||||
|
||||
type Block struct {
|
||||
parentDimensions elements.Dimensions
|
||||
backgroundColor *color.Color
|
||||
mouse.NopHandler
|
||||
width float64
|
||||
height float64
|
||||
}
|
||||
|
||||
func (b *Block) Size() (w, h float64) {
|
||||
w, h = b.parentDimensions.WX, b.parentDimensions.WY
|
||||
if b.width != 0 {
|
||||
w = b.width
|
||||
}
|
||||
if b.height != 0 {
|
||||
h = b.height
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (b *Block) Draw(image *ebiten.Image, _, _ float64) (w, h float64) {
|
||||
w, h = b.Size()
|
||||
if b.backgroundColor != nil {
|
||||
vector.DrawFilledRect(
|
||||
image,
|
||||
float32(b.parentDimensions.ZX),
|
||||
float32(b.parentDimensions.ZY),
|
||||
float32(w),
|
||||
float32(h),
|
||||
*b.backgroundColor,
|
||||
true,
|
||||
)
|
||||
}
|
||||
return
|
||||
}
|
||||
Reference in New Issue
Block a user