control

package
v0.24.1 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2026 License: MIT Imports: 7 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package control is the input vocabulary: what the engine captures each frame, and the commands and bindings a game is driven by.

InputEvents

InputEvents is one tick's input: the mouse (where it is, and whether the window has it), the modifiers, the scroll delta and a queue of [ClickEvent]s and [KeyEvent]s. An EventHandler reacts to it once a tick; the active Scene's HandleEvents is one.

Commands and bindings

A command is an intention in the game's vocabulary, as data: a type is a command.Command by its method command.Command, confirmed where it is defined (var _ command.Command = MoveTo{}). The plugin that defines a command's type keeps a [Queue] of it and drains it in its own pass, each command.Issued with the command.Issuer that gave it, or the entity that gave it itself; a command.Carrier sorts commands into the queues of their types. Traits a command may have besides are asked for where they matter: command.Routed, Contextual. A Binding is a Trigger (KeyPress, KeyDown, KeyHeld, KeyReleased — let go, Context.Held how long it was down — ButtonPress, Drag, Wheel, ButtonHeld, CursorAtEdge — the cursor within EdgeMargin of the picture's edge, or in a corner's square of CornerReach a side, CornerSide for a small picture (Edges, Corner, Edges.Depth how deep in, for a scroll quickening to the edge), CursorInCorner there alone — CursorMove, CursorOver) with exactly its Mods, the command Build makes from a Context or Give names, and a label for the list of keys; a key held, down or let go fires with Shift, Ctrl or Alt held only Binding.InChords; a binding Binding.Yielding fires only when no other on its trigger builds a command. A Context carries the player, its camera, the cursor in the camera's pixels (Context.Dragged: past a click's slop from where the button went down) and the point picked in the world through the camera.

Settings

A Setting is one thing of a plugin's the players adjust on the settings screen: a Switch on or off, a Choice among options, a Range of a number. Each reads its value every frame and builds, from the value chosen, the command that sets it; a key bound to the same command builds the next value instead. A setting names the section of the screen it is listed under (Picture, Graphics, Game and the rest), or is listed under its plugin's; a Range may lie beside a Switch of its section (Range.Beside), in its row, live while the switch is on.

Tools

A Tool is what a player holds in hand, taken with Take and put down with Drop. A binding With a tool fires only while the player holds it, in place of the bindings with none.

Index

Constants

View Source
const (
	// EdgeMargin is how close to a window edge, in pixels, the cursor rests at it (CursorAtEdge).
	EdgeMargin = 60
	// CornerReach is the side of the square at each corner, in pixels, within which the cursor
	// rests in the corner; CornerSide caps it for a small picture.
	CornerReach = 120
	// DragSlop is how far, in shown pixels, the cursor may move from where a button went down
	// for a click, not a drag (Context.Dragged).
	DragSlop = 4
)
View Source
const (
	Picture               = "Picture"
	PictureTactical       = "Picture/Tactical"
	PictureTacticalLayers = "Picture/Tactical/Layers"
	PictureRiding         = "Picture/Riding"
	PictureRidingLayers   = "Picture/Riding/Layers"
	PictureShadows        = "Picture/Shadows"
	PictureAreas          = "Picture/Areas"
	Graphics              = "Picture/Graphics"
	Game                  = "Game"
)

The sections of the settings screen the plugins share: the picture, how it is drawn in a tactical view and riding in first person and the layers of each, the areas shown, the graphics, and the game: what a player sees of the world's own rules.

View Source
const Keys = int(keyCount)

Keys is how many keys there are, for going over all of them.

Variables

This section is empty.

Functions

func CaptureCursor added in v0.3.0

func CaptureCursor(on bool)

CaptureCursor catches the window's cursor — hidden, the mouse moving without end — or shows it again; nothing without a window.

func CornerSide added in v0.3.0

func CornerSide(w, h float32) float32

CornerSide is the side of a corner's square in a picture w by h pixels: CornerReach, or a quarter of the shorter side where that is less.

