input

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Mar 24, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MaxPointers         = 10  // pointer 0 = mouse, 1-9 = touch
	DefaultDragDeadZone = 4.0 // pixels
)

Variables

View Source
var (
	// ScreenToWorldFn converts screen coordinates to world coordinates.
	// Set by root to use the primary camera's ScreenToWorld.
	ScreenToWorldFn func(sx, sy float64) (float64, float64)

	// NodeDimensionsFn returns the display dimensions for a node.
	// Set by root (delegates to camera.NodeDimensions or render.NodeDimensions).
	NodeDimensionsFn func(n *node.Node) (w, h float64)

	// EmitInteractionEventFn bridges input events to the ECS entity store.
	// Set by root; nil when no EntityStore is configured.
	EmitInteractionEventFn func(eventType types.EventType, n *node.Node, wx, wy, lx, ly float64,
		button types.MouseButton, mods types.KeyModifiers, drag node.DragContext, pinch node.PinchContext)

	// RebuildSortedChildrenFn sorts a node's children by ZIndex.
	// Set by root (delegates to render.RebuildSortedChildren).
	RebuildSortedChildrenFn func(n *node.Node)
)

Functions

func ReadModifiers

func ReadModifiers() types.KeyModifiers

ReadModifiers reads the current keyboard modifier state.

Types

type CallbackHandle

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

CallbackHandle allows removing a registered scene-level callback.

func (CallbackHandle) Remove

func (h CallbackHandle) Remove()

Remove unregisters this callback.

type HandlerRegistry

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

HandlerRegistry stores event handler slices for all event types.

type HitCircle

type HitCircle struct {
	CenterX, CenterY, Radius float64
}

HitCircle is a circular hit area in local coordinates.

func (HitCircle) Contains

func (c HitCircle) Contains(x, y float64) bool

Contains reports whether (x, y) lies inside or on the circle.

type HitPolygon

type HitPolygon struct {
	Points []types.Vec2
}

HitPolygon is a convex polygon hit area in local coordinates.

func (HitPolygon) Contains

func (p HitPolygon) Contains(x, y float64) bool

Contains reports whether (x, y) lies inside a convex polygon.

type HitRect

type HitRect struct {
	X, Y, Width, Height float64
}

HitRect is an axis-aligned rectangular hit area in local coordinates.

func (HitRect) Contains

func (r HitRect) Contains(x, y float64) bool

Contains reports whether (x, y) lies inside the rectangle.

type Manager

type Manager struct {
	Handlers     HandlerRegistry
	Captured     [MaxPointers]*node.Node
	Pointers     [MaxPointers]pointerState
	HitBuf       []*node.Node
	DragDeadZone float64
	TouchMap     [MaxPointers]ebiten.TouchID
	TouchUsed    [MaxPointers]bool
	PrevTouchIDs []ebiten.TouchID
	Pinch        pinchState
	InjectQueue  []SyntheticPointerEvent
}

Manager owns all input state. Replaces the input-related fields on Scene.

func NewManager

func NewManager() *Manager

NewManager creates a Manager with default settings.

func (*Manager) CapturePointer

func (m *Manager) CapturePointer(pointerID int, n *node.Node)

CapturePointer routes all events for pointerID to the given node.

func (*Manager) CollectInteractable

func (m *Manager) CollectInteractable(n *node.Node, buf []*node.Node) []*node.Node

CollectInteractable is the exported version of collectInteractable (for testing).

func (*Manager) FireClick

func (m *Manager) FireClick(n *node.Node, pointerID int, wx, wy float64, button types.MouseButton, mods types.KeyModifiers)

FireClick is the exported version of fireClick.

func (*Manager) FireDrag

func (m *Manager) FireDrag(n *node.Node, pointerID int, wx, wy, startX, startY, deltaX, deltaY, screenDX, screenDY float64, button types.MouseButton, mods types.KeyModifiers)

FireDrag is the exported version of fireDrag.

func (*Manager) FireDragEnd

func (m *Manager) FireDragEnd(n *node.Node, pointerID int, wx, wy, startX, startY, deltaX, deltaY, screenDX, screenDY float64, button types.MouseButton, mods types.KeyModifiers)

FireDragEnd is the exported version of fireDragEnd.

func (*Manager) FireDragStart

func (m *Manager) FireDragStart(n *node.Node, pointerID int, wx, wy, startX, startY, deltaX, deltaY, screenDX, screenDY float64, button types.MouseButton, mods types.KeyModifiers)

FireDragStart is the exported version of fireDragStart.

func (*Manager) FirePinch

func (m *Manager) FirePinch(ctx node.PinchContext, mods types.KeyModifiers)

FirePinch is the exported version of firePinch.

func (*Manager) FirePointerDown

func (m *Manager) FirePointerDown(n *node.Node, pointerID int, wx, wy float64, button types.MouseButton, mods types.KeyModifiers)

