Donner SVG 0.8.0
0.8.0 ยท ebf353960.8.0 main
SVG editor and embeddable C⁠+⁠+⁠20 engine.
Loading...
Searching...
No Matches
donner::editor::OverlayRenderer Class Reference

Draws selection and tool chrome from captured document geometry. More...

#include "donner/editor/OverlayRenderer.h"

Public Types

enum class  ChromeSquare {
  PathAnchor ,
  PathControlPoint ,
  TransformHandle
}
 Chrome squares whose on-screen size is fixed, and therefore resolved against the transform the chrome is drawn with rather than stored. More...

Static Public Member Functions

static SelectionChromeSnapshot withLivePathGeometry (SelectionChromeSnapshot snapshot, const Path &pathDoc)
 Replace one cached path's geometry using owning document-space data, without DOM access. Paint and clipping eligibility must already have been validated by the caller's capture.
static void drawChrome (svg::RendererInterface &renderer, const EditorApp &editor)
 Draw all editor chrome layers for the current state of editor into renderer's active frame. No-op if there is no document or no selection. Pulls the canvasFromDocument transform from the editor's document so chrome lands on the same pixels as the rendered content, regardless of canvas/viewBox aspect mismatch.
static void drawChrome (svg::RendererInterface &renderer, const std::optional< svg::SVGElement > &selection)
 Overload that takes a selection snapshot directly. Single-element back-compat shim - kept so worker-thread callers and existing tests don't have to switch to spans. Identity canvasFromDoc.
static void drawChromeWithTransform (svg::RendererInterface &renderer, const std::optional< svg::SVGElement > &selection, const Transform2d &canvasFromDoc)
 Lower-level single-element entry: draw chrome for selection (or none) using canvasFromDoc. Kept for back-compat with the existing single-select call sites.
static void drawChromeWithTransform (svg::RendererInterface &renderer, std::span< const svg::SVGElement > selection, const std::optional< Box2d > &marqueeRectDoc, const Transform2d &canvasFromDoc, const std::optional< SelectionChromeBoundsPreview > &activeBoundsPreview=std::nullopt, std::span< const svg::SVGElement > sourceHover={}, const std::optional< Box2d > &cullRectDoc=std::nullopt, SelectionChromeDetail selectionDetail=SelectionChromeDetail::Full, const Transform2d &representedDocumentFromLiveDocument=Transform2d())
 Multi-element entry: draw path outlines for every selected element, selection AABBs, and the optional marquee rect into renderer's active frame using canvasFromDoc.
static void drawChromeWithTransform (svg::RendererInterface &renderer, std::span< const svg::SVGElement > selection, const Transform2d &canvasFromDoc)
 Back-compat overload without marquee. Kept for existing callers that don't need a marquee rect (older tests, worker-thread helpers). Path outlines + selection AABBs are still drawn.
static SelectionChromeSnapshot captureChromeSnapshot (std::span< const svg::SVGElement > selection, const std::optional< Box2d > &marqueeRectDoc, const Transform2d &canvasFromDoc, const std::optional< SelectionChromeBoundsPreview > &activeBoundsPreview=std::nullopt, std::span< const svg::SVGElement > sourceHover={}, const std::optional< Box2d > &cullRectDoc=std::nullopt, SelectionChromeDetail selectionDetail=SelectionChromeDetail::Full, const Transform2d &representedDocumentFromLiveDocument=Transform2d(), const std::optional< LockedRejectionFlashInput > &lockedFlash=std::nullopt, double devicePixelRatio=1.0, const std::optional< svg::SVGElement > &livePathPreviewElement=std::nullopt)
 Build a SelectionChromeSnapshot for the given selection + marquee + canvas transform. Reads computedSpline, elementFromWorld, and SnapshotSelectionWorldBounds for every selected element - MUST be called when the worker is idle or otherwise not mutating these components on the same registry. When cullRectDoc is present, path outlines, AABBs, and handles fully outside that document-space rect are skipped before draw. CombinedBoundsOnly skips selected path extraction and stores one combined bounds box for low-latency interaction feedback. An active scale/rotate preview derives oriented bounds and handles directly from gesture-owned geometry without traversing the selection.
static SelectionChromeSnapshot projectSelectionSnapshot (SelectionChromeSnapshot snapshot, const Transform2d &documentFromCapturedDocument, const std::optional< SelectionChromeBoundsPreview > &boundsPreview=std::nullopt)
 Project captured selection geometry without accessing the document. Hover chrome and inherited clip guides remain fixed; selection paths, handles and owned clips follow.
