Documentation
¶
Overview ¶
Package input defines backend-neutral input snapshots and events consumed by game. It should not know about Ragnarok gameplay, rendering, or network packets.
Index ¶
- func AndroidGamepadDevice(id int, name string, connected bool)
- func AndroidGamepadKey(id, key int, down bool)
- func AndroidGamepadMotion(id int, axes [GamepadAxisCount]float64, hatX, hatY float64)
- func AndroidKey(code int) gpucontext.Key
- func AndroidResetGamepads()
- func KeyCodeName(code KeyCode) string
- type GamepadAxis
- type GamepadButton
- type GamepadButtonChange
- type GamepadCapture
- type GamepadFrame
- type GamepadSource
- type Key
- type KeyCode
- type MouseButton
- type State
- func (s *State) AddTextInput(text string)
- func (s *State) AddWheel(x, y float64)
- func (s *State) ConsumeKeyCodePress(code KeyCode) bool
- func (s *State) EndFrame()
- func (s *State) FrameID() uint64
- func (s *State) GamepadChanges() []GamepadButtonChange
- func (s *State) GamepadConnected() bool
- func (s *State) GamepadDown(button GamepadButton) bool
- func (s *State) GamepadJustPressed(button GamepadButton) bool
- func (s *State) GamepadJustReleased(button GamepadButton) bool
- func (s *State) GamepadName() string
- func (s *State) GamepadValue(axis GamepadAxis) float64
- func (s *State) JustPressed(key Key) bool
- func (s *State) KeyCodeConsumed(code KeyCode) bool
- func (s *State) KeyCodeDown(code KeyCode) bool
- func (s *State) KeyCodeJustPressed(code KeyCode) bool
- func (s *State) KeyCodeJustReleased(code KeyCode) bool
- func (s *State) MouseJustPressed(button MouseButton) bool
- func (s *State) MouseJustReleased(button MouseButton) bool
- func (s *State) MousePressed(button MouseButton) bool
- func (s *State) Pressed(key Key) bool
- func (s *State) ResetGamepad()
- func (s *State) ResetKeyboard()
- func (s *State) ResetMouseButtons()
- func (s *State) SetGamepad(next GamepadFrame)
- func (s *State) SetKey(key Key, pressed bool)
- func (s *State) SetKeyCode(code KeyCode, pressed bool)
- func (s *State) SetMouseButton(button MouseButton, pressed bool)
- func (s *State) SetMousePosition(x, y int)
- func (s *State) SetTouch(id TouchID, x, y int, pressed bool)
- func (s *State) TextInput() string
- func (s *State) Update()
- type TouchID
- type TouchPoint
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AndroidGamepadDevice ¶ added in v0.16.0
func AndroidGamepadKey ¶ added in v0.16.0
func AndroidGamepadMotion ¶ added in v0.16.0
func AndroidGamepadMotion(id int, axes [GamepadAxisCount]float64, hatX, hatY float64)
func AndroidKey ¶ added in v0.16.0
func AndroidKey(code int) gpucontext.Key
AndroidKey translates Android KeyEvent keycodes to the shared input model.
func AndroidResetGamepads ¶ added in v0.16.0
func AndroidResetGamepads()
func KeyCodeName ¶ added in v0.13.0
KeyCodeName is the layout-independent name used by keyboard callbacks.
Types ¶
type GamepadAxis ¶ added in v0.16.0
type GamepadAxis uint8
const ( GamepadLeftX GamepadAxis = iota GamepadLeftY GamepadRightX GamepadRightY GamepadLeftTrigger GamepadRightTrigger GamepadAxisCount )
func GamepadAxisFromName ¶ added in v0.16.0
func GamepadAxisFromName(name string) (GamepadAxis, bool)
type GamepadButton ¶ added in v0.16.0
type GamepadButton uint8
GamepadButton names describe positions, independent of the printed labels.
const ( GamepadSouth GamepadButton = iota GamepadEast GamepadWest GamepadNorth GamepadLeftShoulder GamepadRightShoulder GamepadBack GamepadStart GamepadLeftStick GamepadRightStick GamepadUp GamepadDown GamepadLeft GamepadRight GamepadButtonCount )
func AndroidGamepadButton ¶ added in v0.16.0
func AndroidGamepadButton(key int) (GamepadButton, bool)
AndroidGamepadButton maps Android KeyEvent constants to positional controls.
func GamepadButtonFromName ¶ added in v0.16.0
func GamepadButtonFromName(name string) (GamepadButton, bool)
type GamepadButtonChange ¶ added in v0.16.0
type GamepadButtonChange struct {
Button GamepadButton
Down bool
}
type GamepadCapture ¶ added in v0.16.0
type GamepadCapture struct {
Buttons [GamepadButtonCount]bool
Pointer bool
}
GamepadCapture lets gameplay claim controls before the pointer fallback. It applies to one frame; button captures last until release in the renderer.
type GamepadFrame ¶ added in v0.16.0
type GamepadFrame struct {
ID string
Name string
Buttons [GamepadButtonCount]bool
Axes [GamepadAxisCount]float64
// Changes belongs to the receiver; draining again cannot replay or mutate it.
Changes []GamepadButtonChange
}
GamepadFrame transfers the latest normalized controller state and the ordered button transitions collected since the previous drain. Empty ID means disconnected. Sticks use [-1,1], with negative Y pointing up; triggers use [0,1].
type GamepadSource ¶ added in v0.16.0
type GamepadSource struct {
// contains filtered or unexported fields
}
GamepadSource keeps the first controller selected until it disconnects. It has one consumer: the window loop. Create, drain and close on that thread (required by macOS). Other consumers read the shared State after SetGamepad.
func NewGamepadSource ¶ added in v0.16.0
func NewGamepadSource() (*GamepadSource, error)
func (*GamepadSource) Close ¶ added in v0.16.0
func (s *GamepadSource) Close()
func (*GamepadSource) DiscardPending ¶ added in v0.16.0
func (s *GamepadSource) DiscardPending()
DiscardPending drops queued actions at a focus boundary, even if updates were suspended while unfocused. The next drain still reports current held state.
func (*GamepadSource) DrainFrame ¶ added in v0.16.0
func (s *GamepadSource) DrainFrame() GamepadFrame
DrainFrame consumes queued changes for all controllers and returns the selected controller's frame. Call once per update, then pass it to State.SetGamepad. Diagnostics and other readers must query State instead of draining the source.
type KeyCode ¶ added in v0.7.0
type KeyCode = gpucontext.Key
KeyCode identifies a physical keyboard position. Its names follow the browser KeyboardEvent.code convention (KeyW, Digit1, ArrowUp, and so on).
func KeyCodeFromName ¶ added in v0.7.0
KeyCodeFromName resolves a layout-independent physical key name. Names use the same vocabulary as browser KeyboardEvent.code so scripts remain clear across QWERTY, AZERTY, and other layouts.
type MouseButton ¶
type MouseButton int
const ( MouseButtonLeft MouseButton = iota MouseButtonRight )
type State ¶
type State struct {
MouseX int
MouseY int
MouseDX int
MouseDY int
WheelX float64
WheelY float64
TouchPoints []TouchPoint
PinchDelta float64
// contains filtered or unexported fields
}
func (*State) AddTextInput ¶
func (*State) ConsumeKeyCodePress ¶ added in v0.7.0
ConsumeKeyCodePress reports a new physical key press once and prevents other consumers from acting on the same edge. Consumption lasts until release so native dispatch can also suppress repeats and associated text. Held state and text already collected in the snapshot are left unchanged.
func (*State) FrameID ¶ added in v0.13.0
FrameID identifies the current batch of input events. UI opened by an event can use it to avoid handling that same event again during the frame update.
func (*State) GamepadChanges ¶ added in v0.16.0
func (s *State) GamepadChanges() []GamepadButtonChange
GamepadChanges reads this frame's transitions without consuming them. The returned slice is read-only and valid until EndFrame or ResetGamepad.
func (*State) GamepadConnected ¶ added in v0.16.0
func (*State) GamepadDown ¶ added in v0.16.0
func (s *State) GamepadDown(button GamepadButton) bool
func (*State) GamepadJustPressed ¶ added in v0.16.0
func (s *State) GamepadJustPressed(button GamepadButton) bool
func (*State) GamepadJustReleased ¶ added in v0.16.0
func (s *State) GamepadJustReleased(button GamepadButton) bool
func (*State) GamepadName ¶ added in v0.16.0
func (*State) GamepadValue ¶ added in v0.16.0
func (s *State) GamepadValue(axis GamepadAxis) float64
func (*State) JustPressed ¶
func (*State) KeyCodeConsumed ¶ added in v0.13.0
func (*State) KeyCodeDown ¶ added in v0.7.0
func (*State) KeyCodeJustPressed ¶ added in v0.7.0
func (*State) KeyCodeJustReleased ¶ added in v0.7.0
func (*State) MouseJustPressed ¶
func (s *State) MouseJustPressed(button MouseButton) bool
func (*State) MouseJustReleased ¶
func (s *State) MouseJustReleased(button MouseButton) bool
func (*State) MousePressed ¶
func (s *State) MousePressed(button MouseButton) bool
func (*State) ResetGamepad ¶ added in v0.16.0
func (s *State) ResetGamepad()
func (*State) ResetKeyboard ¶ added in v0.11.0
func (s *State) ResetKeyboard()
ResetKeyboard forgets held keys and pending keyboard input after focus loss. Releases may happen in another window and never reach us. Clear the edge history too, so cancellation does not trigger actions bound to key releases.
func (*State) ResetMouseButtons ¶ added in v0.16.0
func (s *State) ResetMouseButtons()
ResetMouseButtons cancels drags after focus loss without generating clicks.
func (*State) SetGamepad ¶ added in v0.16.0
func (s *State) SetGamepad(next GamepadFrame)
SetGamepad runs on the game thread, like SetKeyCode. Sources must not mutate State from OS callback threads. Switching controllers clears the old edges.
func (*State) SetKeyCode ¶ added in v0.7.0
func (*State) SetMouseButton ¶
func (s *State) SetMouseButton(button MouseButton, pressed bool)