holy shit components are rendering whaaaaaaaaaaaaaaaat
This commit was merged in pull request #4.
This commit is contained in:
64
common/elements/v1/mouse/mouse.go
Normal file
64
common/elements/v1/mouse/mouse.go
Normal file
@@ -0,0 +1,64 @@
|
||||
package mouse
|
||||
|
||||
import (
|
||||
"github.com/hajimehoshi/ebiten/v2"
|
||||
"github.com/hajimehoshi/ebiten/v2/inpututil"
|
||||
)
|
||||
|
||||
type NopHandler struct{}
|
||||
|
||||
func (n NopHandler) HandleMouseEvent(s State) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
type State struct {
|
||||
X, Y int
|
||||
LeftDown, RightDown bool
|
||||
LeftChanged, RightChanged bool
|
||||
LeftClicked, RightClicked bool
|
||||
Clicked bool
|
||||
}
|
||||
|
||||
//func ClickHandler(e elements.Element) func() bool {
|
||||
// newState := StateBuilder()
|
||||
// return func() bool {
|
||||
// _ = newState()
|
||||
// if
|
||||
// }
|
||||
//}
|
||||
|
||||
func StateBuilder() func() State {
|
||||
prevState := State{}
|
||||
state := State{}
|
||||
return func() State {
|
||||
state = prevState
|
||||
state.X, state.Y = ebiten.CursorPosition()
|
||||
|
||||
if inpututil.IsMouseButtonJustPressed(ebiten.MouseButtonLeft) {
|
||||
state.LeftDown = true
|
||||
}
|
||||
if inpututil.IsMouseButtonJustPressed(ebiten.MouseButtonRight) {
|
||||
state.RightDown = true
|
||||
}
|
||||
if inpututil.IsMouseButtonJustReleased(ebiten.MouseButtonLeft) {
|
||||
state.LeftDown = false
|
||||
if !state.RightDown {
|
||||
state.Clicked = true
|
||||
}
|
||||
}
|
||||
if inpututil.IsMouseButtonJustReleased(ebiten.MouseButtonRight) {
|
||||
state.RightDown = false
|
||||
if !state.LeftDown {
|
||||
state.Clicked = true
|
||||
}
|
||||
}
|
||||
|
||||
state.Clicked = state.Clicked && !prevState.Clicked
|
||||
|
||||
state.LeftChanged = state.LeftDown != prevState.LeftDown
|
||||
state.RightChanged = state.RightDown != prevState.RightDown
|
||||
|
||||
prevState = state
|
||||
return state
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user