static void cullSnapshot (SelectionChromeSnapshot &snapshot, const Box2d &cullRectDoc)
 Cull a presentation copy after projecting it, retaining the complete capture for later moves.
static void projectCachedClipGuides (SelectionChromeSnapshot *destination, const SelectionChromeSnapshot &prior, const std::optional< SelectionChromeBoundsPreview > &activeBoundsPreview, const Transform2d &representedDocumentFromLiveDocument)
 Reuse an idle-captured clip guide without touching the SVG registry during a drag. Direct selected-owner clips follow the gesture; inherited clips keep their document placement.
static Box2d ChromeSquareForPoint (const SelectionChromeSnapshot &snapshot, ChromeSquare kind, const Vector2d &pointDoc)
 Document-space square for one chrome point, sized for snapshot's current canvasFromDoc.
static void drawChromeFromSnapshot (svg::RendererInterface &renderer, const SelectionChromeSnapshot &snapshot)
 Race-free chrome rasterize: reads only the snapshot, never the registry. Safe to call while the async-renderer worker is mid-render.

Detailed Description

Draws selection and tool chrome from captured document geometry.

Member Enumeration Documentation

◆ ChromeSquare

Chrome squares whose on-screen size is fixed, and therefore resolved against the transform the chrome is drawn with rather than stored.

Enumerator
PathAnchor 

Selected-path vertex anchor square.

PathControlPoint 

Selected-path Bezier control-point square.

TransformHandle 

Selection resize/rotate corner handle square.

Member Function Documentation

◆ captureChromeSnapshot()

SelectionChromeSnapshot donner::editor::OverlayRenderer::captureChromeSnapshot ( std::span< const svg::SVGElement > selection,
const std::optional< Box2d > & marqueeRectDoc,
const Transform2d & canvasFromDoc,
const std::optional< SelectionChromeBoundsPreview > & activeBoundsPreview = std::nullopt,
std::span< const svg::SVGElement > sourceHover = {},
const std::optional< Box2d > & cullRectDoc = std::nullopt,
SelectionChromeDetail selectionDetail = SelectionChromeDetail::Full,
const Transform2d & representedDocumentFromLiveDocument = Transform2d(),
const std::optional< LockedRejectionFlashInput > & lockedFlash = std::nullopt,
double devicePixelRatio = 1.0,
const std::optional< svg::SVGElement > & livePathPreviewElement = std::nullopt )
staticnodiscard

Build a SelectionChromeSnapshot for the given selection + marquee + canvas transform. Reads computedSpline, elementFromWorld, and SnapshotSelectionWorldBounds for every selected element - MUST be called when the worker is idle or otherwise not mutating these components on the same registry. When cullRectDoc is present, path outlines, AABBs, and handles fully outside that document-space rect are skipped before draw. CombinedBoundsOnly skips selected path extraction and stores one combined bounds box for low-latency interaction feedback. An active scale/rotate preview derives oriented bounds and handles directly from gesture-owned geometry without traversing the selection.

Parameters
devicePixelRatioViewport framebuffer scale used to convert logical UI stroke widths into device pixels.

The returned snapshot is movable and self- contained: it holds no registry pointers and survives any subsequent registry mutation.

Parameters
livePathPreviewElementWhen set, the element the Pen tool is actively editing: its live document-space geometry and resolved solid paint are captured into SelectionChromeSnapshot::livePathPreview so the draw phase can present the edited path from the same DOM capture as the chrome. Skipped (nullopt in the snapshot) when the element's paint cannot be represented as a solid preview.
selectionSelected elements to capture while the document is available.
marqueeRectDocOptional marquee rectangle in document coordinates.
canvasFromDocMaps document coordinates to canvas pixels.
activeBoundsPreviewOptional live gesture bounds replacing idle selection bounds.
sourceHoverElements highlighted by source-pane hover.
cullRectDocOptional document-space rectangle restricting captured chrome.
selectionDetailDetail level for selected-element outlines and handles.
representedDocumentFromLiveDocumentMaps live geometry into the document coordinates currently presented.
lockedFlashOptional locked-element rejection highlight to capture.

◆ ChromeSquareForPoint()

Box2d donner::editor::OverlayRenderer::ChromeSquareForPoint ( const SelectionChromeSnapshot & snapshot,
ChromeSquare kind,
const Vector2d & pointDoc )
staticnodiscard

