• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/SkRRect.h"
9 #include "modules/skottie/src/Adapter.h"
10 #include "modules/skottie/src/SkottieJson.h"
11 #include "modules/skottie/src/SkottiePriv.h"
12 #include "modules/skottie/src/SkottieValue.h"
13 #include "modules/skottie/src/layers/shapelayer/ShapeLayer.h"
14 #include "modules/sksg/include/SkSGRect.h"
15 
16 namespace skottie {
17 namespace internal {
18 
19 namespace  {
20 
21 class EllipseGeometryAdapter final :
22         public DiscardableAdapterBase<EllipseGeometryAdapter, sksg::RRect> {
23 public:
EllipseGeometryAdapter(const skjson::ObjectValue & jellipse,const AnimationBuilder * abuilder)24     EllipseGeometryAdapter(const skjson::ObjectValue& jellipse,
25                            const AnimationBuilder* abuilder) {
26         this->node()->setDirection(ParseDefault(jellipse["d"], -1) == 3 ? SkPathDirection::kCCW
27                                                                         : SkPathDirection::kCW);
28         this->node()->setInitialPointIndex(1); // starting point: (Center, Top)
29 
30         this->bind(*abuilder, jellipse["s"], fSize);
31         this->bind(*abuilder, jellipse["p"], fPosition);
32     }
33 
34 private:
onSync()35     void onSync() override {
36         const auto bounds = SkRect::MakeXYWH(fPosition.x - fSize.x / 2,
37                                              fPosition.y - fSize.y / 2,
38                                              fSize.x, fSize.y);
39 
40         this->node()->setRRect(SkRRect::MakeOval(bounds));
41     }
42 
43     Vec2Value fSize     = {0,0},
44               fPosition = {0,0}; // center
45 };
46 
47 } // namespace
48 
AttachEllipseGeometry(const skjson::ObjectValue & jellipse,const AnimationBuilder * abuilder)49 sk_sp<sksg::GeometryNode> ShapeBuilder::AttachEllipseGeometry(const skjson::ObjectValue& jellipse,
50                                                               const AnimationBuilder* abuilder) {
51     return abuilder->attachDiscardableAdapter<EllipseGeometryAdapter>(jellipse, abuilder);
52 }
53 
54 } // namespace internal
55 } // namespace skottie
56