Flutter Engine
The Flutter Engine
Rectangle.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2020 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
10#include "include/core/SkRect.h"
18#include "src/utils/SkJSON.h"
19
20namespace sksg {
21class GeometryNode;
22}
23
24namespace skottie {
25namespace internal {
26
27namespace {
28
29class RectangleGeometryAdapter final :
30 public DiscardableAdapterBase<RectangleGeometryAdapter, sksg::RRect> {
31public:
32 RectangleGeometryAdapter(const skjson::ObjectValue& jrect,
33 const AnimationBuilder* abuilder) {
34 this->node()->setDirection(ParseDefault(jrect["d"], -1) == 3 ? SkPathDirection::kCCW
36 this->node()->setInitialPointIndex(2); // starting point: (Right, Top - radius.y)
37
38 this->bind(*abuilder, jrect["s"], fSize );
39 this->bind(*abuilder, jrect["p"], fPosition );
40 this->bind(*abuilder, jrect["r"], fRoundness);
41 }
42
43private:
44 void onSync() override {
45 const auto bounds = SkRect::MakeXYWH(fPosition.x - fSize.x / 2,
46 fPosition.y - fSize.y / 2,
47 fSize.x, fSize.y);
48
49 this->node()->setRRect(SkRRect::MakeRectXY(bounds, fRoundness, fRoundness));
50 }
51
52 Vec2Value fSize = {0,0},
53 fPosition = {0,0}; // center
54 ScalarValue fRoundness = 0;
55};
56
57} // namespace
58
60 const AnimationBuilder* abuilder) {
61 return abuilder->attachDiscardableAdapter<RectangleGeometryAdapter>(jrect, abuilder);
62}
63
64} // namespace internal
65} // namespace skottie
static SkRRect MakeRectXY(const SkRect &rect, SkScalar xRad, SkScalar yRad)
Definition: SkRRect.h:180
void attachDiscardableAdapter(sk_sp< T > adapter) const
Definition: SkottiePriv.h:139
static sk_sp< sksg::GeometryNode > AttachRRectGeometry(const skjson::ObjectValue &, const AnimationBuilder *)
Definition: Rectangle.cpp:59
Optional< SkRect > bounds
Definition: SkRecords.h:189
SkScalar ScalarValue
Definition: SkottieValue.h:22
SkV2 Vec2Value
Definition: SkottieValue.h:23
T ParseDefault(const skjson::Value &v, const T &defaultValue)
Definition: SkottieJson.h:23
Definition: Skottie.h:32
static constexpr SkRect MakeXYWH(float x, float y, float w, float h)
Definition: SkRect.h:659