Skia
2D Graphics Library
SkSGRect.h
Go to the documentation of this file.
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 SkSGRect_DEFINED
9 #define SkSGRect_DEFINED
10 
12 
13 #include "include/core/SkPath.h"
14 #include "include/core/SkRRect.h"
15 #include "include/core/SkRect.h"
16 
17 class SkCanvas;
18 class SkPaint;
19 
20 namespace sksg {
21 
25 class Rect final : public GeometryNode {
26 public:
27  static sk_sp<Rect> Make() { return sk_sp<Rect>(new Rect(SkRect::MakeEmpty())); }
28  static sk_sp<Rect> Make(const SkRect& r) { return sk_sp<Rect>(new Rect(r)); }
29 
30  SG_ATTRIBUTE(L, SkScalar, fRect.fLeft )
31  SG_ATTRIBUTE(T, SkScalar, fRect.fTop )
32  SG_ATTRIBUTE(R, SkScalar, fRect.fRight )
33  SG_ATTRIBUTE(B, SkScalar, fRect.fBottom)
34 
35  SG_MAPPED_ATTRIBUTE(Direction , SkPathDirection, fAttrContaier)
36  SG_MAPPED_ATTRIBUTE(InitialPointIndex, uint8_t , fAttrContaier)
37 
38 protected:
39  void onClip(SkCanvas*, bool antiAlias) const override;
40  void onDraw(SkCanvas*, const SkPaint&) const override;
41  bool onContains(const SkPoint&) const override;
42 
44  SkPath onAsPath() const override;
45 
46 private:
47  explicit Rect(const SkRect&);
48 
49  SkRect fRect;
50 
51  struct AttrContainer {
52  uint8_t fDirection : 1;
53  uint8_t fInitialPointIndex : 2;
54 
55  SkPathDirection getDirection() const {
56  return static_cast<SkPathDirection>(fDirection);
57  }
58  void setDirection(SkPathDirection dir) { fDirection = SkTo<uint8_t>(dir); }
59 
60  uint8_t getInitialPointIndex() const { return fInitialPointIndex; }
61  void setInitialPointIndex(uint8_t idx) { fInitialPointIndex = idx; }
62  };
63  AttrContainer fAttrContaier = { (int)SkPathDirection::kCW, 0 };
64 
65  using INHERITED = GeometryNode;
66 };
67 
71 class RRect final : public GeometryNode {
72 public:
73  static sk_sp<RRect> Make() { return sk_sp<RRect>(new RRect(SkRRect())); }
74  static sk_sp<RRect> Make(const SkRRect& rr) { return sk_sp<RRect>(new RRect(rr)); }
75 
76  SG_ATTRIBUTE(RRect, SkRRect, fRRect)
77 
78  SG_MAPPED_ATTRIBUTE(Direction , SkPathDirection, fAttrContaier)
79  SG_MAPPED_ATTRIBUTE(InitialPointIndex, uint8_t , fAttrContaier)
80 
81 protected:
82  void onClip(SkCanvas*, bool antiAlias) const override;
83  void onDraw(SkCanvas*, const SkPaint&) const override;
84  bool onContains(const SkPoint&) const override;
85 
87  SkPath onAsPath() const override;
88 
89 private:
90  explicit RRect(const SkRRect&);
91 
92  SkRRect fRRect;
93 
94  struct AttrContainer {
95  uint8_t fDirection : 1;
96  uint8_t fInitialPointIndex : 2;
97 
98  SkPathDirection getDirection() const {
99  return static_cast<SkPathDirection>(fDirection);
100  }
101  void setDirection(SkPathDirection dir) { fDirection = SkTo<uint8_t>(dir); }
102 
103  uint8_t getInitialPointIndex() const { return fInitialPointIndex; }
104  void setInitialPointIndex(uint8_t idx) { fInitialPointIndex = idx; }
105  };
106  AttrContainer fAttrContaier = { (int)SkPathDirection::kCW, 0 };
107 
108  using INHERITED = GeometryNode;
109 };
110 
111 } // namespace sksg
112 
113 #endif // SkSGRect_DEFINED
SkPathDirection
Definition: SkPathTypes.h:34
@ kCW
clockwise direction for adding closed contours
#define SG_ATTRIBUTE(attr_name, attr_type, attr_container)
Definition: SkSGNode.h:99
#define SG_MAPPED_ATTRIBUTE(attr_name, attr_type, attr_container)
Definition: SkSGNode.h:112
float SkScalar
Definition: SkScalar.h:14
SkCanvas provides an interface for drawing, and how the drawing is clipped and transformed.
Definition: SkCanvas.h:99
SkMatrix holds a 3x3 matrix for transforming coordinates.
Definition: SkMatrix.h:53
SkPaint controls options applied when drawing.
Definition: SkPaint.h:44
SkPath contain geometry.
Definition: SkPath.h:58
SkRRect describes a rounded rectangle with a bounds and a pair of radii for each corner.
Definition: SkRRect.h:35
Shared pointer class to wrap classes that support a ref()/unref() interface.
Definition: SkRefCnt.h:220
Base class for nodes which provide 'geometry' (as opposed to paint) for drawing.
Definition: SkSGGeometryNode.h:25
Receiver for invalidation events.
Definition: SkSGInvalidationController.h:25
Concrete Geometry node, wrapping an SkRRect.
Definition: SkSGRect.h:71
bool onContains(const SkPoint &) const override
void onDraw(SkCanvas *, const SkPaint &) const override
void onClip(SkCanvas *, bool antiAlias) const override
static sk_sp< RRect > Make(const SkRRect &rr)
Definition: SkSGRect.h:74
static sk_sp< RRect > Make()
Definition: SkSGRect.h:73
SkRect onRevalidate(InvalidationController *, const SkMatrix &) override
SkPath onAsPath() const override
Concrete Geometry node, wrapping an SkRect.
Definition: SkSGRect.h:25
SkRect onRevalidate(InvalidationController *, const SkMatrix &) override
SkPath onAsPath() const override
void onClip(SkCanvas *, bool antiAlias) const override
static sk_sp< Rect > Make()
Definition: SkSGRect.h:27
bool onContains(const SkPoint &) const override
void onDraw(SkCanvas *, const SkPaint &) const override
static sk_sp< Rect > Make(const SkRect &r)
Definition: SkSGRect.h:28
Definition: Skottie.h:30
SkRect holds four float coordinates describing the upper and lower bounds of a rectangle.
Definition: SkRect.h:582
static constexpr SkRect MakeEmpty()
Returns constructed SkRect set to (0, 0, 0, 0).
Definition: SkRect.h:595