HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
graphic_path.hpp
1// Copyright Take Vos 2019-2021.
2// Distributed under the Boost Software License, Version 1.0.
3// (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt)
4
5#pragma once
6
7#include "bezier_point.hpp"
8#include "bezier_curve.hpp"
9#include "utility/module.hpp"
10#include "geometry/module.hpp"
11#include "image/module.hpp"
12#include <vector>
13
14namespace hi::inline v1 {
15
16struct bezier_curve;
17template<typename T>
19
30
34
38
41 void clear() noexcept
42 {
43 points.clear();
44 contourEndPoints.clear();
45 layerEndContours.clear();
46 }
47
50 [[nodiscard]] ssize_t numberOfContours() const noexcept;
51
54 [[nodiscard]] ssize_t numberOfLayers() const noexcept;
55
58 [[nodiscard]] bool allLayersHaveSameColor() const noexcept;
59
62 [[nodiscard]] aarectangle boundingBox() const noexcept;
63
68 void tryRemoveLayers() noexcept;
69
72 [[nodiscard]] std::vector<bezier_point>::const_iterator beginContour(ssize_t contourNr) const noexcept;
73
74 /* Return and end-iterator beyond the end point of a contour.
75 */
76 [[nodiscard]] std::vector<bezier_point>::const_iterator endContour(ssize_t contourNr) const noexcept;
77
78 /* Return the first contour index of a layer.
79 */
80 [[nodiscard]] ssize_t beginLayer(ssize_t layerNr) const noexcept;
81
82 /* Return beyond the last contour index of a layer.
83 */
84 [[nodiscard]] ssize_t endLayer(ssize_t layerNr) const noexcept;
85
86 [[nodiscard]] std::vector<bezier_point> getbezier_pointsOfContour(ssize_t contourNr) const noexcept;
87
88 [[nodiscard]] std::vector<bezier_curve> getBeziersOfContour(ssize_t contourNr) const noexcept;
89
90 [[nodiscard]] std::vector<bezier_curve> getBeziers() const noexcept;
91
92 [[nodiscard]] std::pair<graphic_path, color> getLayer(ssize_t layerNr) const noexcept;
93
94 [[nodiscard]] color getColorOfLayer(ssize_t layerNr) const noexcept;
95
96 void setColorOfLayer(ssize_t layerNr, color fill_color) noexcept;
97
100 [[nodiscard]] bool isContourOpen() const noexcept;
101
105 void closeContour() noexcept;
106
109 [[nodiscard]] bool hasLayers() const noexcept;
110
113 [[nodiscard]] bool isLayerOpen() const noexcept;
114
118 void closeLayer(color fill_color) noexcept;
119
123 void optimizeLayers() noexcept;
124
128 [[nodiscard]] point2 currentPosition() const noexcept;
129
133 void moveTo(point2 position) noexcept;
134
138 void moveRelativeTo(vector2 direction) noexcept;
139
140 void lineTo(point2 position) noexcept;
141
142 void lineRelativeTo(vector2 direction) noexcept;
143
144 void quadraticCurveTo(point2 controlPosition, point2 position) noexcept;
145
150 void quadraticCurveRelativeTo(vector2 controlDirection, vector2 direction) noexcept;
151
152 void cubicCurveTo(point2 controlPosition1, point2 controlPosition2, point2 position) noexcept;
153
159 void cubicCurveRelativeTo(vector2 controlDirection1, vector2 controlDirection2, vector2 direction) noexcept;
160
172 void arcTo(float radius, point2 position) noexcept;
173
179 void addRectangle(aarectangle rectangle, corner_radii corners = corner_radii{0.0f, 0.0f, 0.0f, 0.0f}) noexcept;
180
185 void addCircle(point2 position, float radius) noexcept;
186
190 void addContour(std::vector<bezier_curve> const &contour) noexcept;
191
196 std::vector<bezier_point>::const_iterator const &begin,
197 std::vector<bezier_point>::const_iterator const &end) noexcept;
198
202 void addContour(std::vector<bezier_point> const &contour) noexcept;
203
206 void addPath(graphic_path const &path, color fill_color) noexcept;
207
211 graphic_path const &path,
212 color strokeColor,
213 float strokeWidth,
214 hi::line_join_style line_join_style = line_join_style::miter,
215 float tolerance = 0.05f) noexcept;
216
228 [[nodiscard]] graphic_path toStroke(
229 float strokeWidth = 1.0f,
230 line_join_style line_join_style = line_join_style::miter,
231 float tolerance = 0.05f) const noexcept;
232
235 [[nodiscard]] graphic_path centerScale(extent2 extent, float padding = 0.0) const noexcept;
236
237 graphic_path &operator+=(graphic_path const &rhs) noexcept;
238
239 [[nodiscard]] friend graphic_path operator+(graphic_path lhs, graphic_path const &rhs) noexcept
240 {
241 return lhs += rhs;
242 }
243
244 friend graphic_path operator*(geo::transformer auto const &lhs, graphic_path const &rhs) noexcept
245 {
246 auto rhs_ = rhs;
247 for (auto &&point : rhs_.points) {
248 point = lhs * point;
249 }
250 return rhs_;
251 }
252};
253
260void composit(pixmap_span<sfloat_rgba16> dst, hi::color color, graphic_path const &mask) noexcept;
261
267void composit(pixmap_span<sfloat_rgba16> dst, graphic_path const &mask) noexcept;
268
273void fill(pixmap_span<sdf_r8> dst, graphic_path const &path) noexcept;
274
275} // namespace hi::inline v1
line_join_style
The way two lines should be joined.
Definition line_join_style.hpp:18
STL namespace.
DOXYGEN BUG.
Definition algorithm.hpp:13
void composit(pixmap_span< sfloat_rgba16 > dst, hi::color color, graphic_path const &mask) noexcept
Composit color onto the destination image where the mask is solid.
void fill(pixmap_span< uint8_t > image, std::vector< bezier_curve > const &curves) noexcept
Fill a linear gray scale image by filling a curve with anti-aliasing.
Definition bezier_curve.hpp:22
Definition bezier_point.hpp:16
This is a RGBA floating point color.
Definition color.hpp:44
A rectangle / parallelogram in 3D space.
Definition rectangle.hpp:20
Definition graphic_path.hpp:18
A path is a vector graphics object.
Definition graphic_path.hpp:26
void moveRelativeTo(vector2 direction) noexcept
Start a new contour relative to current position.
void closeContour() noexcept
Close current contour.
void addCircle(point2 position, float radius) noexcept
Draw a circle.
bool isContourOpen() const noexcept
Return true if there is an open contour.
point2 currentPosition() const noexcept
Get the currentPosition of the open contour.
std::vector< std::pair< ssize_t, color > > layerEndContours
An color and index into.
Definition graphic_path.hpp:37
void addPath(graphic_path const &path, color fill_color) noexcept
Add path and close layer.
void arcTo(float radius, point2 position) noexcept
Draw an circular arc.
void optimizeLayers() noexcept
Optimize layers.
bool isLayerOpen() const noexcept
Return true if there is an open layer.
void addContour(std::vector< bezier_point > const &contour) noexcept
Curve with the given bezier curve.
std::vector< ssize_t > contourEndPoints
An index into.
Definition graphic_path.hpp:33
bool allLayersHaveSameColor() const noexcept
Check if all layers have the same color.
void addRectangle(aarectangle rectangle, corner_radii corners=corner_radii{0.0f, 0.0f, 0.0f, 0.0f}) noexcept
Draw a rectangle.
ssize_t numberOfLayers() const noexcept
Return the number of closed layers.
void moveTo(point2 position) noexcept
Start a new contour at position.
std::vector< bezier_point > points
A set of all bezier points describing all bezier curves, contours and layers.
Definition graphic_path.hpp:29
void clear() noexcept
Clear the path.
Definition graphic_path.hpp:41
bool hasLayers() const noexcept
This path has layers.
graphic_path centerScale(extent2 extent, float padding=0.0) const noexcept
Center and scale a path inside the extent with padding.
void tryRemoveLayers() noexcept
Try to move the layers in a path.
graphic_path toStroke(float strokeWidth=1.0f, line_join_style line_join_style=line_join_style::miter, float tolerance=0.05f) const noexcept
Convert path to stroke-path.
void addContour(std::vector< bezier_curve > const &contour) noexcept
Contour with the given bezier curves.
void closeLayer(color fill_color) noexcept
Close current contour.
void addStroke(graphic_path const &path, color strokeColor, float strokeWidth, hi::line_join_style line_join_style=line_join_style::miter, float tolerance=0.05f) noexcept
Stroke a path and close layer.
std::vector< bezier_point >::const_iterator beginContour(ssize_t contourNr) const noexcept
Return an iterator to the start point of a contour.
ssize_t numberOfContours() const noexcept
Return the number of closed contours.
void cubicCurveRelativeTo(vector2 controlDirection1, vector2 controlDirection2, vector2 direction) noexcept
Draw curve from the current position to the new direction.
void addContour(std::vector< bezier_point >::const_iterator const &begin, std::vector< bezier_point >::const_iterator const &end) noexcept
Curve with the given bezier curve.
void quadraticCurveRelativeTo(vector2 controlDirection, vector2 direction) noexcept
Draw curve from the current position to the new direction.
aarectangle boundingBox() const noexcept
Calculate bounding box.
Definition transform.hpp:84