43 lines
786 B
Go
43 lines
786 B
Go
package elements
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/hajimehoshi/ebiten/v2"
|
|
)
|
|
|
|
type MouseState struct {
|
|
X, Y int32
|
|
LeftDown, RightDown bool
|
|
}
|
|
|
|
const (
|
|
ParentKey = "parent_element"
|
|
ZeroKey = "zero"
|
|
)
|
|
|
|
type Mouseable interface {
|
|
HandleMouseMove(ctx context.Context, s MouseState) error
|
|
HandleMouseDown(ctx context.Context, s MouseState) error
|
|
HandleMouseUp(ctx context.Context, s MouseState) error
|
|
}
|
|
|
|
type Element interface {
|
|
Draw(ctx context.Context, image *ebiten.Image) error
|
|
Size() (w, h int32)
|
|
}
|
|
|
|
func GetZero(ctx context.Context) (x, y int32) {
|
|
if v, ok := ctx.Value(ZeroKey).([2]int32); ok {
|
|
return v[0], v[1]
|
|
}
|
|
return 0, 0
|
|
}
|
|
|
|
func GetParent(ctx context.Context) Element {
|
|
if e, ok := ctx.Value(ParentKey).(Element); ok {
|
|
return e
|
|
}
|
|
return nil
|
|
}
|