blob: 091751b227ab8a6ab12fa88879d8be8d498cd1d1 [file] [log] [blame]
Florin Malita4aa44412017-12-19 12:21:02 -05001/*
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 "SkSGRect.h"
9
10#include "SkCanvas.h"
11#include "SkPaint.h"
Florin Malitae6345d92018-01-03 23:37:54 -050012#include "SkPath.h"
Florin Malita4aa44412017-12-19 12:21:02 -050013
14namespace sksg {
15
16Rect::Rect(const SkRect& rect) : fRect(rect) {}
17
Florin Malita38ea40e2018-01-29 16:31:14 -050018void Rect::onClip(SkCanvas* canvas, bool antiAlias) const {
19 canvas->clipRect(fRect, SkClipOp::kIntersect, antiAlias);
20}
21
Florin Malita4aa44412017-12-19 12:21:02 -050022void Rect::onDraw(SkCanvas* canvas, const SkPaint& paint) const {
23 canvas->drawRect(fRect, paint);
24}
25
Florin Malitaeb46bd82019-02-12 09:33:21 -050026bool Rect::onContains(const SkPoint& p) const {
27 return fRect.contains(p.x(), p.y());
28}
29
Florin Malitac14f1442018-01-05 11:32:31 -050030SkRect Rect::onRevalidate(InvalidationController*, const SkMatrix&) {
31 SkASSERT(this->hasInval());
Florin Malitac75e2402018-01-03 16:17:29 -050032
Florin Malitac14f1442018-01-05 11:32:31 -050033 return fRect;
Florin Malita4aa44412017-12-19 12:21:02 -050034}
35
Florin Malitae6345d92018-01-03 23:37:54 -050036SkPath Rect::onAsPath() const {
37 SkPath path;
Florin Malitac91527f2019-01-22 12:19:51 -050038 path.addRect(fRect, this->getDirection(), this->getInitialPointIndex());
Florin Malitae6345d92018-01-03 23:37:54 -050039 return path;
40}
41
Florin Malita2e1d7e22018-01-02 10:40:00 -050042RRect::RRect(const SkRRect& rr) : fRRect(rr) {}
43
Florin Malita38ea40e2018-01-29 16:31:14 -050044void RRect::onClip(SkCanvas* canvas, bool antiAlias) const {
45 canvas->clipRRect(fRRect, SkClipOp::kIntersect, antiAlias);
46}
47
Florin Malita2e1d7e22018-01-02 10:40:00 -050048void RRect::onDraw(SkCanvas* canvas, const SkPaint& paint) const {
49 canvas->drawRRect(fRRect, paint);
50}
51
Florin Malitaeb46bd82019-02-12 09:33:21 -050052bool 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
Florin Malitac14f1442018-01-05 11:32:31 -050068SkRect RRect::onRevalidate(InvalidationController*, const SkMatrix&) {
69 SkASSERT(this->hasInval());
Florin Malitac75e2402018-01-03 16:17:29 -050070
Florin Malitac14f1442018-01-05 11:32:31 -050071 return fRRect.getBounds();
Florin Malita2e1d7e22018-01-02 10:40:00 -050072}
73
Florin Malitae6345d92018-01-03 23:37:54 -050074SkPath RRect::onAsPath() const {
75 SkPath path;
Florin Malitac91527f2019-01-22 12:19:51 -050076 path.addRRect(fRRect, this->getDirection(), this->getInitialPointIndex());
Florin Malitae6345d92018-01-03 23:37:54 -050077 return path;
78}
79
Florin Malita4aa44412017-12-19 12:21:02 -050080} // namespace sksg