69 lines
1.3 KiB
Go
69 lines
1.3 KiB
Go
package elements
|
|
|
|
import (
|
|
"github.com/hajimehoshi/ebiten/v2"
|
|
)
|
|
|
|
type ElementFunc func(Dimensions) Element
|
|
|
|
type MouseState struct {
|
|
X, Y int32
|
|
LeftDown, RightDown bool
|
|
LeftChanged, RightChanged bool
|
|
}
|
|
|
|
type Clickable interface {
|
|
HandleClick(s MouseState) error
|
|
}
|
|
|
|
type Mouseable interface {
|
|
HandleMouseEnter(s MouseState) error
|
|
HandleMouseLeave(s MouseState) error
|
|
HandleMouseMove(s MouseState) error
|
|
HandleMouseDown(s MouseState) error
|
|
HandleMouseUp(s MouseState) error
|
|
}
|
|
|
|
type Element interface {
|
|
Draw(image *ebiten.Image, anchorX, anchorY float64) (w, h float64)
|
|
}
|
|
|
|
type Dimensions struct {
|
|
zx, zy float64
|
|
wx, wy float64
|
|
}
|
|
|
|
type mouseHandler struct {
|
|
mouseState MouseState
|
|
prevMouseState MouseState
|
|
}
|
|
|
|
func (b *mouseHandler) HandleMouseEnter(s MouseState) error {
|
|
b.mouseState = s
|
|
return nil
|
|
}
|
|
|
|
func (b *mouseHandler) HandleMouseLeave(s MouseState) error {
|
|
b.prevMouseState = b.mouseState
|
|
b.mouseState = MouseState{}
|
|
return nil
|
|
}
|
|
|
|
func (b *mouseHandler) HandleMouseMove(s MouseState) error {
|
|
b.prevMouseState = b.mouseState
|
|
b.mouseState = s
|
|
return nil
|
|
}
|
|
|
|
func (b *mouseHandler) HandleMouseDown(s MouseState) error {
|
|
b.prevMouseState = b.mouseState
|
|
b.mouseState = s
|
|
return nil
|
|
}
|
|
|
|
func (b *mouseHandler) HandleMouseUp(s MouseState) error {
|
|
b.prevMouseState = b.mouseState
|
|
b.mouseState = s
|
|
return nil
|
|
}
|