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"
10#include "geometry/axis_aligned_rectangle.hpp"
11#include "geometry/transform.hpp"
12#include "rapid/sfloat_rgba16.hpp"
13#include "rapid/sdf_r8.hpp"
14#include <vector>
15
16namespace tt {
17
18struct bezier_curve;
19template<typename T>
20class pixel_map;
21
32
36
40
43 void clear() noexcept
44 {
45 points.clear();
46 contourEndPoints.clear();
47 layerEndContours.clear();
48 }
49
52 [[nodiscard]] ssize_t numberOfContours() const noexcept;
53
56 [[nodiscard]] ssize_t numberOfLayers() const noexcept;
57
60 [[nodiscard]] bool allLayersHaveSameColor() const noexcept;
61
64 [[nodiscard]] aarectangle boundingBox() const noexcept;
65
70 void tryRemoveLayers() noexcept;
71
74 [[nodiscard]] std::vector<bezier_point>::const_iterator beginContour(ssize_t contourNr) const noexcept;
75
76 /* Return and end-iterator beyond the end point of a contour.
77 */
78 [[nodiscard]] std::vector<bezier_point>::const_iterator endContour(ssize_t contourNr) const noexcept;
79
80 /* Return the first contour index of a layer.
81 */
82 [[nodiscard]] ssize_t beginLayer(ssize_t layerNr) const noexcept;
83
84 /* Return beyond the last contour index of a layer.
85 */
86 [[nodiscard]] ssize_t endLayer(ssize_t layerNr) const noexcept;
87
88 [[nodiscard]] std::vector<bezier_point> getbezier_pointsOfContour(ssize_t contourNr) const noexcept;
89
90 [[nodiscard]] std::vector<bezier_curve> getBeziersOfContour(ssize_t contourNr) const noexcept;
91
92 [[nodiscard]] std::vector<bezier_curve> getBeziers() const noexcept;
93
94 [[nodiscard]] std::pair<graphic_path, color> getLayer(ssize_t layerNr) const noexcept;
95
96 [[nodiscard]] color getColorOfLayer(ssize_t layerNr) const noexcept;
97
98 void setColorOfLayer(ssize_t layerNr, color fill_color) noexcept;
99
102 [[nodiscard]] bool isContourOpen() const noexcept;
103
107 void closeContour() noexcept;
108
111 [[nodiscard]] bool hasLayers() const noexcept;
112
115 [[nodiscard]] bool isLayerOpen() const noexcept;
116
120 void closeLayer(color fill_color) noexcept;
121
125 void optimizeLayers() noexcept;
126
130 [[nodiscard]] point2 currentPosition() const noexcept;
131
135 void moveTo(point2 position) noexcept;
136
140 void moveRelativeTo(vector2 direction) noexcept;
141
142 void lineTo(point2 position) noexcept;
143
144 void lineRelativeTo(vector2 direction) noexcept;
145
146 void quadraticCurveTo(point2 controlPosition, point2 position) noexcept;
147
152 void quadraticCurveRelativeTo(vector2 controlDirection, vector2 direction) noexcept;
153
154 void cubicCurveTo(point2 controlPosition1, point2 controlPosition2, point2 position) noexcept;
155
161 void cubicCurveRelativeTo(vector2 controlDirection1, vector2 controlDirection2, vector2 direction) noexcept;
162
174 void arcTo(float radius, point2 position) noexcept;
175
181 void addRectangle(aarectangle rectangle, corner_shapes corners = corner_shapes{0.0f, 0.0f, 0.0f, 0.0f}) noexcept;
182
187 void addCircle(point2 position, float radius) noexcept;
188
192 void addContour(std::vector<bezier_curve> const &contour) noexcept;
193
198 std::vector<bezier_point>::const_iterator const &begin,
199 std::vector<bezier_point>::const_iterator const &end) noexcept;
200
204 void addContour(std::vector<bezier_point> const &contour) noexcept;
205
208 void addPath(graphic_path const &path, color fill_color) noexcept;
209
213 graphic_path const &path,
214 color strokeColor,
215 float strokeWidth,
216 LineJoinStyle lineJoinStyle = LineJoinStyle::Miter,
217 float tolerance = 0.05f) noexcept;
218
230 [[nodiscard]] graphic_path toStroke(
231 float strokeWidth = 1.0f,
232 LineJoinStyle lineJoinStyle = LineJoinStyle::Miter,
233 float tolerance = 0.05f) const noexcept;
234
237 [[nodiscard]] graphic_path centerScale(extent2 extent, float padding = 0.0) const noexcept;
238
239 graphic_path &operator+=(graphic_path const &rhs) noexcept;
240
241 [[nodiscard]] friend graphic_path operator+(graphic_path lhs, graphic_path const &rhs) noexcept
242 {
243 return lhs += rhs;
244 }
245
246 friend graphic_path operator*(geo::transformer auto const &lhs, graphic_path const &rhs) noexcept
247 {
248 auto rhs_ = rhs;
249 for (auto &&point : rhs_.points) {
250 point = lhs * point;
251 }
252 return rhs_;
253 }
254};
255
262void composit(pixel_map<sfloat_rgba16> &dst, tt::color color, graphic_path const &mask) noexcept;
263
269void composit(pixel_map<sfloat_rgba16> &dst, graphic_path const &mask) noexcept;
270
275void fill(pixel_map<sdf_r8> &dst, graphic_path const &path) noexcept;
276
277} // namespace tt
STL namespace.
Definition bezier_curve.hpp:29
Definition bezier_point.hpp:18
This is a RGBA floating point color.
Definition color.hpp:36
Class which represents an axis-aligned rectangle.
Definition axis_aligned_rectangle.hpp:20
Definition corner_shapes.hpp:9
Class which represents an rectangle.
Definition rectangle.hpp:16
A path is a vector graphics object.
Definition graphic_path.hpp:28
bool hasLayers() const noexcept
This path has layers.
void quadraticCurveRelativeTo(vector2 controlDirection, vector2 direction) noexcept
Draw curve from the current position to the new direction.
std::vector< std::pair< ssize_t, color > > layerEndContours
An color and index into.
Definition graphic_path.hpp:39
std::vector< bezier_point >::const_iterator beginContour(ssize_t contourNr) const noexcept
Return an iterator to the start point of a contour.
void optimizeLayers() noexcept
Optimize layers.
ssize_t numberOfLayers() const noexcept
Return the number of closed layers.
void addContour(std::vector< bezier_point > const &contour) noexcept
Curve with the given bezier curve.
graphic_path toStroke(float strokeWidth=1.0f, LineJoinStyle lineJoinStyle=LineJoinStyle::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 moveTo(point2 position) noexcept
Start a new contour at position.
void arcTo(float radius, point2 position) noexcept
Draw an circular arc.
void addPath(graphic_path const &path, color fill_color) noexcept
Add path and close layer.
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< ssize_t > contourEndPoints
An index into.
Definition graphic_path.hpp:35
void addCircle(point2 position, float radius) noexcept
Draw a circle.
void addStroke(graphic_path const &path, color strokeColor, float strokeWidth, LineJoinStyle lineJoinStyle=LineJoinStyle::Miter, float tolerance=0.05f) noexcept
Stroke a path and close layer.
void closeLayer(color fill_color) noexcept
Close current contour.
aarectangle boundingBox() const noexcept
Calculate bounding box.
void closeContour() noexcept
Close current contour.
bool isLayerOpen() const noexcept
Return true if there is an open layer.
ssize_t numberOfContours() const noexcept
Return the number of closed contours.
void moveRelativeTo(vector2 direction) noexcept
Start a new contour relative to current position.
void addRectangle(aarectangle rectangle, corner_shapes corners=corner_shapes{0.0f, 0.0f, 0.0f, 0.0f}) noexcept
Draw a rectangle.
void tryRemoveLayers() noexcept
Try to move the layers in a path.
void clear() noexcept
Clear the path.
Definition graphic_path.hpp:43
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.
std::vector< bezier_point > points
A set of all bezier points describing all bezier curves, contours and layers.
Definition graphic_path.hpp:31
bool allLayersHaveSameColor() const noexcept
Check if all layers have the same color.
graphic_path centerScale(extent2 extent, float padding=0.0) const noexcept
Center and scale a path inside the extent with padding.
void cubicCurveRelativeTo(vector2 controlDirection1, vector2 controlDirection2, vector2 direction) noexcept
Draw curve from the current position to the new direction.
Definition transform.hpp:83
T fill(T... args)