func FullscreenKey added in v0.6.0

func FullscreenKey() (key, label string)

FullscreenKey is the key that switches full screen and its label for the controls screen: F11, unless the engine said otherwise.

func ScreenRect added in v0.3.0

func ScreenRect(a, b geom.Vec) geom.AABB

ScreenRect is the screen rectangle between a and b, at least a pixel a side.

func SectionOf added in v0.3.0

func SectionOf(s Setting) string

SectionOf is the section s is listed under; empty for the plugin's own.

func SetCursorCapture added in v0.3.0

func SetCursorCapture(fn func(on bool))

SetCursorCapture is the engine's: how the window catches its cursor and lets it go.

func SetFullscreenKey added in v0.6.0

func SetFullscreenKey(key, label string)

SetFullscreenKey is the engine's: the key that switches full screen on this platform and what the controls screen says of it, where the system keeps F11 for itself.

Types

type Binding added in v0.3.0

type Binding struct {
	Trigger Trigger
	Label   string
	// contains filtered or unexported fields
}

Binding is one thing a player can do: a Trigger, the command it issues and a label for a help screen. Make one with Build or Give.

func Build added in v0.3.0

func Build[C command.Command](
	trigger Trigger,
	label string,
	build func(c Context) (C, bool),
) Binding

Build is a Binding issuing a C built from the Context when trigger fires; build may decline.

func Give added in v0.3.0

func Give(trigger Trigger, label string, cmd command.Command) Binding

Give is a Binding issuing cmd whenever trigger fires, a Contextual one for the Context. A command kept in a register (a ceremony.command.Command) must come from it: one made on the spot panics.

func (Binding) Build added in v0.3.0

func (b Binding) Build(c Context) (command.Command, bool)

Build is the command for c, if the binding has one to give.

func (Binding) Holds added in v0.3.0

func (b Binding) Holds(how camera.How) bool

Holds reports whether b holds while the camera is fastened how.

func (Binding) In added in v0.3.0

func (b Binding) In(hows ...camera.How) Binding

In is b holding only while the player's camera is fastened one of hows (camera.HowOf). A binding never given hows holds whatever the camera does.

func (Binding) InChords added in v0.3.0

func (b Binding) InChords() Binding

InChords is b, on a key held, down or let go, firing with Shift, Ctrl or Alt held too: a sprint with Shift, a jump while sprinting. Without it such a binding leaves the chords to the shortcuts.

func (Binding) Overlaps added in v0.3.0

func (b Binding) Overlaps(o Binding) bool

Overlaps reports whether b and o hold in some How both with one tool, both yielding or neither: two such bindings on one Trigger would both fire.

func (Binding) Takes added in v0.3.0

func (b Binding) Takes(mods Mods) bool

Takes reports whether b fires with mods held: a key's or a button's press and a drag as their triggers ask; a key held, down or let go with no modifier but the key itself, unless InChords.

func (Binding) Tool added in v0.3.0

func (b Binding) Tool() Tool

Tool is the tool b holds with; none for a binding holding whatever the player holds.

func (Binding) Type added in v0.3.0

func (b Binding) Type() reflect.Type

Type is the type of command the binding issues; nil for one made with neither Build nor Give.

func (Binding) With added in v0.3.0

func (b Binding) With(tool Tool) Binding

With is b holding only while the player holds tool, its trigger taken from the bindings with no tool.

func (Binding) Yielding added in v0.6.0

func (b Binding) Yielding() Binding

Yielding is b firing only when no other binding on its trigger builds a command: what the trigger does when nothing else takes it.

func (Binding) Yields added in v0.6.0

func (b Binding) Yields() bool

Yields reports whether b fires only when no other binding on its trigger builds a command.

type ButtonHeld added in v0.3.0

type ButtonHeld struct{ Button MouseButton }

ButtonHeld fires every pass Button is down and the cursor moved inside the window; Context.Delta is by how much and Context.Start where the button went down.

