• 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 #include "modules/sksg/include/SkSGRect.h"
9 
10 #include "include/core/SkCanvas.h"
11 #include "include/core/SkPaint.h"
12 #include "include/core/SkPath.h"
13 
14 namespace sksg {
15 
Rect(const SkRect & rect)16 Rect::Rect(const SkRect& rect) : fRect(rect) {}
17 
onClip(SkCanvas * canvas,bool antiAlias) const18 void Rect::onClip(SkCanvas* canvas, bool antiAlias) const {
19     canvas->clipRect(fRect, SkClipOp::kIntersect, antiAlias);
20 }
21 
onDraw(SkCanvas * canvas,const SkPaint & paint) const22 void Rect::onDraw(SkCanvas* canvas, const SkPaint& paint) const {
23     canvas->drawRect(fRect, paint);
24 }
25 
onContains(const SkPoint & p) const26 bool Rect::onContains(const SkPoint& p) const {
27     return fRect.contains(p.x(), p.y());
28 }
29 
onRevalidate(InvalidationController *,const SkMatrix &)30 SkRect Rect::onRevalidate(InvalidationController*, const SkMatrix&) {
31     SkASSERT(this->hasInval());
32 
33     return fRect;
34 }
35 
onAsPath() const36 SkPath Rect::onAsPath() const {
37     SkPath path;
38     path.addRect(fRect, this->getDirection(), this->getInitialPointIndex());
39     return path;
40 }
41 
RRect(const SkRRect & rr)42 RRect::RRect(const SkRRect& rr) : fRRect(rr) {}
43 
onClip(SkCanvas * canvas,bool antiAlias) const44 void RRect::onClip(SkCanvas* canvas, bool antiAlias) const {
45     canvas->clipRRect(fRRect, SkClipOp::kIntersect, antiAlias);
46 }
47 
onDraw(SkCanvas * canvas,const SkPaint & paint) const48 void RRect::onDraw(SkCanvas* canvas, const SkPaint& paint) const {
49     canvas->drawRRect(fRRect, paint);
50 }
51 
onContains(const SkPoint & p) const52 bool RRect::onContains(const SkPoint& p) const {
53     if (!fRRect.rect().contains(p.x(), p.y())) {
54         return false;
55     }
56 
57     if (fRRect.isRect()) {
58         return true;
59     }
60 
61     // TODO: no SkRRect::contains(x, y)
62     return fRRect.contains(SkRect::MakeLTRB(p.x() - SK_ScalarNearlyZero,
63                                             p.y() - SK_ScalarNearlyZero,
64                                             p.x() + SK_ScalarNearlyZero,
65                                             p.y() + SK_ScalarNearlyZero));
66 }
67 
onRevalidate(InvalidationController *,const SkMatrix &)68 SkRect RRect::onRevalidate(InvalidationController*, const SkMatrix&) {
69     SkASSERT(this->hasInval());
70 
71     return fRRect.getBounds();
72 }
73 
onAsPath() const74 SkPath RRect::onAsPath() const {
75     SkPath path;
76     path.addRRect(fRRect, this->getDirection(), this->getInitialPointIndex());
77     return path;
78 }
79 
80 } // namespace sksg
81