Documentation
¶
Overview ¶
Package mouse handles the propagation of mouse events though clickable regions. It extends the functionality of the collision package.
Index ¶
- Constants
- Variables
- func Add(sps ...*collision.Space)
- func Binding(fn func(event.CID, *Event) int) func(event.CID, interface{}) int
- func Clear()
- func GetEventName(d mouse.Direction, b mouse.Button) string
- func HitLabel(sp *collision.Space, labels ...collision.Label) *collision.Space
- func Hits(sp *collision.Space) []*collision.Space
- func PhaseCollision(s *collision.Space) error
- func Remove(sps ...*collision.Space)
- func ShiftSpace(x, y float64, s *collision.Space) error
- func UpdateSpace(x, y, w, h float64, s *collision.Space) error
- type Button
- type CollisionPhase
- type Event
Constants ¶
const ( MinZLayer = 0 MaxZLayer = 1000 )
Min and Max Z layer inform what range of z layer values will be checked on mouse collision interactions. Mouse events will not propagate to elements with z layers outside of this range.
const ( ButtonLeft = mouse.ButtonLeft ButtonMiddle = mouse.ButtonMiddle ButtonRight = mouse.ButtonRight ButtonWheelDown = mouse.ButtonWheelDown ButtonWheelUp = mouse.ButtonWheelUp ButtonWheelLeft = mouse.ButtonWheelLeft ButtonWheelRight = mouse.ButtonWheelRight ButtonNone = mouse.ButtonNone )
Valid Button event types
const ( Start = "MouseCollisionStart" Stop = "MouseCollisionStop" )
MouseCollisionStart/Stop: see collision Start/Stop, for mouse collision Payload: (*mouse.Event)
const ( Press = "MousePress" Release = "MouseRelease" ScrollDown = "MouseScrollDown" ScrollUp = "MouseScrollUp" Click = "MouseClick" Drag = "MouseDrag" // PressOn = Press + "On" ReleaseOn = Release + "On" ScrollDownOn = ScrollDown + "On" ScrollUpOn = ScrollUp + "On" ClickOn = Click + "On" DragOn = Drag + "On" )
Mouse events: MousePress, MouseRelease, MouseScrollDown, MouseScrollUp, MouseDrag Payload: (*mouse.Event) details of the mouse event
Variables ¶
var ( // LastEvent is the last triggered mouse event, // tracked for continuous mouse responsiveness on events // that don't take in a mouse event LastEvent = NewZeroEvent(0, 0) // LastPress is the last triggered mouse event, // where the mouse event was a press. // If TrackMouseClicks is set to false then this will not be tracked LastPress = NewZeroEvent(0, 0) )
var (
DefaultTree = collision.NewTree()
)
DefaultTree is a collision tree intended to be used by default if no other is instantiated. Methods on a collision tree are duplicated as functions in this package, so `tree.Add(...)` can instead be `mouse.Add(...)` if the codebase is coordinated to just use the default tree.
Functions ¶
func Binding ¶
Binding will convert a function that accepts a typecast *mouse.Event into a generic event binding
Example:
bus.Bind(mouse.ClickOn, mouse.Binding(clickHandler))
func GetEventName ¶
GetEventName returns a string event name given some mobile/mouse information
func HitLabel ¶
HitLabel acts like hits, but reutrns the first space within hits that matches one of the input labels
func PhaseCollision ¶
PhaseCollision binds to the entity behind the space's CID so that it will receive MouseCollisionStart and MouseCollisionStop events, appropriately when the mouse begins to hover or stops hovering over the input space.
func ShiftSpace ¶
ShiftSpace adds x and y to a space and updates its position in the collision rtree that should not be a package global
Types ¶
type Button ¶
Button represents a mouse interaction type, like a left button or mouse wheel movement.
type CollisionPhase ¶
type CollisionPhase struct { OnCollisionS *collision.Space LastEvent *Event // contains filtered or unexported fields }
CollisionPhase is a component that can be placed into another struct to enable PhaseCollision on the struct. See PhaseCollision.
type Event ¶
type Event struct { floatgeom.Point2 Button Event string // Set StopPropagation on a mouse event to prevent it from triggering on // lower layers of mouse collision spaces while in flight StopPropagation bool }
An Event is passed in through all Mouse related event bindings to indicate what type of mouse event was triggered, where it was triggered, and which mouse button it concerns.
func NewZeroEvent ¶
NewZeroEvent creates an event with no button or event name.