Documentation
¶
Overview ¶
Package editorkit holds editor primitives shared by the asset editor and the map editor: a pan/zoom camera, a dot-grid renderer and a generic undo/redo history. It is asset-agnostic; it only depends on render for the View type.
Index ¶
- Constants
- func ClampScale(s float64) float64
- func DoubleClick(cur, last int64, dx, dy float64) bool
- func DrawDotGrid(dst *ebiten.Image, view render.View, region image.Rectangle, step float64, ...)
- func PlayPreview(rate int, pcm []byte, vol float64)
- func PlayPreviewLoop(rate int, pcm []byte, vol float64)
- func PlayPreviewMP3(rate int, data []byte, vol float64)
- func PlayPreviewStream(rate int, src io.Reader, vol float64)
- func StopPreview()
- type Camera
- type History
Constants ¶
const ( MinScale = 0.5 MaxScale = 64.0 FitMargin = 24.0 )
Zoom limits and framing margin (in screen pixels of scale).
const DoubleClickGap int64 = 20
DoubleClickGap is the maximum number of ticks between two clicks for them to count as a double-click (about a third of a second at 60 TPS).
Variables ¶
This section is empty.
Functions ¶
func ClampScale ¶
ClampScale keeps a scale within the allowed zoom range.
func DoubleClick ¶
DoubleClick reports whether a click at the current tick closely follows the previous one in both time and screen position. dx/dy are the screen-space offsets from the previous click.
func DrawDotGrid ¶
func DrawDotGrid(dst *ebiten.Image, view render.View, region image.Rectangle, step float64, dotColor, axisColor color.Color, originX, originY float64)
DrawDotGrid draws a faint grid of dots across the region at the given world spacing, plus brighter axis lines through (originX, originY). When zoomed out the spacing coarsens (in powers of two) so the dots remain visible rather than disappearing, keeping the cost bounded.
func PlayPreview ¶
PlayPreview plays a PCM buffer (16-bit LE stereo at rate), replacing any running preview. Empty PCM just stops the current one.
func PlayPreviewLoop ¶
PlayPreviewLoop plays a PCM buffer as a seamless infinite loop (a continuous sound: an engine, a beam), replacing any running preview. Stop with StopPreview.
func PlayPreviewMP3 ¶
PlayPreviewMP3 decodes an MP3 file's bytes and streams it as the preview, replacing any running one. Undecodable data just stops the current preview.
func PlayPreviewStream ¶
PlayPreviewStream plays a decoded audio stream (16-bit LE stereo at rate), replacing any running preview — used for long tracks (a stage song) that should stream rather than be buffered whole.
Types ¶
type Camera ¶
Camera maps asset/world space to screen via a render.View, with zoom, pan and fit-to-box helpers. MinScale/MaxScale override the package defaults when set (non-zero), letting an unbounded map zoom out much further than an asset.
func (*Camera) FitBox ¶
FitBox frames the world-space box [minX,minY]-[maxX,maxY] centered within the screen region, leaving a margin.
type History ¶
type History[T any] struct { // contains filtered or unexported fields }
History is a generic undo/redo stack over deep-copied snapshots of a document of type T. It coalesces a continuous gesture (e.g. a drag) into a single step: the pre-gesture snapshot is held until the gesture settles.
func NewHistory ¶
NewHistory creates a history that snapshots with clone and keeps at most limit undo steps.
func (*History[T]) Commit ¶
Commit turns per-frame change signals into undo steps. before is the document state captured at the start of the frame; changed reports whether the document changed this frame; busy is true while a continuous gesture is in progress (no step is cut mid-gesture).