type ButtonPress added in v0.3.0

type ButtonPress struct {
	Button MouseButton
	Mods   Mods
}

ButtonPress fires when Button goes down with Mods held; Context.Cursor is where.

type Choice added in v0.3.0

type Choice struct {
	Label   string
	Section string
	Options []string
	Get     func() int
	Set     func(i int) command.Command
}

Choice is a setting with one of its Options chosen, Get and Set by its index.

type ClickEvent

type ClickEvent struct {
	Pos    geom.Vec
	Button MouseButton
	Action KeyAction
}

type Context added in v0.3.0

type Context struct {
	Player     command.Issuer
	Camera     camera.Camera
	Cursor     geom.Vec // where the cursor is, or where a button went down or up
	Start      geom.Vec // where a Drag began
	Delta      geom.Vec
	Wheel      float32
	Screen     geom.Vec // the picture's size in the camera's pixels
	Resolution float32  // camera pixels a shown pixel; 0 as 1
	Mods       Mods
	Held       time.Duration // how long a key was held, for KeyReleased
}

Context is what a binding builds its command from: the player, its camera and this tick's input in the camera's pixels, Resolution of them a shown one; World and WorldBox go through the camera.

func (Context) Dragged added in v0.6.0

func (c Context) Dragged() bool

Dragged reports whether the cursor has moved past DragSlop from where the button went down (Start): a drag, not a click.

func (Context) Edges added in v0.3.0

func (c Context) Edges() Edges

Edges is which window edges the cursor rests near and in which corner's square of CornerReach a side, the margins in shown pixels; a cursor outside the window rests near none.

func (Context) Pixels added in v0.3.0

func (c Context) Pixels(shown float32) float32

Pixels is shown pixels in the camera's: a speed in pixels of the screen as the camera has it.

func (Context) Point added in v0.3.0

func (c Context) Point(s geom.Vec) (at geom.Vec, z float32, picked bool)

Point is what screen position s sees and its height, through a camera.Picker's own Pick. Where the camera picks nothing (no Picker, or the sky) picked is false and at is World.

func (Context) Shown added in v0.3.0

func (c Context) Shown(v geom.Vec) geom.Vec

Shown is v, in the camera's pixels, in the shown ones: a move of the mouse as the hand made it.

func (Context) World added in v0.3.0

func (c Context) World(s geom.Vec) geom.Vec

World is the ground point under screen position s: a camera.Picker's own Pick, else the camera's FromScreen. Through no camera it is s itself.

func (Context) WorldBox added in v0.3.0

func (c Context) WorldBox(a, b geom.Vec) geom.AABB

WorldBox is the world rectangle between screen points a and b, at least one unit a side. Through no camera it is the screen's rectangle itself.

type Contextual added in v0.3.0

type Contextual interface {
	In(c Context) command.Command
}

Contextual is a command that reads where it was given: In is the command for the Context its trigger fired in — the one pointed at with the cursor.

type Corner added in v0.3.0

type Corner uint8

Corner is which corner of the window a cursor rests in, NoCorner for none.

const (
	NoCorner Corner = iota
	TopLeft
	TopRight
	BottomLeft
	BottomRight
)

func (Corner) Signs added in v0.3.0

func (c Corner) Signs() (x, y float32)

Signs are the way the corner lies from the middle, -1 or 1 each way; 0 for none.

type CursorAtEdge added in v0.3.0

type CursorAtEdge struct{}

CursorAtEdge fires every tick the cursor rests near a window edge; the carrier says how near.

type CursorInCorner added in v0.3.0

type CursorInCorner struct{}

CursorInCorner fires every tick the cursor rests in a corner's square, as CursorAtEdge does too; Context.Edges says which corner.

type CursorMove added in v0.3.0

type CursorMove struct{}

CursorMove fires every pass the cursor moves, Context.Delta by how much. It reaches the player the cursor is over, and one whose camera rides in an entity wherever the cursor is.

