Flutter Engine
The Flutter Engine
Ellipse.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 EllipseGeometryAdapter final :
30 public DiscardableAdapterBase<EllipseGeometryAdapter, sksg::RRect> {
31public:
32 EllipseGeometryAdapter(const skjson::ObjectValue& jellipse,
33 const AnimationBuilder* abuilder) {
34 this->node()->setDirection(ParseDefault(jellipse["d"], -1) == 3 ? SkPathDirection::kCCW
36 this->node()->setInitialPointIndex(1); // starting point: (Center, Top)
37
38 this->bind(*abuilder, jellipse["s"], fSize);
39 this->bind(*abuilder, jellipse["p"], fPosition);
40 }
41
42private:
43 void onSync() override {
44 const auto bounds = SkRect::MakeXYWH(fPosition.x - fSize.x / 2,
45 fPosition.y - fSize.y / 2,
46 fSize.x, fSize.y);
47
48 this->node()->setRRect(SkRRect::MakeOval(bounds));
49 }
50
51 Vec2Value fSize = {0,0},
52 fPosition = {0,0}; // center
53};
54
55} // namespace
56
58 const AnimationBuilder* abuilder) {
59 return abuilder->attachDiscardableAdapter<EllipseGeometryAdapter>(jellipse, abuilder);
60}
61
62} // namespace internal
63} // namespace skottie
static SkRRect MakeOval(const SkRect &oval)
Definition: SkRRect.h:162
void attachDiscardableAdapter(sk_sp< T > adapter) const
Definition: SkottiePriv.h:139
static sk_sp< sksg::GeometryNode > AttachEllipseGeometry(const skjson::ObjectValue &, const AnimationBuilder *)
Definition: Ellipse.cpp:57
Optional< SkRect > bounds
Definition: SkRecords.h:189
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