diff options
Diffstat (limited to 'experimental/skotty/SkottyProperties.cpp')
-rw-r--r-- | experimental/skotty/SkottyProperties.cpp | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/experimental/skotty/SkottyProperties.cpp b/experimental/skotty/SkottyProperties.cpp index 241b659c9d..3029409f6c 100644 --- a/experimental/skotty/SkottyProperties.cpp +++ b/experimental/skotty/SkottyProperties.cpp @@ -10,9 +10,12 @@ #include "SkColor.h" #include "SkottyPriv.h" #include "SkPath.h" +#include "SkSGPath.h" #include "SkSGRect.h" #include "SkSGTransform.h" +#include <cmath> + namespace skotty { namespace { @@ -185,4 +188,36 @@ void CompositeTransform::apply() { fTransformNode->setMatrix(t); } +CompositePolyStar::CompositePolyStar(sk_sp<sksg::Path> wrapped_node, Type t) + : fPathNode(std::move(wrapped_node)) + , fType(t) {} + +void CompositePolyStar::apply() { + const auto count = SkScalarTruncToInt(fPointCount); + const auto arc = SK_ScalarPI * 2 / count; + + const auto pt_on_circle = [](const SkPoint& c, SkScalar r, SkScalar a) { + return SkPoint::Make(c.x() + r * std::cos(a), + c.y() + r * std::sin(a)); + }; + + // TODO: inner/outer "roundness"? + + SkPath poly; + + auto angle = SkDegreesToRadians(fRotation); + poly.moveTo(pt_on_circle(fPosition, fOuterRadius, angle)); + + for (int i = 0; i < count; ++i) { + if (fType == Type::kStar) { + poly.lineTo(pt_on_circle(fPosition, fInnerRadius, angle + arc * 0.5f)); + } + angle += arc; + poly.lineTo(pt_on_circle(fPosition, fOuterRadius, angle)); + } + + poly.close(); + fPathNode->setPath(poly); +} + } // namespace skotty |