type CursorOver added in v0.3.0

type CursorOver struct{}

CursorOver fires once a tick while the cursor lies over the player's picture of the world, still or not, its command landing in the tick after.

type Drag added in v0.3.0

type Drag struct {
	Button MouseButton
	Mods   Mods
}

Drag fires when Button comes up with Mods held, after going down: Context.Start is where it went down, Context.Cursor where it came up. A click is a Drag of no length.

type Drop added in v0.3.0

type Drop struct{}

Drop has the player who gives it put down the tool it holds.

func (Drop) Command added in v0.3.0

func (Drop) Command()

type Edges added in v0.3.0

type Edges struct {
	Left, Right, Top, Bottom bool
	Corner                   Corner
	Depth                    float32
}

Edges are the window edges a cursor rests near, the corner it rests in, and how Deep in the strip or the corner's square it stands: 0 at the inner bound, 1 at the window's edge, in a corner the deeper of the two ways.

func (Edges) Any added in v0.3.0

func (e Edges) Any() bool

Any reports whether the cursor rests near any edge or in a corner.

type EventHandler

type EventHandler interface {
	HandleEvents(events *InputEvents)
}

EventHandler reacts to this tick's input events.

type InputEvents

type InputEvents struct {
	MousePos    geom.Vec
	CursorDelta geom.Vec
	Modifiers   struct {
		Shift, Ctrl, Alt bool
	}
	MiddleDown bool
	// CursorInWindow reports whether the window has the cursor: it came in and has not left
	// since. MousePos is where it was last seen, zero before any.
	CursorInWindow bool

	ClickQueue  []ClickEvent
	KeyEvents   []KeyEvent
	ScrollDelta float32
}

func (*InputEvents) AddClickEvent

func (e *InputEvents) AddClickEvent(x, y int, button MouseButton, action KeyAction)

func (*InputEvents) AddKeyEvent

func (e *InputEvents) AddKeyEvent(key Key, action KeyAction)

func (*InputEvents) ResetTransient

func (e *InputEvents) ResetTransient()

type Key added in v0.3.0

type Key uint16

Key is a key of the keyboard, by its place on it; Shift, Control and Alt are either of the two.

const (
	KeyUnknown Key = iota
	KeyA
	KeyB
	KeyC
	KeyD
	KeyE
	KeyF
	KeyG
	KeyH
	KeyI
	KeyJ
	KeyK
	KeyL
	KeyM
	KeyN
	KeyO
	KeyP
	KeyQ
	KeyR
	KeyS
	KeyT
	KeyU
	KeyV
	KeyW
	KeyX
	KeyY
	KeyZ
	Key0
	Key1
	Key2
	Key3
	Key4
	Key5
	Key6
	Key7
	Key8
	Key9
	KeyF1
	KeyF2
	KeyF3
	KeyF4
	KeyF5
	KeyF6
	KeyF7
	KeyF8
	KeyF9
	KeyF10
	KeyF11
	KeyF12
	KeyEscape
	KeyEnter
	KeySpace
	KeyTab
	KeyBackspace
	KeyDelete
	KeyInsert
	KeyHome
	KeyEnd
	KeyPageUp
	KeyPageDown
	KeyArrowUp
	KeyArrowDown
	KeyArrowLeft
	KeyArrowRight
	KeyShift
	KeyControl
	KeyAlt
	KeyMinus
	KeyEqual
	KeyBracketLeft
	KeyBracketRight
	KeyBackslash
	KeySemicolon
	KeyQuote
	KeyBackquote
	KeyComma
	KeyPeriod
	KeySlash
	KeyCapsLock
	KeyNumpad0
	KeyNumpad1
	KeyNumpad2
	KeyNumpad3
	KeyNumpad4
	KeyNumpad5
	KeyNumpad6
	KeyNumpad7
	KeyNumpad8
	KeyNumpad9
	KeyNumpadAdd
	KeyNumpadSubtract
	KeyNumpadMultiply
	KeyNumpadDivide
	KeyNumpadDecimal
	KeyNumpadEnter
)

The keys, named as Ebitengine named them.

func (Key) String added in v0.3.0

func (k Key) String() string

String is the key's name, as Ebitengine wrote it: "A", "Digit1", "ArrowUp".

type KeyAction

type KeyAction int
const (
	ActionPress KeyAction = iota
	ActionRelease
)

type KeyDown added in v0.3.0

type KeyDown struct{ Key Key }

KeyDown fires when Key goes down, whatever other key is held; with Shift, Ctrl or Alt held only as a binding InChords: a jump while sprinting with Shift.

type KeyEvent

type KeyEvent struct {
	Key    Key
	Action KeyAction
}

type KeyHeld added in v0.3.0

type KeyHeld struct{ Key Key }

KeyHeld fires once a tick while Key is down, whatever other key is held, with Shift, Ctrl or Alt only as a binding InChords; its command lands in the tick after. A key tapped between two ticks never fires.

type KeyPress added in v0.3.0

type KeyPress struct {
	Key  Key
	Mods Mods
}

KeyPress fires when Key goes down with Mods held.

type KeyReleased added in v0.3.0

type KeyReleased struct{ Key Key }

KeyReleased fires when Key comes up, Context.Held saying how long it was down: a throw as strong as the key was held. A key held for a chord with modifiers (Shift+X) does not fire it, nor one let go with a modifier held besides it, unless the binding is InChords.

type Mods added in v0.3.0

type Mods struct {
	Shift, Ctrl, Alt bool
	// contains filtered or unexported fields
}

Mods is the modifier keys a trigger asks for, and at most one other key held down with them (see Holding); a trigger fires only with exactly these held.

func (Mods) Held added in v0.3.0

func (m Mods) Held() (Key, bool)

Held is the key m asks to be held down besides its modifiers, if any.

func (Mods) Holding added in v0.3.0

func (m Mods) Holding(key Key) Mods

Holding is m with key held down besides: S held while right-clicking, say.

type MouseButton added in v0.3.0

type MouseButton uint8

MouseButton is a button of the mouse.

const (
	MouseButtonLeft MouseButton = iota
	MouseButtonRight
	MouseButtonMiddle
)

type Range added in v0.3.0

type Range struct {
	Label   string
	Section string
	Beside  string
	Min     float64
	Max     float64
	Step    float64
	Get     func() float64
	Set     func(v float64) command.Command
	Shows   func(v float64) string
}

Range is a setting of a number between Min and Max, moved a Step at a time; Shows writes the number for the player (nil: as it is). Beside names a Switch of the same section the range lies beside, in its row, live while the switch is on; empty, the range has a row of its own.

type Setting added in v0.3.0

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

Setting is one thing of a plugin's the players adjust on the settings screen, a control each: a Switch, a Choice or a Range. Get is read every frame; Set builds the command carrying the value chosen, which the screen issues as a button issues its commands. Section is the section the setting is listed under, a path of levels ("Picture/Graphics"); empty, the plugin's own.

type Switch added in v0.3.0

type Switch struct {
	Label   string
	Section string
	Get     func() bool
	Set     func(on bool) command.Command
}

Switch is a setting that is on or off.

type Take added in v0.3.0

type Take struct{ Tool Tool }

Take has the player who gives it hold Tool in hand, putting down whatever it held.

func (Take) Command added in v0.3.0

func (Take) Command()

type Tool added in v0.3.0

type Tool string

Tool is what a player holds in hand, by name. While it holds one, the bindings With it take their triggers from the bindings with none.

type Trigger added in v0.3.0

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

Trigger is what fires a Binding: a key, a button, a gesture. The concrete triggers are values, so two bindings on one trigger are told apart when bound.

type Wheel added in v0.3.0

type Wheel struct{}

Wheel fires on any scroll; Context.Wheel is how much.

Jump to

Keyboard shortcuts

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