Donner SVG Editor & Engine
SVG-native editor and embeddable SVG2 + CSS3 engine in C++20, with GPU (WebGPU) and compact CPU renderers, built for correctness, security, and performance.
Loading...
Searching...
No Matches
donner::editor::PenTool Class Referencefinal

Click-to-place path authoring tool with direct point editing. More...

#include "donner/editor/PenTool.h"

Inheritance diagram for donner::editor::PenTool:
[legend]

Public Member Functions

void onMouseDown (EditorApp &editor, const Vector2d &documentPoint, MouseModifiers modifiers) override
 Handle a click in document space.
void onMouseMove (EditorApp &editor, const Vector2d &documentPoint, bool buttonHeld) override
 Handle pointer movement. While dragging the most recently placed anchor this shapes its Bezier handles; otherwise it is a no-op.
void onMouseMove (EditorApp &editor, const Vector2d &documentPoint, bool buttonHeld, MouseModifiers modifiers)
 Modifier-aware pointer movement. Alt/Option breaks handle symmetry so the dragged anchor becomes a corner whose incoming handle stays put while the outgoing handle follows the mouse.
void onMouseUp (EditorApp &editor, const Vector2d &documentPoint) override
 Handle mouse release. Commits the dragged anchor's handles if it moved.
void cancel (EditorApp &editor)
 Cancel the in-progress path. Restores the document and undo stack to the state before the pen session began - Escape / cancel never leaves a partial path behind.
void cancel ()
 Cancel the in-progress path without touching the document. Used when no editor is available (e.g. tool destruction); does not roll back the DOM.
bool commitOpenPath (EditorApp &editor)
 Commit the in-progress open path without closing it (no trailing Z). Triggered by Enter / double-click and by tool switches. Finalizes the path as one undoable command and clears the draft. No-op when not drafting or when the path has fewer than two anchors.
bool removeLastAnchor (EditorApp &editor)
 Remove the most recently placed anchor from the creation draft (Backspace/Delete while drafting). Removing the only remaining anchor discards the draft entirely. No-op during an active drag or a point-edit session on a committed path.
std::optional< PathpreviewSegmentPath (const Vector2d &documentPoint, const MouseModifiers &modifiers) const
 Live rubber-band preview of the segment a click at documentPoint would commit: from the draft's last anchor (honoring its outgoing handle and the Shift 45-degree constraint) to the pointer - or to the first anchor when the pointer is within closing range. Returns nullopt while not drafting, mid-drag, in a point-edit session, or after close.
bool wouldCloseAt (const Vector2d &documentPoint, const MouseModifiers &modifiers) const
 True when a click at documentPoint would close the active contour (used for the close-path hover affordance).
const Vector2ddraftStartPoint () const
 First anchor of the active draft (the close-path target).
bool isDrafting () const
 Whether the tool is currently appending to or point-editing a path.
bool isDraggingAnchor () const
 Whether a mouse drag is currently shaping a path point - the most recently placed anchor's handles, an existing anchor, or an existing control point.
const std::string & activePathData () const
 Current path data for tests and UI diagnostics.
Public Member Functions inherited from donner::editor::Tool
 Tool (const Tool &)=delete
Tool & operator= (const Tool &)=delete
 Tool (Tool &&)=delete
Tool & operator= (Tool &&)=delete

Detailed Description

Click-to-place path authoring tool with direct point editing.

Supports polyline creation, click-drag smooth Bezier anchors with Alt/Option corner-break, shift-constrained points (45-degree increments), continuing a selected open <path>, closing an active path by clicking near its first point, and committing an open path with Enter / double-click. Every finalized pen session records exactly one undoable command.

