mouse

package
v3.4.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 12, 2022 License: Apache-2.0 Imports: 5 Imported by: 1

Documentation

Overview

Package mouse handles the propagation of mouse events though clickable regions. It extends the functionality of the collision package.

Index

Constants

View Source
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.

View Source
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

View Source
const (
	Start = "MouseCollisionStart"
	Stop  = "MouseCollisionStop"
)

MouseCollisionStart/Stop: see collision Start/Stop, for mouse collision Payload: (*mouse.Event)

View Source
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

View Source
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)
)
View Source
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 Add

func Add(sps ...*collision.Space)

Add adds a set of spaces to the rtree

func Binding

func Binding(fn func(event.CID, *Event) int) func(event.CID, interface{}) int

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 Clear

func Clear()

Clear resets the default collision tree

func GetEventName

func GetEventName(d mouse.Direction, b mouse.Button) string

GetEventName returns a string event name given some mobile/mouse information

func HitLabel

func HitLabel(sp *collision.Space, labels ...collision.Label) *collision.Space

HitLabel acts like hits, but reutrns the first space within hits that matches one of the input labels

func Hits

func Hits(sp *collision.Space) []*collision.Space

Hits returns the set of spaces which are colliding with the passed in space.

func PhaseCollision

func PhaseCollision(s *collision.Space) error

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 Remove

func Remove(sps ...*collision.Space)

Remove removes a space from the rtree

func ShiftSpace

func ShiftSpace(x, y float64, s *collision.Space) error

ShiftSpace adds x and y to a space and updates its position in the collision rtree that should not be a package global

func UpdateSpace

func UpdateSpace(x, y, w, h float64, s *collision.Space) error

UpdateSpace resets a space's location to a given rtreego.Rect. This is not an operation on a space because a space can exist in multiple rtrees.

Types

type Button

type Button = mouse.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 NewEvent

func NewEvent(x, y float64, button Button, event string) Event

NewEvent creates an event.

func NewZeroEvent

func NewZeroEvent(x, y float64) Event

NewZeroEvent creates an event with no button or event name.

func (Event) ToSpace

func (e Event) ToSpace() *collision.Space

ToSpace converts a mouse event into a collision space

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL