/src/skia/modules/skottie/src/layers/shapelayer/Rectangle.cpp
Line | Count | Source |
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 | | |
8 | | #include "include/core/SkPathTypes.h" |
9 | | #include "include/core/SkRRect.h" |
10 | | #include "include/core/SkRect.h" |
11 | | #include "include/core/SkRefCnt.h" |
12 | | #include "modules/skottie/src/Adapter.h" |
13 | | #include "modules/skottie/src/SkottieJson.h" |
14 | | #include "modules/skottie/src/SkottiePriv.h" |
15 | | #include "modules/skottie/src/SkottieValue.h" |
16 | | #include "modules/skottie/src/layers/shapelayer/ShapeLayer.h" |
17 | | #include "modules/sksg/include/SkSGRect.h" |
18 | | #include "src/utils/SkJSON.h" |
19 | | |
20 | | namespace sksg { |
21 | | class GeometryNode; |
22 | | } |
23 | | |
24 | | namespace skottie { |
25 | | namespace internal { |
26 | | |
27 | | namespace { |
28 | | |
29 | | class RectangleGeometryAdapter final : |
30 | | public DiscardableAdapterBase<RectangleGeometryAdapter, sksg::RRect> { |
31 | | public: |
32 | | RectangleGeometryAdapter(const skjson::ObjectValue& jrect, |
33 | 77.4k | const AnimationBuilder* abuilder) { |
34 | 77.4k | this->node()->setDirection(ParseDefault(jrect["d"], -1) == 3 ? SkPathDirection::kCCW |
35 | 77.4k | : SkPathDirection::kCW); |
36 | 77.4k | this->node()->setInitialPointIndex(2); // starting point: (Right, Top - radius.y) |
37 | | |
38 | 77.4k | this->bind(*abuilder, jrect["s"], fSize ); |
39 | 77.4k | this->bind(*abuilder, jrect["p"], fPosition ); |
40 | 77.4k | this->bind(*abuilder, jrect["r"], fRoundness); |
41 | 77.4k | } |
42 | | |
43 | | private: |
44 | 77.3k | void onSync() override { |
45 | 77.3k | const auto bounds = SkRect::MakeXYWH(fPosition.x - fSize.x / 2, |
46 | 77.3k | fPosition.y - fSize.y / 2, |
47 | 77.3k | fSize.x, fSize.y); |
48 | | |
49 | 77.3k | this->node()->setRRect(SkRRect::MakeRectXY(bounds, fRoundness, fRoundness)); |
50 | 77.3k | } |
51 | | |
52 | | Vec2Value fSize = {0,0}, |
53 | | fPosition = {0,0}; // center |
54 | | ScalarValue fRoundness = 0; |
55 | | }; |
56 | | |
57 | | } // namespace |
58 | | |
59 | | sk_sp<sksg::GeometryNode> ShapeBuilder::AttachRRectGeometry(const skjson::ObjectValue& jrect, |
60 | 77.4k | const AnimationBuilder* abuilder) { |
61 | 77.4k | return abuilder->attachDiscardableAdapter<RectangleGeometryAdapter>(jrect, abuilder); |
62 | 77.4k | } |
63 | | |
64 | | } // namespace internal |
65 | | } // namespace skottie |