The visible path-point chrome is directly editable: anchors and control points of the active draft - or of a selected, already-committed <path>

  • are hit targets. Dragging a control point reshapes that handle (aligned coupling on smooth anchors; Alt/Option breaks the coupling; Shift constrains the handle angle to 45-degree increments), dragging an anchor moves it together with its handles, clicking the draft's last anchor retracts its outgoing handle so the next segment starts straight, Alt/Option-clicking an anchor toggles it between corner and smooth, clicking the open endpoint of a selected path resumes drafting from it, and Cmd/Ctrl restricts the gesture to point editing so a miss never places an anchor.

Member Function Documentation

◆ commitOpenPath()

bool donner::editor::PenTool::commitOpenPath ( EditorApp & editor)

Commit the in-progress open path without closing it (no trailing Z). Triggered by Enter / double-click and by tool switches. Finalizes the path as one undoable command and clears the draft. No-op when not drafting or when the path has fewer than two anchors.

Parameters
editorEditor state and mutation queue.
Returns
true if an open path was committed.

◆ onMouseDown()

void donner::editor::PenTool::onMouseDown ( EditorApp & editor,
const Vector2d & documentPoint,
MouseModifiers modifiers )
overridevirtual

Handle a click in document space.

Parameters
editorEditor state and mutation queue.
documentPointClick location in SVG document coordinates.
modifiersModifier-key state for the click.

Implements donner::editor::Tool.

◆ onMouseMove() [1/2]

void donner::editor::PenTool::onMouseMove ( EditorApp & editor,
const Vector2d & documentPoint,
bool buttonHeld )
overridevirtual

Handle pointer movement. While dragging the most recently placed anchor this shapes its Bezier handles; otherwise it is a no-op.

Parameters
editorEditor state and mutation queue.
documentPointPointer location in SVG document coordinates.
buttonHeldWhether the left mouse button is down.

Implements donner::editor::Tool.

◆ onMouseMove() [2/2]

void donner::editor::PenTool::onMouseMove ( EditorApp & editor,
const Vector2d & documentPoint,
bool buttonHeld,
MouseModifiers modifiers )

Modifier-aware pointer movement. Alt/Option breaks handle symmetry so the dragged anchor becomes a corner whose incoming handle stays put while the outgoing handle follows the mouse.

Parameters
editorEditor state and mutation queue.
documentPointPointer location in SVG document coordinates.
buttonHeldWhether the left mouse button is down.
modifiersModifier-key state for the drag.

◆ onMouseUp()

void donner::editor::PenTool::onMouseUp ( EditorApp & editor,
const Vector2d & documentPoint )
overridevirtual

Handle mouse release. Commits the dragged anchor's handles if it moved.

Parameters
editorEditor state and mutation queue.
documentPointRelease location in SVG document coordinates.

Implements donner::editor::Tool.

◆ previewSegmentPath()

std::optional< Path > donner::editor::PenTool::previewSegmentPath ( const Vector2d & documentPoint,
const MouseModifiers & modifiers ) const
nodiscard

Live rubber-band preview of the segment a click at documentPoint would commit: from the draft's last anchor (honoring its outgoing handle and the Shift 45-degree constraint) to the pointer - or to the first anchor when the pointer is within closing range. Returns nullopt while not drafting, mid-drag, in a point-edit session, or after close.

Parameters
documentPointPointer location in SVG document coordinates.
modifiersModifier-key state for the hover.

◆ removeLastAnchor()

bool donner::editor::PenTool::removeLastAnchor ( EditorApp & editor)

Remove the most recently placed anchor from the creation draft (Backspace/Delete while drafting). Removing the only remaining anchor discards the draft entirely. No-op during an active drag or a point-edit session on a committed path.

Parameters
editorEditor state and mutation queue.
Returns
true if an anchor was removed (or the draft was discarded).

◆ wouldCloseAt()

bool donner::editor::PenTool::wouldCloseAt ( const Vector2d & documentPoint,
const MouseModifiers & modifiers ) const
nodiscard

True when a click at documentPoint would close the active contour (used for the close-path hover affordance).

Parameters
documentPointPointer location in SVG document coordinates.
modifiersModifier-key state for the hover.

The documentation for this class was generated from the following file: