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
ViewportState.h File Reference

ViewportState is the single source of truth for the editor render pane's screen↔document coordinate mapping. See docs/design_docs/0025-2-editor_ux.md for the full design rationale; this header is the public API. More...

Include dependency graph for ViewportState.h:
This graph shows which files directly or indirectly include this file:

Classes

struct  donner::editor::EditorRasterViewport
 Raster target derived from an editor viewport. More...
struct  donner::editor::ViewportState
 All viewport state for a single frame of the render pane. Plain data, side-effect-free, copyable, ~80 bytes. More...

Namespaces

namespace  donner
 Top-level Donner namespace, which is split into different sub-namespaces such as donner::svg and donner::css.

Detailed Description

ViewportState is the single source of truth for the editor render pane's screen↔document coordinate mapping. See docs/design_docs/0025-2-editor_ux.md for the full design rationale; this header is the public API.

Conceptually a ViewportState is a value the main loop snapshots once at the top of each frame and then hands to every reader (async render dispatch, click math, overlay re-render, image draw, inspector text). Every reader consults the same value, so the four pieces never disagree about where the document is on screen.

Coordinate spaces:

  • document / world: SVG viewBox coordinates.
  • screen: ImGui screen-pixel coordinates in logical pixels, (0, 0) at the top-left of the OS window. On Retina, a mouse position of (100, 100) is the same logical pixel regardless of devicePixelRatio.
  • device pixel: physical pixels in the rasterized bitmap. Equal to screen * devicePixelRatio. Only the SVG renderer's bitmap output and the GL texture upload care about this.

Zoom semantics: zoom == 1.0 means 100% - one SVG viewBox unit takes exactly one screen pixel. This is the initial state when the editor opens and the target of Cmd+0 / View → Reset Zoom. The user can pan freely if the document doesn't fit the window.