DrawStateMachine

class DrawStateMachine(historyManager: HistoryManager, entityRepository: EntityRepository, overlay: OverlayEngine? = null)

Holds the draw engine's live DrawEngineState and exposes it reactively via state.

state is deliberately exposed as StateFlow (via asStateFlow), never the underlying MutableStateFlow — this is the only place state actually changes, and only through onEvent routing into DrawEngineReducer. Exposing the mutable type directly would let external code overwrite state without going through the reducer.

Undo/redo is scoped to a session, not global: either drawing one new shape, or editing one existing entity. Inside a session each step — placing, moving or inserting a point of the draft (ReduceResult.modeChange, applied through SetModeCommand), or moving/adding a vertex of the entity being edited — is an undo step. When the session ends (finishing or abandoning the drawing, leaving edit mode, or editing a different entity) the history is cleared, and so is what could be undone: finishing a shape is not itself something undo can take back, so undo can never delete a whole shape you just finished. (Deleting a shape is the one thing that ends a session AND stays undoable — undo restores it.) Starting a session is likewise not a step. A host that runs its own commands through the same HistoryManager loses them at these boundaries too.

ReduceResult.commands are handed to historyManager, which both executes them (mutating entityRepository) and makes them undoable. ReduceResult.previewCommands are executed directly instead — see ReduceResult's KDoc for why a live vertex drag needs that distinction.

Constructors

Link copied to clipboard
constructor(historyManager: HistoryManager, entityRepository: EntityRepository, overlay: OverlayEngine? = null)

Properties

Link copied to clipboard
val state: StateFlow<DrawEngineState>

What the engine is doing now (see DrawEngineState); collect it to follow every change.

Functions

Link copied to clipboard
fun onEvent(event: DrawEvent)

Gives the engine event (a tap, a drag, a mode change, an edit...): it changes the state and the shapes as the event asks, and records the undo steps.