35 lines
551 B
Go
35 lines
551 B
Go
package elements
|
|
|
|
import (
|
|
"context"
|
|
|
|
"git.vezzani.net/ben/games/common/control/v1"
|
|
|
|
"github.com/hajimehoshi/ebiten/v2"
|
|
)
|
|
|
|
type ClickEvent struct {
|
|
X, Y int
|
|
Button control.MouseButton
|
|
}
|
|
|
|
const (
|
|
ParentKey = "parent_element"
|
|
)
|
|
|
|
type Clickable interface {
|
|
HandleClick(ctx context.Context, click *ClickEvent) error
|
|
}
|
|
|
|
type Element interface {
|
|
Draw(ctx context.Context, image *ebiten.Image) error
|
|
Size() (w, h int32)
|
|
}
|
|
|
|
func GetParent(ctx context.Context) Element {
|
|
if e, ok := ctx.Value(ParentKey).(Element); ok {
|
|
return e
|
|
}
|
|
return nil
|
|
}
|