• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2017 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 #ifndef SkSGGroup_DEFINED
9 #define SkSGGroup_DEFINED
10 
11 #include "modules/sksg/include/SkSGRenderNode.h"
12 
13 #include <vector>
14 
15 namespace sksg {
16 
17 /**
18  * Concrete node, grouping together multiple descendants.
19  */
20 class Group : public RenderNode {
21 public:
Make()22     static sk_sp<Group> Make() {
23         return sk_sp<Group>(new Group(std::vector<sk_sp<RenderNode>>()));
24     }
25 
Make(std::vector<sk_sp<RenderNode>> children)26     static sk_sp<Group> Make(std::vector<sk_sp<RenderNode>> children) {
27         return sk_sp<Group>(new Group(std::move(children)));
28     }
29 
30     void addChild(sk_sp<RenderNode>);
31     void removeChild(const sk_sp<RenderNode>&);
32 
size()33     size_t size() const { return fChildren.size(); }
empty()34     bool  empty() const { return fChildren.empty(); }
35     void  clear();
36 
37 protected:
38     explicit Group(std::vector<sk_sp<RenderNode>>);
39     ~Group() override;
40 
41     void onRender(SkCanvas*, const RenderContext*) const override;
42     const RenderNode* onNodeAt(const SkPoint&)     const override;
43 
44     SkRect onRevalidate(InvalidationController*, const SkMatrix&) override;
45 
46 private:
47     std::vector<sk_sp<RenderNode>> fChildren;
48 
49     typedef RenderNode INHERITED;
50 };
51 
52 } // namespace sksg
53 
54 #endif // SkSGGroup_DEFINED
55