event

package
v0.0.0-...-a8da853 Latest Latest
Warning

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

Go to latest
Published: Feb 12, 2024 License: MIT Imports: 1 Imported by: 12

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type GameController

type GameController interface {
	ID() int      // Usually the controller index number
	Name() string // Friendly name of the controller

	// State setters, to be called by the engine.
	// Note: button names are implementation-specific, use Button*() methods in your code.
	SetButtonState(name string, pressed bool)
	GetButtonState(name string) bool
	SetAxisState(name string, value int) // value maybe -32768 to 32767

	// State getters.
	ButtonA() bool
	ButtonB() bool
	ButtonX() bool
	ButtonY() bool
	ButtonL1() bool // Left shoulder
	ButtonR1() bool // Right shoulder
	ButtonL2() bool // Left trigger (digital)
	ButtonR2() bool // Right trigger (digital)
	ButtonLStick() bool
	ButtonRStick() bool
	ButtonStart() bool
	ButtonSelect() bool // Back button
	ButtonHome() bool   // Guide button

	// D-Pad buttons.
	ButtonUp() bool
	ButtonLeft() bool
	ButtonRight() bool
	ButtonDown() bool

	// Axis getters. Returns Vectors ranging from -1.0 to 1.0 being a
	// percentage of the axis between neutral and maxed out.
	LeftStick() Vector
	RightStick() Vector
	LeftTrigger() float64
	RightTrigger() float64
}

GameController holds event state for one or more (Xbox-style) controllers.

type State

type State struct {
	// Mouse buttons.
	Button1 bool // Left
	Button2 bool // Middle
	Button3 bool // Right

	// Special keys
	Escape bool
	Space  bool
	Enter  bool
	Shift  bool
	Ctrl   bool
	Alt    bool
	Up     bool
	Left   bool
	Right  bool
	Down   bool

	// Cursor position
	CursorX int
	CursorY int

	// Window resized
	WindowResized bool

	// Touch state
	Touching        bool
	TouchNumFingers int
	TouchCenterX    int
	TouchCenterY    int
	GestureRotated  float64
	GesturePinched  float64

	// Game controller events.
	// NOTE: for SDL2 you will need to call GameControllerEventState(1)
	// from veandco/go-sdl2/sdl for events to be read by SDL2.
	Controllers map[int]GameController
	// contains filtered or unexported fields
}

State holds the current state of key/mouse events.

func NewState

func NewState() *State

NewState creates a new event.State.

func (*State) AddController

func (s *State) AddController(index int, v GameController) bool

AddController adds a new controller to the event state. This is typically called automatically by the render engine, e.g. on an SDL ControllerDeviceEvent.

func (*State) GetController

func (s *State) GetController(index int) (GameController, bool)

GetController gets a registered controller by index.

func (*State) KeyDown

func (s *State) KeyDown(name string) bool

KeyDown returns whether a named key is currently pressed.

func (*State) KeysDown

func (s *State) KeysDown(shifted bool) []string

KeysDown returns a list of all key names currently pressed down. Set shifted to True to return the key symbols correctly shifted (uppercase, or symbols on number keys, etc.)

func (*State) RemoveController

func (s *State) RemoveController(index int) bool

RemoveController removes the available controller.

func (*State) ResetKeyDown

func (s *State) ResetKeyDown()

ResetKeyDown clears all key-down states.

func (*State) SetKeyDown

func (s *State) SetKeyDown(name string, down bool)

SetKeyDown sets that a named key is pressed down.

type Vector

type Vector struct {
	X float64
	Y float64
}

Vector holds a floating point vector along an X and Y axis.

Jump to

Keyboard shortcuts

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