QmlMaterial 0.1.0
Loading...
Searching...
No Matches
rounded_polygon.hpp
1#pragma once
2
3#include <QtGui/QPainterPath>
4#include <QtGui/QTransform>
5#include <vector>
6#include <utility>
7#include "qml_material/export.hpp"
8
9namespace qml_material
10{
11
12struct CornerRounding {
13 qreal radius = 0;
14 qreal smoothing = 0;
15};
16
17struct QML_MATERIAL_API Cubic {
18 QPointF anchor0, control0, control1, anchor1;
19 QPointF point(qreal t) const;
20 std::pair<Cubic, Cubic> split(qreal t) const;
21 Cubic reversed() const;
22 Cubic transformed(const QTransform& transform) const;
23 static Cubic line(QPointF from, QPointF to);
24 static Cubic arc(QPointF center, QPointF from, QPointF to);
25};
26
30class QML_MATERIAL_API RoundedPolygon {
31public:
32 struct Vertex {
33 QPointF position;
34 CornerRounding rounding;
35 };
36 struct Feature {
37 std::vector<Cubic> cubics;
38 bool corner = false;
39 bool convex = false;
40 };
41
42 RoundedPolygon() = default;
43 explicit RoundedPolygon(const std::vector<Vertex>& vertices, QPointF center = {});
44 const std::vector<Feature>& features() const { return m_features; }
45 std::vector<Cubic> cubics() const;
46 QPointF center() const { return m_center; }
47 QPainterPath path() const;
48 RoundedPolygon transformed(const QTransform& transform) const;
49 RoundedPolygon normalized(bool radial = false) const;
50
51private:
52 std::vector<Feature> m_features;
53 QPointF m_center;
54};
55
56class QML_MATERIAL_API Morph {
57public:
58 Morph(const RoundedPolygon& from, const RoundedPolygon& to);
59 QPainterPath path(qreal progress) const;
60 std::vector<Cubic> cubics(qreal progress) const;
61 qsizetype curveCount() const { return qsizetype(m_match.size()); }
62
63private:
64 std::vector<std::pair<Cubic, Cubic>> m_match;
65};
66
67} // namespace qml_material
Definition rounded_polygon.hpp:30