editorkit

package
v0.0.35 Latest Latest
Warning

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

Go to latest
Published: Aug 2, 2026 License: MIT Imports: 10 Imported by: 0

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

View Source
const (
	MinScale  = 0.5
	MaxScale  = 64.0
	FitMargin = 24.0
)

Zoom limits and framing margin (in screen pixels of scale).

View Source
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

func ClampScale(s float64) float64

ClampScale keeps a scale within the allowed zoom range.

func DoubleClick

func DoubleClick(cur, last int64, dx, dy float64) bool

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

func PlayPreview(rate int, pcm []byte, vol float64)

PlayPreview plays a PCM buffer (16-bit LE stereo at rate), replacing any running preview. Empty PCM just stops the current one.

func PlayPreviewLoop

func PlayPreviewLoop(rate int, pcm []byte, vol float64)

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

func PlayPreviewMP3(rate int, data []byte, vol float64)

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

func PlayPreviewStream(rate int, src io.Reader, vol float64)

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.

func StopPreview

func StopPreview()

StopPreview silences the running preview (a Stop button).

Types

type Camera

type Camera struct {
	View     render.View
	MinScale float64
	MaxScale float64
}

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

func (c *Camera) FitBox(region image.Rectangle, minX, minY, maxX, maxY float64)

FitBox frames the world-space box [minX,minY]-[maxX,maxY] centered within the screen region, leaving a margin.

func (*Camera) Pan

func (c *Camera) Pan(dx, dy float64)

Pan shifts the view by a screen-space delta.

func (*Camera) ZoomAt

func (c *Camera) ZoomAt(mx, my, factor float64)

ZoomAt multiplies the scale by factor while keeping the world point under the screen position (mx, my) fixed.

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

func NewHistory[T any](clone func(T) T, limit int) *History[T]

NewHistory creates a history that snapshots with clone and keeps at most limit undo steps.

func (*History[T]) Commit

func (h *History[T]) Commit(before T, changed, busy bool)

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).

func (*History[T]) Redo

func (h *History[T]) Redo(current T) (T, bool)

Redo re-applies the most recently undone snapshot.

func (*History[T]) RedoLen

func (h *History[T]) RedoLen() int

func (*History[T]) Undo

func (h *History[T]) Undo(current T) (T, bool)

Undo restores the previous snapshot, pushing current onto the redo stack. It returns the restored document and whether anything was undone.

func (*History[T]) UndoLen

func (h *History[T]) UndoLen() int

UndoLen and RedoLen report stack depths (useful for UI and tests).

Jump to

Keyboard shortcuts

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