Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
SkSGRect.cpp
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
9
12#include "include/core/SkPath.h"
15
16class SkMatrix;
17
18namespace sksg {
19
20Rect::Rect(const SkRect& rect) : fRect(rect) {}
21
22void Rect::onClip(SkCanvas* canvas, bool antiAlias) const {
23 canvas->clipRect(fRect, SkClipOp::kIntersect, antiAlias);
24}
25
26void Rect::onDraw(SkCanvas* canvas, const SkPaint& paint) const {
27 canvas->drawRect(fRect, paint);
28}
29
30bool Rect::onContains(const SkPoint& p) const {
31 return fRect.contains(p.x(), p.y());
32}
33
34SkRect Rect::onRevalidate(InvalidationController*, const SkMatrix&) {
35 SkASSERT(this->hasInval());
36
37 return fRect;
38}
39
40SkPath Rect::onAsPath() const {
41 return SkPath::Rect(fRect, this->getDirection(), this->getInitialPointIndex());
42}
43
44RRect::RRect(const SkRRect& rr) : fRRect(rr) {}
45
46void RRect::onClip(SkCanvas* canvas, bool antiAlias) const {
47 canvas->clipRRect(fRRect, SkClipOp::kIntersect, antiAlias);
48}
49
50void RRect::onDraw(SkCanvas* canvas, const SkPaint& paint) const {
51 canvas->drawRRect(fRRect, paint);
52}
53
54bool 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
71 SkASSERT(this->hasInval());
72
73 return fRRect.getBounds();
74}
75
77 return SkPath::RRect(fRRect, this->getDirection(), this->getInitialPointIndex());
78}
79
80} // namespace sksg
SkRRect fRRect
SkRect fRect
#define SkASSERT(cond)
Definition SkAssert.h:116
#define SK_ScalarNearlyZero
Definition SkScalar.h:99
void drawRect(const SkRect &rect, const SkPaint &paint)
void clipRect(const SkRect &rect, SkClipOp op, bool doAntiAlias)
void drawRRect(const SkRRect &rrect, const SkPaint &paint)
void clipRRect(const SkRRect &rrect, SkClipOp op, bool doAntiAlias)
static SkPath RRect(const SkRRect &, SkPathDirection dir=SkPathDirection::kCW)
Definition SkPath.cpp:3534
static SkPath Rect(const SkRect &, SkPathDirection=SkPathDirection::kCW, unsigned startIndex=0)
Definition SkPath.cpp:3518
const SkRect & rect() const
Definition SkRRect.h:264
bool isRect() const
Definition SkRRect.h:84
bool contains(const SkRect &rect) const
Definition SkRRect.cpp:360
const SkRect & getBounds() const
Definition SkRRect.h:279
bool hasInval() const
Definition SkSGNode.h:60
bool onContains(const SkPoint &) const override
Definition SkSGRect.cpp:54
void onDraw(SkCanvas *, const SkPaint &) const override
Definition SkSGRect.cpp:50
void onClip(SkCanvas *, bool antiAlias) const override
Definition SkSGRect.cpp:46
SkRect onRevalidate(InvalidationController *, const SkMatrix &) override
Definition SkSGRect.cpp:70
SkPath onAsPath() const override
Definition SkSGRect.cpp:76
const Paint & paint
sk_sp< SkBlender > blender SkRect rect
Definition SkRecords.h:350
Definition Skottie.h:32
bool contains(SkScalar x, SkScalar y) const
Definition extension.cpp:19
static constexpr SkRect MakeLTRB(float l, float t, float r, float b)
Definition SkRect.h:646