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