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 "exception.hpp"
11#include "geometry/transform.hpp"
13#include "rapid/sfloat_rgba16.hpp"
14#include "rapid/sdf_r8.hpp"
15#include <vector>
16
17namespace hi::inline v1 {
18
19struct bezier_curve;
20template<typename T>
21class pixel_map;
22
33
37
41
44 void clear() noexcept
45 {
46 points.clear();
47 contourEndPoints.clear();
48 layerEndContours.clear();
49 }
50
53 [[nodiscard]] ssize_t numberOfContours() const noexcept;
54
57 [[nodiscard]] ssize_t numberOfLayers() const noexcept;
58
61 [[nodiscard]] bool allLayersHaveSameColor() const noexcept;
62
65 [[nodiscard]] aarectangle boundingBox() const noexcept;
66
71 void tryRemoveLayers() noexcept;
72
75 [[nodiscard]] std::vector<bezier_point>::const_iterator beginContour(ssize_t contourNr) const noexcept;
76
77 /* Return and end-iterator beyond the end point of a contour.
78 */
79 [[nodiscard]] std::vector<bezier_point>::const_iterator endContour(ssize_t contourNr) const noexcept;
80
81 /* Return the first contour index of a layer.
82 */
83 [[nodiscard]] ssize_t beginLayer(ssize_t layerNr) const noexcept;
84
85 /* Return beyond the last contour index of a layer.
86 */
87 [[nodiscard]] ssize_t endLayer(ssize_t layerNr) const noexcept;
88
89 [[nodiscard]] std::vector<bezier_point> getbezier_pointsOfContour(ssize_t contourNr) const noexcept;
90
91 [[nodiscard]] std::vector<bezier_curve> getBeziersOfContour(ssize_t contourNr) const noexcept;
92
93 [[nodiscard]] std::vector<bezier_curve> getBeziers() const noexcept;
94
95 [[nodiscard]] std::pair<graphic_path, color> getLayer(ssize_t layerNr) const noexcept;
96
97 [[nodiscard]] color getColorOfLayer(ssize_t layerNr) const noexcept;
98
99 void setColorOfLayer(ssize_t layerNr, color fill_color) noexcept;
100
103 [[nodiscard]] bool isContourOpen() const noexcept;
104
108 void closeContour() noexcept;
109
112 [[nodiscard]] bool hasLayers() const noexcept;
113
116 [[nodiscard]] bool isLayerOpen() const noexcept;
117
121 void closeLayer(color fill_color) noexcept;
122
126 void optimizeLayers() noexcept;
127
131 [[nodiscard]] point2 currentPosition() const noexcept;
132
136 void moveTo(point2 position) noexcept;
137
141 void moveRelativeTo(vector2 direction) noexcept;
142
143 void lineTo(point2 position) noexcept;
144
145 void lineRelativeTo(vector2 direction) noexcept;
146
147 void quadraticCurveTo(point2 controlPosition, point2 position) noexcept;
148
153 void quadraticCurveRelativeTo(vector2 controlDirection, vector2 direction) noexcept;
154
155 void cubicCurveTo(point2 controlPosition1, point2 controlPosition2, point2 position) noexcept;
156
162 void cubicCurveRelativeTo(vector2 controlDirection1, vector2 controlDirection2, vector2 direction) noexcept;
163
175 void arcTo(float radius, point2 position) noexcept;
176
182 void addRectangle(aarectangle rectangle, corner_radii corners = corner_radii{0.0f, 0.0f, 0.0f, 0.0f}) noexcept;
183
188 void addCircle(point2 position, float radius) noexcept;
189
193 void addContour(std::vector<bezier_curve> const &contour) noexcept;
194
199 std::vector<bezier_point>::const_iterator const &begin,
200 std::vector<bezier_point>::const_iterator const &end) noexcept;
201
205 void addContour(std::vector<bezier_point> const &contour) noexcept;
206
209 void addPath(graphic_path const &path, color fill_color) noexcept;
210
214 graphic_path const &path,
215 color strokeColor,
216 float strokeWidth,
217 hi::line_join_style line_join_style = line_join_style::miter,
218 float tolerance = 0.05f) noexcept;
219
231 [[nodiscard]] graphic_path toStroke(
232 float strokeWidth = 1.0f,
233 line_join_style line_join_style = line_join_style::miter,
234 float tolerance = 0.05f) const noexcept;
235
238 [[nodiscard]] graphic_path centerScale(extent2 extent, float padding = 0.0) const noexcept;
239
240 graphic_path &operator+=(graphic_path const &rhs) noexcept;
241
242 [[nodiscard]] friend graphic_path operator+(graphic_path lhs, graphic_path const &rhs) noexcept
243 {
244 return lhs += rhs;
245 }
246
247 friend graphic_path operator*(geo::transformer auto const &lhs, graphic_path const &rhs) noexcept
248 {
249 auto rhs_ = rhs;
250 for (auto &&point : rhs_.points) {
251 point = lhs * point;
252 }
253 return rhs_;
254 }
255};
256
263void composit(pixel_map<sfloat_rgba16> &dst, hi::color color, graphic_path const &mask) noexcept;
264
270void composit(pixel_map<sfloat_rgba16> &dst, graphic_path const &mask) noexcept;
271
276void fill(pixel_map<sdf_r8> &dst, graphic_path const &path) noexcept;
277
278} // namespace hi::inline v1
Defines line_join_style.
line_join_style
The way two lines should be joined.
Definition line_join_style.hpp:18
STL namespace.
DOXYGEN BUG.
Definition algorithm.hpp:15
void composit(pixel_map< sfloat_rgba16 > &dst, hi::color color, graphic_path const &mask) noexcept
Composit color onto the destination image where the mask is solid.
Definition bezier_curve.hpp:28
Definition bezier_point.hpp:18
This is a RGBA floating point color.
Definition color.hpp:39
A rectangle / parallelogram in 3D space.
Definition rectangle.hpp:20
A 2D canvas of pixels.
Definition pixel_map.hpp:111
A path is a vector graphics object.
Definition graphic_path.hpp:29
void addCircle(point2 position, float radius) noexcept
Draw a circle.
std::vector< std::pair< ssize_t, color > > layerEndContours
An color and index into.
Definition graphic_path.hpp:40
void addPath(graphic_path const &path, color fill_color) noexcept
Add path and close 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:36
std::vector< bezier_point > points
A set of all bezier points describing all bezier curves, contours and layers.
Definition graphic_path.hpp:32
void clear() noexcept
Clear the path.
Definition graphic_path.hpp:44
void addContour(std::vector< bezier_curve > const &contour) noexcept
Contour with the given bezier curves.
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.
ssize_t numberOfContours() const noexcept
Return the number of closed contours.
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.
Definition transform.hpp:84
T clear(T... args)