• 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 "experimental/skrive/include/SkRive.h"
9 
10 #include "experimental/skrive/src/reader/StreamReader.h"
11 
12 #include <tuple>
13 
14 namespace skrive {
15 namespace internal {
16 
17 template <typename T>
18 size_t parse_node(StreamReader*, T*);
19 
20 template <>
parse_node(StreamReader * sr,Node * node)21 size_t parse_node<Node>(StreamReader* sr, Node* node) {
22     const auto parent_id = parse_node<TransformableComponent>(sr, node);
23 
24     node->setCollapsedVisibility(sr->readBool("isCollapsed"));
25 
26     if (sr->openArray("clips")) {
27         const auto count = sr->readLength8();
28 
29         SkDebugf(".. %d clips\n", count);
30 
31         for (size_t i = 0; i < count; ++i) {
32             if (sr->openObject("clip")) {
33                 /*const auto clip_id   =*/ sr->readUInt16("node");
34                 /*const auto intersect =*/ sr->readBool("intersect");
35 
36                 // TODO: actually use clips
37                 sr->closeObject();
38             }
39         }
40 
41         sr->closeArray();
42     }
43 
44     return parent_id;
45 }
46 
47 }  // namespace internal
48 
addChild(sk_sp<Component> child)49 void Node::addChild(sk_sp<Component> child) {
50     child->fParent = this;
51     fChildren.push_back(std::move(child));
52     this->invalidate();
53 }
54 
onRevalidate()55 void Node::onRevalidate() {
56     SkASSERT(this->hasInval());
57 
58     for (const auto& child : fChildren) {
59         if (child) {
60             child->revalidate();
61         }
62     }
63 }
64 
onRender(SkCanvas * canvas) const65 void Node::onRender(SkCanvas* canvas) const {
66     SkASSERT(!this->hasInval());
67 
68     TransformableComponent::ScopedTransformContext stc(this, canvas);
69 
70     // TODO: draw order?
71     for (const auto& child : this->children()) {
72         child->render(canvas);
73     }
74 }
75 
76 
77 }  // namespace skrive
78