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,Rectangle * node)20 size_t parse_node<Rectangle>(StreamReader* sr, Rectangle* 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 node->setRadius(sr->readFloat("cornerRadius"));
26
27 return parent_id;
28 }
29
30 } // namespace internal
31
onRevalidate()32 void Rectangle::onRevalidate() {
33 SkASSERT(this->hasInval());
34 }
35
onDraw(SkCanvas * canvas,const SkPaint & paint,SkPathFillType) const36 void Rectangle::onDraw(SkCanvas* canvas, const SkPaint& paint, SkPathFillType) const {
37 SkASSERT(!this->hasInval());
38
39 const auto rect = SkRect::MakeXYWH(-fWidth * 0.5f, -fHeight * 0.5f, fWidth, fHeight);
40
41 canvas->drawRect(rect, paint);
42 }
43
44 } // namespace skrive
45