Donner 0.5.1
Embeddable browser-grade SVG2 engine
Loading...
Searching...
No Matches
donner::editor::ViewportState Struct Reference

All viewport state for a single frame of the render pane. Plain data, side-effect-free, copyable, ~80 bytes. More...

#include "donner/editor/ViewportState.h"

Collaboration diagram for donner::editor::ViewportState:
[legend]

Public Member Functions

double pixelsPerDocUnit () const
 Screen pixels per document unit at the current zoom. With the "zoom is in screen-pixels-per-doc-unit" convention this is just zoom; the accessor exists so callers don't reach for the raw field and the definition can grow if "100%" ever stops meaning "1:1".
double devicePixelsPerDocUnit () const
 Device pixels per document unit. Used by desiredCanvasSize and the renderer's RenderViewport.devicePixelRatio.
Vector2d documentToScreen (const Vector2d &docPoint) const
 Map a document point to a screen-pixel point.
Vector2d screenToDocument (const Vector2d &screenPoint) const
 Map a screen-pixel point to a document point.
Box2d documentToScreen (const Box2d &docBox) const
 Map a document-space box to its screen-pixel AABB.
Box2d screenToDocument (const Box2d &screenBox) const
 Map a screen-pixel box to its document-space AABB.
Box2d imageScreenRect () const
 On-screen rectangle of the displayed document image, in screen pixels. Equal to documentToScreen(documentViewBox). Used by the AddImage call so the image always lands at the right place regardless of texture resolution.
Vector2i desiredCanvasSize () const
 Canvas size (in device pixels) the SVG renderer should produce for the current zoom and DPR. Equal to documentViewBox.size() * zoom * devicePixelRatio, clamped to [1, kMaxCanvasDim] per axis.
void zoomAround (double newZoom, const Vector2d &focalScreen)
 Set the zoom factor while holding focalScreen fixed: after this call, the document point that was previously under focalScreen is still under focalScreen. Use for Cmd+wheel, Cmd+Plus / Cmd+Minus, menu-driven zoom, and pinch-to-zoom.
void panBy (const Vector2d &screenDelta)
 Pan by screenDelta screen pixels. After this call, every document point that was previously visible is at its previous screen position + screenDelta.
void resetTo100Percent ()
 Reset to 100%, with the document viewBox center anchored at the pane center. After this call, pixelsPerDocUnit() == 1.0 and documentToScreen(documentViewBoxCenter()) == paneCenter. This is the initial state when the editor opens, and the target of Cmd+0 / View → Reset Zoom / View → Actual Size.
Vector2d paneCenter () const
 Center of the render pane in screen pixels.
Vector2d documentViewBoxCenter () const
 Center of the document viewBox in document coordinates.

Public Attributes

Vector2d paneOrigin = Vector2d::Zero()
 Top-left of the render pane's content region in screen pixels.
Vector2d paneSize = Vector2d::Zero()
 Size of the render pane's content region in screen pixels.
Box2d documentViewBox
 SVG document viewBox in document coordinates.
double devicePixelRatio = 1.0
 OS device pixel ratio (1.0 on standard displays, 2.0 on Retina). Read via glfwGetWindowContentScale.
double zoom = 1.0
 Zoom factor in screen pixels per document unit. 1.0 means "100%": one SVG viewBox unit takes exactly one screen pixel, regardless of how many physical device pixels that is.
Vector2d panDocPoint = Vector2d::Zero()
 Document point that should appear at panScreenPoint. Together with panScreenPoint and zoom, this fully determines the screen↔document map.
Vector2d panScreenPoint = Vector2d::Zero()
 Screen point at which panDocPoint is anchored.

Static Public Attributes

static constexpr double kMinZoom = 0.1
 Minimum allowed zoom (10%).
static constexpr double kMaxZoom = 32.0
 Maximum allowed zoom (3200%).
static constexpr int kMaxCanvasDim = 8192
 Hard cap on the rasterized canvas dimension on either axis. A 32x zoom on a 4K display would otherwise rasterize a multi-GB bitmap; this clamp keeps us in a safe place at the cost of transient pixelation when the user zooms very far in.

Detailed Description

All viewport state for a single frame of the render pane. Plain data, side-effect-free, copyable, ~80 bytes.

Member Function Documentation

◆ zoomAround()

void donner::editor::ViewportState::zoomAround ( double newZoom,
const Vector2d & focalScreen )

Set the zoom factor while holding focalScreen fixed: after this call, the document point that was previously under focalScreen is still under focalScreen. Use for Cmd+wheel, Cmd+Plus / Cmd+Minus, menu-driven zoom, and pinch-to-zoom.

newZoom is clamped to [kMinZoom, kMaxZoom].


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