Pulp 1.88.0
Cross-platform audio plugin framework
Loading...
Searching...
No Matches
scene_shape.hpp
Go to the documentation of this file.
1// SceneShape — retained primitive-shape node (rect, rounded-rect,
2// circle, ellipse, line). Anything more complex composes into ScenePath.
3#pragma once
4
6
7#include <memory>
8
9namespace pulp::canvas {
10
11class SceneShape : public SceneNode {
12public:
20
22
23 // SceneNode disables copy; the factory functions return owning
24 // `std::unique_ptr<SceneShape>` so callers can hand them straight to
25 // `SceneGroup::add_child(...)`.
26 static std::unique_ptr<SceneShape> make_rect(float x, float y,
27 float w, float h);
28 static std::unique_ptr<SceneShape> make_rounded_rect(float x, float y,
29 float w, float h,
30 float radius);
31 static std::unique_ptr<SceneShape> make_circle(float cx, float cy,
32 float radius);
33 static std::unique_ptr<SceneShape> make_ellipse(float cx, float cy,
34 float rx, float ry);
35 static std::unique_ptr<SceneShape> make_line(float x0, float y0,
36 float x1, float y1);
37
38 Kind shape_kind() const { return shape_kind_; }
39
40 // ── Geometry accessors / mutators ────────────────────────────────────
41 // For rect / rounded_rect: x,y,w,h. radius extra for rounded.
42 // For circle: cx,cy,radius (uses x=cx, y=cy, w=h=radius*2 internally).
43 // For ellipse: cx,cy,rx,ry.
44 // For line: x0,y0 in (x,y), x1,y1 in (w,h).
45 float x() const { return x_; }
46 float y() const { return y_; }
47 float w() const { return w_; }
48 float h() const { return h_; }
49 float radius() const { return radius_; }
50
51 void set_rect(float x, float y, float w, float h);
52 void set_rounded_rect(float x, float y, float w, float h, float radius);
53 void set_circle(float cx, float cy, float radius);
54 void set_ellipse(float cx, float cy, float rx, float ry);
55 void set_line(float x0, float y0, float x1, float y1);
56
57 // ── Paint ────────────────────────────────────────────────────────────
58 bool fill_enabled() const { return fill_enabled_; }
59 void set_fill_enabled(bool v) {
60 if (fill_enabled_ == v) return;
61 fill_enabled_ = v;
62 mark_dirty();
63 }
64
65 bool stroke_enabled() const { return stroke_enabled_; }
66 void set_stroke_enabled(bool v) {
67 if (stroke_enabled_ == v) return;
68 stroke_enabled_ = v;
69 mark_dirty();
70 }
71
72 Color fill_color() const { return fill_color_; }
74 if (fill_color_ == c) return;
75 fill_color_ = c;
76 mark_dirty();
77 }
78
79 Color stroke_color() const { return stroke_color_; }
81 if (stroke_color_ == c) return;
82 stroke_color_ = c;
83 mark_dirty();
84 }
85
86 float stroke_width() const { return stroke_width_; }
87 void set_stroke_width(float w) {
88 if (stroke_width_ == w) return;
89 stroke_width_ = w;
90 mark_dirty();
91 }
92
93 // ── SceneNode overrides ──────────────────────────────────────────────
94 SceneRect local_bounds() const override;
95 void paint_geometry(Canvas& canvas) const override;
96
97private:
98 Kind shape_kind_ = Kind::rect;
99 float x_ = 0, y_ = 0, w_ = 0, h_ = 0, radius_ = 0;
100 Color fill_color_ = Color::rgba(0, 0, 0, 1);
101 Color stroke_color_ = Color::rgba(0, 0, 0, 1);
102 float stroke_width_ = 1.0f;
103 bool fill_enabled_ = true;
104 bool stroke_enabled_ = false;
105};
106
107} // namespace pulp::canvas
Definition canvas.hpp:240
void mark_dirty()
Mark this node and (recursively) every ancestor dirty.
SceneNode(SceneNodeKind kind)
Definition scene_node.hpp:108
bool fill_enabled() const
Definition scene_shape.hpp:58
SceneShape()
Definition scene_shape.hpp:21
bool stroke_enabled() const
Definition scene_shape.hpp:65
float y() const
Definition scene_shape.hpp:46
float x() const
Definition scene_shape.hpp:45
void set_stroke_width(float w)
Definition scene_shape.hpp:87
void set_line(float x0, float y0, float x1, float y1)
Color fill_color() const
Definition scene_shape.hpp:72
void set_stroke_color(Color c)
Definition scene_shape.hpp:80
void set_ellipse(float cx, float cy, float rx, float ry)
void paint_geometry(Canvas &canvas) const override
Paint this node (and its sub-tree) into canvas.
void set_circle(float cx, float cy, float radius)
void set_rounded_rect(float x, float y, float w, float h, float radius)
float stroke_width() const
Definition scene_shape.hpp:86
SceneRect local_bounds() const override
Local-coordinate bounding box (pre-transform, pre-opacity).
void set_fill_enabled(bool v)
Definition scene_shape.hpp:59
void set_rect(float x, float y, float w, float h)
void set_fill_color(Color c)
Definition scene_shape.hpp:73
float w() const
Definition scene_shape.hpp:47
static std::unique_ptr< SceneShape > make_rect(float x, float y, float w, float h)
float h() const
Definition scene_shape.hpp:48
static std::unique_ptr< SceneShape > make_rounded_rect(float x, float y, float w, float h, float radius)
static std::unique_ptr< SceneShape > make_ellipse(float cx, float cy, float rx, float ry)
static std::unique_ptr< SceneShape > make_circle(float cx, float cy, float radius)
Kind
Definition scene_shape.hpp:13
@ rect
Definition scene_shape.hpp:14
@ ellipse
Definition scene_shape.hpp:17
@ line
Definition scene_shape.hpp:18
@ rounded_rect
Definition scene_shape.hpp:15
@ circle
Definition scene_shape.hpp:16
Kind shape_kind() const
Definition scene_shape.hpp:38
float radius() const
Definition scene_shape.hpp:49
void set_stroke_enabled(bool v)
Definition scene_shape.hpp:66
static std::unique_ptr< SceneShape > make_line(float x0, float y0, float x1, float y1)
Color stroke_color() const
Definition scene_shape.hpp:79
Definition affine_transform.hpp:24
SceneNodeKind
Kind discriminator — keeps dynamic_cast off the hot path.
Definition scene_node.hpp:91
@ shape
Definition scene_node.hpp:94
Definition canvas.hpp:52
static constexpr Color rgba(float r, float g, float b, float a=1.0f)
Construct from float channels [0,1] (>1.0 allowed for HDR).
Definition canvas.hpp:56
Axis-aligned bounding box used for repaint-rect math.
Definition scene_node.hpp:27