input

package
v0.3.26 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2021 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package input processes button presses from a gamepad or keyboard.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func PackButtons added in v0.2.81

func PackButtons(buttons ...Button) uint64

PackButtons combines the specified buttons into a bitmask. Order is not preserved, and any repeated buttons are only stored once.

Types

type Button added in v0.2.81

type Button uint8

Button represents a gamepad button.

const (
	BtnUp      Button = 0
	BtnDown    Button = 1
	BtnLeft    Button = 2
	BtnRight   Button = 3
	BtnConfirm Button = 4
	BtnCancel  Button = 5
	BtnSwitch  Button = 6
	BtnToggle  Button = 7
	BtnPause   Button = 8
	BtnHelp    Button = 9

	NumButtons = 10
)

Constants for Button.

func UnpackButtons added in v0.2.81

func UnpackButtons(mask uint64) []Button

UnpackButtons extracts the buttons from a given bitmask.

func (Button) String added in v0.2.81

func (i Button) String() string

type Context

type Context struct {

	// OnMouseImmediate is called when a mouse event occurs, which may be
	// helpful for APIs that require being called from an event.
	OnMouseImmediate func()
	// contains filtered or unexported fields
}

Context is an input context.

func GetContext

func GetContext(ctx context.Context) *Context

GetContext returns the Context created using NewContext.

It panics if no context was created.

func NewContext

func NewContext(ctx context.Context, gamepad func() []Button) (context.Context, *Context)

NewContext creates a new input context.

func (*Context) Consume

func (c *Context) Consume(btn Button) bool

Consume returns true if a button is pressed, and consumes the button press indefinitely.

func (*Context) ConsumeAllowRepeat

func (c *Context) ConsumeAllowRepeat(btn Button, defaultDelay, minDelay uint64) bool

ConsumeAllowRepeat returns true if a button is pressed, and consumes the button press for a number of ticks.

func (*Context) ConsumeClick added in v0.2.81

func (c *Context) ConsumeClick()

ConsumeClick sets the mouse drag distance to infinity.

This API may change in the future.

func (*Context) ConsumeKey added in v0.2.81

func (c *Context) ConsumeKey() (key.Event, bool)

ConsumeKey takes a key event from the queue.

This API may change in the future.

func (*Context) Held

func (c *Context) Held(btn Button) bool

Held returns true if a button is currently held.

func (*Context) IsMouseDrag added in v0.2.81

func (c *Context) IsMouseDrag() bool

IsMouseDrag returns true if the mouse has been dragged at least this many pixels.

This API may change in the future.

func (*Context) LastMouse added in v0.2.81

func (c *Context) LastMouse() (x, y float32, click bool)

LastMouse returns the mouse state for the previous tick.

This API may change in the future.

func (*Context) LoadState

func (c *Context) LoadState(s State)

LoadState loads the input state from a snapshot.

func (*Context) Mouse added in v0.2.75

func (c *Context) Mouse() (x, y float32, click bool)

Mouse returns the mouse position and pressed state.

This API may change in the future.

func (*Context) OnKey added in v0.2.81

func (c *Context) OnKey(e key.Event)

OnKey handles keyboard events.

func (*Context) OnMouse added in v0.2.81

func (c *Context) OnMouse(e mouse.Event)

OnMouse handles mouse events.

func (*Context) OnSize added in v0.2.81

func (c *Context) OnSize(e size.Event)

OnSize handles screen size events.

func (*Context) OnTouch added in v0.2.81

func (c *Context) OnTouch(e touch.Event)

OnTouch handles touchscreen events.

func (*Context) SaveState

func (c *Context) SaveState() State

SaveState takes a snapshot of the input state.

func (*Context) Tick

func (c *Context) Tick()

Tick updates the input context.

func (*Context) Wheel added in v0.3.1

func (c *Context) Wheel() float32

Wheel returns the mouse wheel delta for this tick.

This API may change in the future.

type State

type State struct {
	// contains filtered or unexported fields
}

State is a snapshot of the input context state.

Jump to

Keyboard shortcuts

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