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