FirePointerDown is the exported version of firePointerDown (for testing and bridging).

func (*Manager) HitTest

func (m *Manager) HitTest(root *node.Node, worldX, worldY float64) *node.Node

HitTest finds the topmost interactable node at (worldX, worldY). Returns nil if nothing is hit.

func (*Manager) InjectClick

func (m *Manager) InjectClick(x, y float64)

InjectClick is a convenience that queues a press followed by a release at the same screen coordinates. Consumes two frames.

func (*Manager) InjectDrag

func (m *Manager) InjectDrag(fromX, fromY, toX, toY float64, frames int)

InjectDrag queues a full drag sequence: press at (fromX, fromY), linearly interpolated moves over frames-2 intermediate frames, and release at (toX, toY). Minimum frames is 2.

func (*Manager) InjectHover

func (m *Manager) InjectHover(x, y float64)

InjectHover queues a free pointer move (no button held) at the given screen coordinates. Use this to trigger OnPointerEnter / OnPointerLeave callbacks without pressing a button.

func (*Manager) InjectMove

func (m *Manager) InjectMove(x, y float64)

InjectMove queues a pointer move event at the given screen coordinates with the button held down.

func (*Manager) InjectPress

func (m *Manager) InjectPress(x, y float64)

InjectPress queues a pointer press event at the given screen coordinates.

func (*Manager) InjectRelease

func (m *Manager) InjectRelease(x, y float64)

InjectRelease queues a pointer release event at the given screen coordinates.

func (*Manager) IsPointerDown

func (m *Manager) IsPointerDown(button types.MouseButton) bool

IsPointerDown reports whether the given mouse button is currently pressed. This checks the mouse pointer (pointer 0) state.

func (*Manager) OnBackgroundClick

func (m *Manager) OnBackgroundClick(fn func(node.ClickContext)) CallbackHandle

func (*Manager) OnClick

func (m *Manager) OnClick(fn func(node.ClickContext)) CallbackHandle

func (*Manager) OnDrag

func (m *Manager) OnDrag(fn func(node.DragContext)) CallbackHandle

func (*Manager) OnDragEnd

func (m *Manager) OnDragEnd(fn func(node.DragContext)) CallbackHandle

func (*Manager) OnDragStart

func (m *Manager) OnDragStart(fn func(node.DragContext)) CallbackHandle

func (*Manager) OnPinch

func (m *Manager) OnPinch(fn func(node.PinchContext)) CallbackHandle

func (*Manager) OnPointerDown

func (m *Manager) OnPointerDown(fn func(node.PointerContext)) CallbackHandle

func (*Manager) OnPointerEnter

func (m *Manager) OnPointerEnter(fn func(node.PointerContext)) CallbackHandle

func (*Manager) OnPointerLeave

func (m *Manager) OnPointerLeave(fn func(node.PointerContext)) CallbackHandle

func (*Manager) OnPointerMove

func (m *Manager) OnPointerMove(fn func(node.PointerContext)) CallbackHandle

func (*Manager) OnPointerUp

func (m *Manager) OnPointerUp(fn func(node.PointerContext)) CallbackHandle

func (*Manager) PointerPosition

func (m *Manager) PointerPosition() (x, y float64)

PointerPosition returns the last known pointer position in screen space for the mouse pointer (pointer 0).

func (*Manager) ProcessInjectedInput

func (m *Manager) ProcessInjectedInput(root *node.Node, mods types.KeyModifiers) bool

ProcessInjectedInput pops one event from the inject queue, converts screen→world via ScreenToWorldFn, and feeds it through processPointer. Returns true if an event was consumed (real mouse input should be skipped).

func (*Manager) ProcessInput

func (m *Manager) ProcessInput(root *node.Node)

ProcessInput handles all mouse and touch input for a frame. root is the scene graph root for hit testing.

func (*Manager) ProcessPointer

func (m *Manager) ProcessPointer(root *node.Node, pointerID int, wx, wy, sx, sy float64, pressed bool, button types.MouseButton, mods types.KeyModifiers)

ProcessPointer is the exported version of processPointer (for testing and bridging).

func (*Manager) ReleasePointer

func (m *Manager) ReleasePointer(pointerID int)

ReleasePointer stops routing events for pointerID to a captured node.

func (*Manager) SetDragDeadZone

func (m *Manager) SetDragDeadZone(pixels float64)

SetDragDeadZone sets the minimum movement in pixels before a drag starts.

type SyntheticPointerEvent

type SyntheticPointerEvent struct {
	ScreenX float64
	ScreenY float64
	Pressed bool
	Button  types.MouseButton
}

SyntheticPointerEvent represents a single injected pointer event. Screen coordinates are used (matching what an AI sees in screenshots) and converted to world coordinates via ScreenToWorldFn.

Jump to

Keyboard shortcuts

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