mouse

package
v2.0.0+incompatible Latest Latest
Warning

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

Go to latest
Published: Feb 7, 2018 License: Apache-2.0 Imports: 8 Imported by: 0

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 (
	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 (
	DefTree *collision.Tree
)

There's a default collision tree you can access via collision.func as opposed to tree.func

View Source
var (
	//TrackMouseClicks enables the propagation of MouseClickOn during MouseRelease events
	TrackMouseClicks = true
)

Functions

func Add

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

Add adds a set of spaces to the rtree

func Clear

func Clear()

Clear resets the default collision tree

func GetEventName added in v1.4.0

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

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

func GetMouseButton

func GetMouseButton(b mouse.Button) (s string)

GetMouseButton is a utitilty function which translates integer values of mouse keys from golang's event/mouse library into strings. Intended for internal use.

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 Propagate

func Propagate(eventName string, me Event)

Propagate triggers direct mouse events on entities which are clicked

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 CollisionPhase

type CollisionPhase struct {
	OnCollisionS *collision.Space
	// 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 string
	Event  string
}

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, event string) Event

NewEvent creates and returns an Event

func NewZeroEvent

func NewZeroEvent(x, y float64) Event

NewZeroEvent creates an event with no button or event string.

func (Event) ToSpace

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

ToSpace converts a mouse event into a collision space

type GestureEvent

type GestureEvent struct {
	Drag        bool
	LongPress   bool
	DoublePress bool

	InitialPos physics.Vector
	CurrentPos physics.Vector

	Time time.Time
}

A GestureEvent is a conversion of a shiny Gesture to our local type so we don't need to import shiny variables in more places. GestureEvents contain information about mouse events that are not single actions, like drags, holds, and double clicks. Todo: standardize events to also use vectors for their position

func FromShinyGesture

func FromShinyGesture(shinyGesture gesture.Event) GestureEvent

FromShinyGesture converts a shiny gesture.Event to a GestureEvent

Jump to

Keyboard shortcuts

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