Pulp 1.88.0
Cross-platform audio plugin framework
Loading...
Searching...
No Matches
svg_path_widget.hpp
Go to the documentation of this file.
1#pragma once
2
10
11#include <pulp/view/view.hpp>
13#include <pulp/canvas/path.hpp>
14#include <optional>
15#include <string>
16#include <vector>
17
18namespace pulp::view {
19
31 float p[6] = {};
32};
33
39class SvgPathWidget : public View {
40public:
41 SvgPathWidget() = default;
42
51 void set_path(std::string data);
52
58
64 void set_viewbox(float width, float height);
65
74 bool stretch_to_bounds() const { return stretch_to_bounds_; }
75
79 void clear_fill();
80
100 void set_fill_gradient(std::string css_linear_gradient);
102 const std::string& fill_gradient() const { return fill_gradient_; }
103
108
117 void set_stroke_gradient(std::string css_linear_gradient);
119 const std::string& stroke_gradient() const { return stroke_gradient_; }
120
122 void set_stroke_width(float w);
123
131 void set_stroke_miter_limit(float limit);
132 std::optional<canvas::LineCap> stroke_cap() const {
133 return stroke_cap_;
134 }
135 std::optional<canvas::LineJoin> stroke_join() const {
136 return stroke_join_;
137 }
138 std::optional<float> stroke_miter_limit() const {
139 return stroke_miter_limit_;
140 }
141
152
153 // Accessors used by tests.
154 const std::string& path_data() const { return path_data_; }
155 const std::vector<SvgPathSegment>& segments() const { return segments_; }
156 bool has_fill() const { return has_fill_; }
157 bool has_stroke() const { return has_stroke_; }
158 canvas::Color fill_color() const { return fill_color_; }
159 canvas::Color stroke_color() const { return stroke_color_; }
160 float stroke_width() const { return stroke_width_; }
161 canvas::FillRule fill_rule() const { return fill_rule_; }
162 float viewbox_width() const { return viewbox_w_; }
163 float viewbox_height() const { return viewbox_h_; }
164
165 void paint(canvas::Canvas& canvas) override;
166
175 float intrinsic_width() const override { return viewbox_w_ > 0 ? viewbox_w_ : 0; }
176 float intrinsic_height() const override { return viewbox_h_ > 0 ? viewbox_h_ : 0; }
177
178private:
179 void reparse();
181 canvas::Path stroke_geometry() const;
183 void repaint_extent_change(const Rect& before);
184
185 std::string path_data_;
186 std::vector<SvgPathSegment> segments_;
187 canvas::Color fill_color_{0.0f, 0.0f, 0.0f, 1.0f};
188 canvas::Color stroke_color_{0.0f, 0.0f, 0.0f, 1.0f};
189 std::string fill_gradient_; // non-empty overrides solid fill
190 std::string stroke_gradient_; // non-empty overrides solid stroke
191 float stroke_width_ = 1.0f;
192 std::optional<canvas::LineCap> stroke_cap_;
193 std::optional<canvas::LineJoin> stroke_join_;
194 std::optional<float> stroke_miter_limit_;
195 canvas::FillRule fill_rule_ = canvas::FillRule::nonzero; // pulp #3656
196 float viewbox_w_ = 0.0f; // 0 means "use widget bounds 1:1"
197 float viewbox_h_ = 0.0f;
198 bool stretch_to_bounds_ = false; // preserveAspectRatio="none"
199 bool has_fill_ = true;
200 bool has_stroke_ = false;
201};
202
203} // namespace pulp::view
Definition canvas.hpp:240
Definition path.hpp:87
void set_stroke_width(float w)
Stroke width in SVG path-coords (i.e. viewBox space). Default 1.
bool stretch_to_bounds() const
Definition svg_path_widget.hpp:74
canvas::Color fill_color() const
Definition svg_path_widget.hpp:158
void set_stretch_to_bounds(bool stretch)
Stretch the viewbox onto the widget's bounds instead of fitting it — SVG's preserveAspectRatio="none"...
canvas::FillRule fill_rule() const
Definition svg_path_widget.hpp:161
void set_stroke_cap(canvas::LineCap cap)
SVG stroke-linecap, stroke-linejoin and stroke-miterlimit.
const std::string & fill_gradient() const
Definition svg_path_widget.hpp:102
std::optional< canvas::LineJoin > stroke_join() const
Definition svg_path_widget.hpp:135
const std::vector< SvgPathSegment > & segments() const
Definition svg_path_widget.hpp:155
float stroke_width() const
Definition svg_path_widget.hpp:160
void paint(canvas::Canvas &canvas) override
void set_stroke_join(canvas::LineJoin join)
float viewbox_width() const
Definition svg_path_widget.hpp:162
bool has_fill() const
Definition svg_path_widget.hpp:156
bool has_stroke() const
Definition svg_path_widget.hpp:157
float intrinsic_width() const override
pulp #72 — expose the viewBox as the natural / intrinsic size so Yoga can use it as flex-basis when t...
Definition svg_path_widget.hpp:175
void set_fill_gradient(std::string css_linear_gradient)
pulp #932 / #1737 — gradient fill as a CSS linear-gradient string.
void set_stroke_miter_limit(float limit)
canvas::Color stroke_color() const
Definition svg_path_widget.hpp:159
std::optional< float > stroke_miter_limit() const
Definition svg_path_widget.hpp:138
void set_viewbox(float width, float height)
Set the source coordinate space the path was authored in.
std::optional< canvas::LineCap > stroke_cap() const
Definition svg_path_widget.hpp:132
void set_stroke_gradient(std::string css_linear_gradient)
Gradient stroke as a CSS linear-gradient string — the stroke mirror of set_fill_gradient(),...
void set_stroke_color(canvas::Color c)
Solid-stroke paint.
void set_fill_rule(canvas::FillRule rule)
pulp #3656 — fill winding rule, mirroring SVG's fill-rule (nonzero | evenodd).
Rect paint_extent() const
Conservative local-space box of everything paint() draws: the path's control-point hull mapped throug...
const std::string & stroke_gradient() const
Definition svg_path_widget.hpp:119
void set_path(std::string data)
Set the path-data string.
void set_fill_color(canvas::Color c)
Solid-fill paint.
const std::string & path_data() const
Definition svg_path_widget.hpp:154
float intrinsic_height() const override
Definition svg_path_widget.hpp:176
float viewbox_height() const
Definition svg_path_widget.hpp:163
Definition affine_transform.hpp:24
FillRule
Winding rule used to decide what counts as "inside" a path.
Definition path.hpp:54
@ nonzero
Definition path.hpp:54
LineJoin
Join applied where two segments meet when stroking.
Definition path.hpp:60
LineCap
Line cap applied to the ends of open subpaths when stroking.
Definition path.hpp:57
Hover-cursor tracking for platform window hosts.
Definition fwd.hpp:27
@ c
Definition input_events.hpp:39
@ w
Definition input_events.hpp:41
@ height
Definition css_animation.hpp:128
@ width
Definition css_animation.hpp:127
@ stretch
Definition design_ir.hpp:57
Definition canvas.hpp:52
Axis-aligned rectangle in continuous (float) coordinates.
Definition geometry.hpp:52
Parsed path segment — flat, allocation-light, ready to replay onto a Canvas in a single pass during p...
Definition svg_path_widget.hpp:22
Op
Definition svg_path_widget.hpp:23
@ cubic_to
(cp1x, cp1y, cp2x, cp2y, x, y)
Definition svg_path_widget.hpp:27
@ line_to
(x, y)
Definition svg_path_widget.hpp:25
@ move_to
(x, y)
Definition svg_path_widget.hpp:24
@ close_path
Definition svg_path_widget.hpp:28
@ quad_to
(cpx, cpy, x, y)
Definition svg_path_widget.hpp:26
float p[6]
Definition svg_path_widget.hpp:31
Op op
Definition svg_path_widget.hpp:30