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 "experimental/skrive/include/SkRive.h"
9
10 #include "experimental/skrive/src/reader/StreamReader.h"
11 #include "include/core/SkCanvas.h"
12
13 namespace skrive {
14 namespace internal {
15
16 template <typename T>
17 size_t parse_node(StreamReader*, T*);
18
19 template <>
parse_node(StreamReader * sr,Ellipse * node)20 size_t parse_node<Ellipse>(StreamReader* sr, Ellipse* node) {
21 const auto parent_id = parse_node<Node>(sr, node);
22
23 node->setWidth(sr->readFloat("width"));
24 node->setHeight(sr->readFloat("height"));
25
26 return parent_id;
27 }
28
29 } // namespace internal
30
onRevalidate()31 void Ellipse::onRevalidate() {
32 SkASSERT(this->hasInval());
33 }
34
onDraw(SkCanvas * canvas,const SkPaint & paint,SkPathFillType) const35 void Ellipse::onDraw(SkCanvas* canvas, const SkPaint& paint, SkPathFillType) const {
36 SkASSERT(!this->hasInval());
37
38 if (SkScalarNearlyEqual(fWidth, fHeight)) {
39 canvas->drawCircle(0, 0, fWidth * 0.5f, paint);
40 } else {
41 canvas->drawOval(SkRect::MakeXYWH(-fWidth * 0.5f, -fHeight * 0.5f, fWidth, fHeight), paint);
42 }
43 }
44
45 } // namespace skrive
46