Pulp 1.88.0
Cross-platform audio plugin framework
Loading...
Searching...
No Matches
scene.hpp
Go to the documentation of this file.
1// VectorScene — the root of Pulp's retained vector scene graph.
2//
3// License-lineage note: the Pulp-side primitives use Pulp-native names
4// (`VectorScene`, `SceneNode`, `ScenePath`, `SceneShape`, `SceneImage`,
5// `SceneText`, `SceneGroup`) rather than any reference framework's
6// class names.
7//
8// Why a retained scene graph for Pulp:
9// - Custom paint widgets that build a vector composition once and
10// mutate a child's opacity / transform every frame should not have
11// to re-stream the whole command buffer to the canvas. The retained
12// model lets them surface only the dirty sub-tree to the host.
13// - SVG import (via the existing nanosvg path in `core/canvas/svg.hpp`)
14// wants a structured destination so the host can address individual
15// shapes — toggle visibility, swap a fill, animate a transform —
16// without re-parsing.
17// - Design-tool imports need a one-to-one container per design node so
18// round-tripping stays predictable.
19//
20// Current behavior:
21// - SVG loads as a `VectorScene` or `SceneGroup`.
22// - Mutating a child's opacity re-paints only that sub-tree's
23// bounding box (see `take_dirty_rect()`).
24// - Renders through the existing Canvas backends.
25#pragma once
26
33
34#include <memory>
35#include <string>
36
37namespace pulp::canvas {
38
40public:
41 VectorScene() : root_(std::make_unique<SceneGroup>()) {}
42
43 SceneGroup& root() { return *root_; }
44 const SceneGroup& root() const { return *root_; }
45
47 void set_root(std::unique_ptr<SceneGroup> r) {
48 if (!r) r = std::make_unique<SceneGroup>();
49 root_ = std::move(r);
50 dirty_rect_pending_ = root_->transformed_local_bounds();
51 }
52
53 // ── Painting ─────────────────────────────────────────────────────────
58
59 // ── Dirty-rect query (the whole point of a retained graph) ───────────
66
68 SceneRect peek_dirty_rect() const { return dirty_rect_pending_; }
69
72 void note_node_dirtied(const SceneNode& node);
73
74 // ── SVG ingest ───────────────────────────────────────────────────────
80 static VectorScene from_svg_string(const std::string& svg_data);
81
83 static VectorScene from_svg_file(const std::string& path);
84
85private:
86 std::unique_ptr<SceneGroup> root_;
87 SceneRect dirty_rect_pending_{}; // accumulates across mutations
88};
89
90} // namespace pulp::canvas
Definition canvas.hpp:240
Definition scene_group.hpp:18
Abstract base of every node in a VectorScene.
Definition scene_node.hpp:106
static VectorScene from_svg_file(const std::string &path)
Convenience: load an SVG file and return a populated scene.
void set_root(std::unique_ptr< SceneGroup > r)
Replace the root group entirely (e.g. after a fresh SVG import).
Definition scene.hpp:47
const SceneGroup & root() const
Definition scene.hpp:44
SceneGroup & root()
Definition scene.hpp:43
static VectorScene from_svg_string(const std::string &svg_data)
Parse an SVG document string and produce a populated VectorScene.
SceneRect peek_dirty_rect() const
Peek without resetting — useful for diagnostics + tests.
Definition scene.hpp:68
void note_node_dirtied(const SceneNode &node)
Called by SceneNode::mark_dirty() when a node mutates; unions the node's "old + new" bounds into the ...
VectorScene()
Definition scene.hpp:41
void paint(Canvas &canvas)
Walk + paint the entire scene to canvas.
SceneRect take_dirty_rect()
Returns the union of "old painted bounds" and "new transformedbounds" for every node that mutated sin...
Definition affine_transform.hpp:24
@ path
Definition scene_node.hpp:93
STL namespace.
Axis-aligned bounding box used for repaint-rect math.
Definition scene_node.hpp:27