Document-space square for one chrome point, sized for snapshot's current canvasFromDoc.

Consumers outside the draw path (the SVG viewport export) resolve their geometry through this so it matches the drawn chrome exactly.

Parameters
snapshotSnapshot supplying the transform and device pixel ratio.
kindWhich chrome square to size.
pointDocDocument-space center of the square.

◆ cullSnapshot()

void donner::editor::OverlayRenderer::cullSnapshot ( SelectionChromeSnapshot & snapshot,
const Box2d & cullRectDoc )
static

Cull a presentation copy after projecting it, retaining the complete capture for later moves.

Parameters
snapshotPresentation copy whose offscreen geometry is removed.
cullRectDocVisible document rectangle including the chrome margin.

◆ drawChromeFromSnapshot()

void donner::editor::OverlayRenderer::drawChromeFromSnapshot ( svg::RendererInterface & renderer,
const SelectionChromeSnapshot & snapshot )
static

Race-free chrome rasterize: reads only the snapshot, never the registry. Safe to call while the async-renderer worker is mid-render.

Produces byte-identical pixels to drawChromeWithTransform(selection, marqueeRectDoc, canvasFromDoc) given the same input snapshot - pinned by OverlayRendererTest.SnapshotProducesByteIdenticalPixels.

◆ drawChromeWithTransform()

void donner::editor::OverlayRenderer::drawChromeWithTransform ( svg::RendererInterface & renderer,
std::span< const svg::SVGElement > selection,
const std::optional< Box2d > & marqueeRectDoc,
const Transform2d & canvasFromDoc,
const std::optional< SelectionChromeBoundsPreview > & activeBoundsPreview = std::nullopt,
std::span< const svg::SVGElement > sourceHover = {},
const std::optional< Box2d > & cullRectDoc = std::nullopt,
SelectionChromeDetail selectionDetail = SelectionChromeDetail::Full,
const Transform2d & representedDocumentFromLiveDocument = Transform2d() )
static

Multi-element entry: draw path outlines for every selected element, selection AABBs, and the optional marquee rect into renderer's active frame using canvasFromDoc.

This renderer-backed path is kept for pixel tests and non-editor callers. The live editor presentation path captures the same snapshot, then draws it immediately through RenderPanePresenter to avoid allocating and uploading a full overlay texture.

AABBs are computed inline from selection (via SnapshotSelectionWorldBounds) at overlay-draw time so they always match the current DOM snapshot - same source of truth as the per-element path outlines. This avoids the frame-lag-shear that happened when AABBs came from a separately-promoted cache while the path outlines came from the live DOM.

Parameters
selectionSelected elements whose per-element path outlines
  • AABBs should be drawn.
marqueeRectDocOptional marquee rect in document space; drawn as a filled + stroked rectangle matching the prior ImGui chrome style.
canvasFromDocMaps document coordinates into canvas pixels.
cullRectDocOptional document-space cull rect. Chrome fully outside this rect is skipped before draw.
selectionDetailDetail level for selected-element chrome.
rendererRenderer whose active frame receives the chrome.
activeBoundsPreviewOptional live gesture bounds replacing idle selection bounds.
sourceHoverElements highlighted by source-pane hover.
representedDocumentFromLiveDocumentMaps live geometry into the document coordinates currently presented.

◆ projectSelectionSnapshot()

SelectionChromeSnapshot donner::editor::OverlayRenderer::projectSelectionSnapshot ( SelectionChromeSnapshot snapshot,
const Transform2d & documentFromCapturedDocument,
const std::optional< SelectionChromeBoundsPreview > & boundsPreview = std::nullopt )
staticnodiscard

Project captured selection geometry without accessing the document. Hover chrome and inherited clip guides remain fixed; selection paths, handles and owned clips follow.

Parameters
snapshotCaptured geometry, copied or moved by the caller.
documentFromCapturedDocumentTransform from captured to represented document space.
boundsPreviewGesture bounds already expressed in represented document space.

◆ withLivePathGeometry()

SelectionChromeSnapshot donner::editor::OverlayRenderer::withLivePathGeometry ( SelectionChromeSnapshot snapshot,
const Path & pathDoc )
static

Replace one cached path's geometry using owning document-space data, without DOM access. Paint and clipping eligibility must already have been validated by the caller's capture.

Parameters
snapshotOwning copy of the captured selection chrome.
pathDocReplacement geometry copied into the snapshot in document coordinates.
Returns
Updated snapshot, or the unchanged copy when it has no live path preview.

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