input

package
v0.0.0-...-d322e89 Latest Latest
Warning

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

Go to latest
Published: Oct 14, 2018 License: BSD-2-Clause Imports: 6 Imported by: 0

Documentation

Overview

Package input provides a flexible way to handle player inputs

Work in Progress

The package is not feature-complete, but is advanced enough to handle most common cases.

Index

Constants

View Source
const (
	Select = ButtonID(iota)
	Close
	Up
	Down
	Left
	Right
	Click

	Pointer = CursorID(0)
)

Default actions with automatic bindings. If a context contain one of these, but no bindings is found, default bindings will be added. If there is no declared context, a default context will be created and include all these actions.

Variables

This section is empty.

Functions

func Err

func Err() error

Err returns the first unchecked error of the package since last call to the function. The error is then considered checked, and further calls to Err will return nil until the next error occurs.

Note: errors occuring while there already is an unchecked error will not be recorded. However, if the debug mode is active, all errors will be logged.

func GrabMouse

func GrabMouse(grab bool)

GrabMouse puts the mouse in relative mode: the cursor is hidden and cannot leave the game window, but the mouse movements (delta) are continuously reported, without constraints.

func MouseGrabbed

func MouseGrabbed() bool

MouseGrabbed returns true if the relative mode is enabled.

func ShowMouse

func ShowMouse(show bool)

ShowMouse shows or hides the (system) mouse cursor.

Types

type Action

type Action interface {
	// contains filtered or unexported methods
}

An Action represents something the player can do in the game. Actions can be bound to hardware input (by the player). During the game loop, actions can be queried and reacted upon.

type AxisID

type AxisID uint32

AxisID identifies an absolute, one-dimensional analog action with a resting position and two directions, i.e. any action that is best represented by one floating-point value between -1 and +1.

func Axis

func Axis(name string) AxisID

Axis declares a new bipolar action, and returns its ID.

func (AxisID) Name

func (a AxisID) Name() string

Name of the action.

func (AxisID) Value

func (a AxisID) Value() float32

Value returns the current value of the action on the current device. This value is normalized between -1 and +1.

func (AxisID) ValueOn

func (a AxisID) ValueOn(d DeviceID) float32

ValueOn returns the current value of the action on a specific device. This value is normalized between -1 and +1.

type Bindings

type Bindings map[string]map[string][]string

Bindings is a list of bindings for each context/action combination. The first map level associates each context name to a sub-map; this sub map then associates each action name to a slice of strings (the actual bindings).

type ButtonID

type ButtonID uint32

ButtonID identifies a digital Action, i.e. an action that can be either "on" or "off".

In this package, the state of being "on" is called "pressed". The transition from "off" to "on" is called "pushed"; and the transition back to "off" is called "released".

func Button

func Button(name string) ButtonID

Button declares a new digital action, and returns its ID.

func (ButtonID) Changed

func (a ButtonID) Changed() bool

Changed returns true if the action has just been pressed or released this very frame (i.e. just been started or stopped by the player).

Note: this *must* be queried in the React method of the game loop, as this is the only method that is guaranteed to run at least once each frame.

func (ButtonID) ChangedOn

func (a ButtonID) ChangedOn(d DeviceID) bool

ChangedOn returns true if the action has just been pressed or released this very frame (i.e. just been started or stopped by the player).

Note: this *must* be queried in the React method of the game loop, as this is the only method that is guaranteed to run at least once each frame.

func (ButtonID) Name

func (a ButtonID) Name() string

Name of the button action.

func (ButtonID) Ongoing

func (a ButtonID) Ongoing() bool

Ongoing returns true if the action has been started and is currently ongoing on the current device (i.e. it has been pressed but not released).

func (ButtonID) OngoingOn

func (a ButtonID) OngoingOn(d DeviceID) bool

OngoingOn returns true if the action has been started and is currently ongoing on a specific device (i.e. it has been pressed but not released).

func (ButtonID) Pressed

func (a ButtonID) Pressed() bool

Pressed returns true if the action has just been started this very frame (i.e. just been pressed by the player).

Note: this *must* be queried in the React method of the game loop, as this is the only method that is guaranteed to run at least once each frame.

func (ButtonID) PressedOn

func (a ButtonID) PressedOn(d DeviceID) bool

PressedOn returns true if the action has just been started this very frame (i.e. just been pressed by the player).

Note: this *must* be queried in the React method of the game loop, as this is the only method that is guaranteed to run at least once each frame.

func (ButtonID) Released

func (a ButtonID) Released() bool

Released returns true if the action has just been stopped this very frame (i.e. just been released by the player).

Note: this *must* be queried in the React method of the game loop, as this is the only method that is guaranteed to run at least once each frame.

func (ButtonID) ReleasedOn

func (a ButtonID) ReleasedOn(d DeviceID) bool

ReleasedOn returns true if the action has just been stopped this very frame (i.e. just been released by the player).

Note: this *must* be queried in the React method of the game loop, as this is the only method that is guaranteed to run at least once each frame.

type ContextID

type ContextID uint32

ContextID identifies an input context, i.e. a set of actions that can be active at the same time. The same action can be listed in several contexts, and have different (or identical) bindings in each.

func Context

func Context(name string, list ...Action) ContextID

Context declares a new input context. Its name should be unique.

func (ContextID) Activate

func (a ContextID) Activate()

Activate makes the context active on all devices.

func (ContextID) ActivateOn

func (a ContextID) ActivateOn(d DeviceID)

ActivateOn makes the context active on a specific device.

func (ContextID) Active

func (a ContextID) Active() bool

Active returns true if the context is currently active for the current device.

func (ContextID) ActiveOn

func (a ContextID) ActiveOn(d DeviceID) bool

ActiveOn returns true if the context is currently active on a specific device.

type CursorID

type CursorID uint32

CursorID identifes an absolute two-dimensional analog input, i.e. any action that is best represented by a pair of X and Y coordinates, and whose most important characteristic is the position in the game window.

func Cursor

func Cursor(name string) CursorID

Cursor declares a new cursor action, and returns its ID.

func (CursorID) Name

func (a CursorID) Name() string

Name of the action.

func (CursorID) XY

func (a CursorID) XY() window.XY

XY returns the current status of the action on the current device. The cursorinates are the current absolute position; the values of X and Y are normalized between -1 and 1.

func (CursorID) XYon

func (a CursorID) XYon(d DeviceID) window.XY

XYon returns the current status of the action on a specific device. The cursorinates are the current absolute position; the values of X and Y are normalized between -1 and 1.

type DeltaID

type DeltaID uint32

DeltaID identifes a relative two-dimensional analog input, i.e. any action that is best represented by a pair of X and Y coordinates, and whose most important characteristic is the change in position.

func Delta

func Delta(name string) DeltaID

Delta declares a new delta action, and returns its ID.

func (DeltaID) Name

func (a DeltaID) Name() string

Name of the action.

func (DeltaID) XY

func (a DeltaID) XY() coord.XY

XY returns the current status of the action on the current device. The coordinates correspond to the change in position since the last frame.

func (DeltaID) XYon

func (a DeltaID) XYon(d DeviceID) coord.XY

XYon returns the current status of the action on a specific device. The coordinates correspond to the change in position since the last frame.

type DeviceID

type DeviceID uint32

DeviceID identifies an input device, i.e. any kind of hardware that can be bound to a game action.

Note: for convenience, the mouse and keyboard are considered to be the same device, and share the same ID.

const (
	// KeyboardAndMouse is the only device that doesn't need to be declared
	KeyboardAndMouse DeviceID = 0
)

func CurrentDevice

func CurrentDevice() DeviceID

CurrentDevice returns the device most recently used

func (DeviceID) Name

func (a DeviceID) Name() string

Name returns the name of the device

type DualAxisID

type DualAxisID uint32

DualAxisID identifies an absolute two-dimensional analog action, i.e. any action that is best represented by a pair of X and Y coordinates, and whose most important characteristic is the current position. The values of the coordinates are normalized between -1 and 1.

func DualAxis

func DualAxis(name string) DualAxisID

DualAxis declares a new two-dimensional analog action, and returns its ID.

func (DualAxisID) Name

func (a DualAxisID) Name() string

Name of the action.

func (DualAxisID) XY

func (a DualAxisID) XY() coord.XY

XY returns the current status of the action on the current device. The coordinates are the current absolute position; the values of X and Y are normalized between -1 and 1.

func (DualAxisID) XYon

func (a DualAxisID) XYon(d DeviceID) coord.XY

XYon returns the current status of the action on a specific device. The coordinates are the current absolute position; the values of X and Y are normalized between -1 and 1.

type HalfAxisID

type HalfAxisID uint32

HalfAxisID identifies an absolute, one-dimensional analog action with a resting position and one signle direction, i.e. any action that is best represented by one floating-point value between 0 and 1.

func HalfAxis

func HalfAxis(name string) HalfAxisID

HalfAxis declares a new unipolar analog action, and returns its ID.

func (HalfAxisID) Name

func (a HalfAxisID) Name() string

Name of the action.

func (HalfAxisID) Value

func (a HalfAxisID) Value() float32

Value returns the current value of the action on the current device. This value is normalized between 0 and 1.

func (HalfAxisID) ValueOn

func (a HalfAxisID) ValueOn(d DeviceID) float32

ValueOn returns the current value of the action on a specific device. This value is normalized between 0 and 1.

Jump to

Keyboard shortcuts

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