event

package
v0.0.0-...-96c78b7 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2016 License: MIT Imports: 3 Imported by: 4

Documentation

Overview

Package event manages a single queue for all events, including input, window, and user-defined events.

Index

Constants

View Source
const MaxEventsInQueue = 256

MaxEventsInQueue is number of events the queue can hold before it starts dropping new events.

Variables

This section is empty.

Functions

func Clear

func Clear()

Clear removes all events form the queue.

func ClearType

func ClearType(t Type)

ClearType removes all events of the given type form the queue.

func ClearTypeList

func ClearTypeList(ts []Type)

ClearTypeList removes all events with the given types form the queue.

func Post

func Post(e Event) error

Post pushes the given event onto the queue. If the queue is already full then a non-nil error is returned.

Types

type Event

type Event struct {
	Type Type
	Data interface{}
}

Event has a type and arbitrary data. See the documentation for each Type for a description of what data will be returned.

func Get

func Get() []Event

Get returns all events and removes them from the queue.

func GetType

func GetType(t Type) []Event

GetType returns all events in the queue of the given type. Note that if you are mostly using this function (or GetTypeList) then the queue may eventually fill up with events you are not interested in.

func GetTypeList

func GetTypeList(ts []Type) []Event

GetTypeList returns all events in the queue that match one of the types given. Note that if you are mostly using this function (or GetType) then the queue may eventually fill up with events you are not interested in.

func Poll

func Poll() Event

Poll removes and returns the next event in the queue. If there are no events it returns an Event with type NoEvent.

type KeyData

type KeyData struct {
	Key key.Key
	Mod map[key.Key]bool
}

KeyData holds a key that is of interest to the event and also any modifier keys that were held down at the time of the event.

type MouseData

type MouseData struct {
	Pos    geo.Vec
	Button int
}

MouseData holds the position of the mouse relative to the uppert left corner of the display and the button of interest to the event.

type MouseMotionData

type MouseMotionData struct {
	Pos     geo.Vec
	Rel     geo.Vec
	Buttons map[int]bool
}

MouseMotionData holds the position of the mouse relative to the uppert left corner of the display, the position relative to it's previous position, and which buttons where held down.

type MouseWheelData

type MouseWheelData struct {
	Dx, Dy, Dz float64
}

MouseWheelData holds the delta x, y, and z for the mouse wheel.

type ResizeData

type ResizeData struct {
	W, H int
}

ResizeData holds the new width and height.

type Type

type Type int

Type is used to distinguish different kinds of events. Custom types may be defined and should start from UserEvent.

const (
	// NoEvent is used when an Event is expected to be returned but there is no Event available
	// to return. It has no data assiciated with it.
	NoEvent Type = iota
	// Quit signals the user closing/reloading the page. It has no data assiciated with it.
	Quit
	// KeyDown is when a key on the keyboard is pressed down. Its data will be of type KeyData.
	KeyDown
	// KeyUp is when a key on the keyboard is released. Its data will be of type KeyData.
	KeyUp
	// MouseMotion is when the mouse moves. Its data will be of type MouseMotionData.
	MouseMotion
	// MouseButtonDown is when a button on the mouse is pressed down. Its data will be of
	// type MouseData.
	MouseButtonDown
	// MouseButtonUp is when a button on the mouse is released. Its data will be of type MouseData.
	MouseButtonUp
	// MouseWheel is when the mouse wheel is moved.
	MouseWheel
	// WindowResize is when the window's dimensions change. Its data will be of type ResizeData.
	WindowResize
	// UserEvent is the base for user events. Users may define custom Types but they're value
	// shuold be at least equal to UserEvent. Their data is whatever the user defines it to be.
	UserEvent
)

Jump to

Keyboard shortcuts

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