package input
import "git.teletypegames.org/engines/inkwell/inkbase/input"
Package input provides consume-on-use input polling for inkbase hosts and widgets.
The host calls Input.Poll once at the start of every frame, which snapshots the pointer position, the just-pressed state of both mouse buttons, the wheel's travel and every key that went down. Then the one click is authoritative: whoever consumes it first wins, and later checks see LeftClicked report false. A widget that takes the click calls ConsumeLeft or ConsumeRight; a click on a speech line only skips the line and does not also fire the hotspot underneath.
Keys work the same way, and Input.ClaimKey — KeyPressed plus ConsumeKey — is the shape a widget binding half a dozen of them wants: a menu walking a list with the arrow keys claims them, so nothing else reads them on that frame. KeyPressed is edge-triggered like LeftClicked — holding a key answers true once — and a widget that wants a key held down reads ebiten.IsKeyPressed itself. The wheel is not consumed.
Index
-
type Input
- func New() *Input
- func (i *Input) ClaimKey(key ebiten.Key) bool
- func (i *Input) ConsumeKey(key ebiten.Key)
- func (i *Input) ConsumeLeft()
- func (i *Input) ConsumeRight()
- func (i *Input) ConsumedClick() bool
- func (i *Input) KeyPressed(key ebiten.Key) bool
- func (i *Input) LeftClicked() bool
- func (i *Input) Point() inkbase.Point
- func (i *Input) Poll()
- func (i *Input) Pos() (int, int)
- func (i *Input) RightClicked() bool
- func (i *Input) Wheel() (float64, float64)
Types
type Input
type Input struct { // contains filtered or unexported fields }
Input is read once per Update() and exposes a tiny "consume on use" API so that one click can be authoritative — e.g. clicking on a hotspot while a Say is active should only skip the Say, not also fire the hotspot underneath.
Keys work the same way. A widget that binds the arrow keys claims them, so a menu walking a list does not also drive whatever else listens for the same key on the same frame.
func New
func New() *Input
New returns an empty Input; call Input.Poll at the start of each Update before reading it.
func (*Input) ClaimKey
func (i *Input) ClaimKey(key ebiten.Key) bool
ClaimKey is KeyPressed followed by ConsumeKey — the shape a widget that binds half a dozen keys wants, so its own navigation does not leak to whatever else reads the same key.
func (*Input) ConsumeKey
func (i *Input) ConsumeKey(key ebiten.Key)
ConsumeKey claims a key for this frame.
func (*Input) ConsumeLeft
func (i *Input) ConsumeLeft()
ConsumeLeft claims this frame's left click, so Input.LeftClicked reports false until the next Poll.
func (*Input) ConsumeRight
func (i *Input) ConsumeRight()
ConsumeRight claims this frame's right click, so Input.RightClicked reports false until the next Poll.
func (*Input) ConsumedClick
func (i *Input) ConsumedClick() bool
ConsumedClick is the Say-style "did the player click to skip?" probe: it reports whether there is an unconsumed left click, and consumes it.
func (*Input) KeyPressed
func (i *Input) KeyPressed(key ebiten.Key) bool
KeyPressed is edge-triggered: the key went down this frame and nobody has claimed it yet.
func (*Input) LeftClicked
func (i *Input) LeftClicked() bool
LeftClicked reports whether the left button went down this frame and nobody has consumed the click yet. It does not consume it.
func (*Input) Point
func (i *Input) Point() inkbase.Point
Point returns the cursor position as of the last Poll as an inkbase.Point.
func (*Input) Poll
func (i *Input) Poll()
Poll reads the cursor position, this frame's fresh mouse clicks, the wheel and the newly pressed keys from Ebitengine, and clears every consumed mark from the previous frame. Call it once per Update.
func (*Input) Pos
func (i *Input) Pos() (int, int)
Pos returns the cursor position in screen pixels as of the last Poll.
func (*Input) RightClicked
func (i *Input) RightClicked() bool
RightClicked reports whether the right button went down this frame and nobody has consumed the click yet. It does not consume it.
func (*Input) Wheel
func (i *Input) Wheel() (float64, float64)
Wheel is the mouse wheel's travel on this frame, in ebiten's own units. Nothing consumes it — a widget that scrolls checks that the pointer is over it first.