2012-11-29 13:24:55 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2012 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef SkRRect_DEFINED
|
|
|
|
#define SkRRect_DEFINED
|
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkPoint.h"
|
|
|
|
#include "include/core/SkRect.h"
|
2012-11-29 13:24:55 +00:00
|
|
|
|
2012-12-12 20:48:18 +00:00
|
|
|
class SkPath;
|
2013-11-05 15:54:42 +00:00
|
|
|
class SkMatrix;
|
2020-09-28 15:39:09 +00:00
|
|
|
class SkString;
|
2012-12-12 20:48:18 +00:00
|
|
|
|
2012-11-29 13:24:55 +00:00
|
|
|
/** \class SkRRect
|
2018-07-13 12:21:59 +00:00
|
|
|
SkRRect describes a rounded rectangle with a bounds and a pair of radii for each corner.
|
2018-08-10 17:11:06 +00:00
|
|
|
The bounds and radii can be set so that SkRRect describes: a rectangle with sharp corners;
|
|
|
|
a circle; an oval; or a rectangle with one or more rounded corners.
|
2012-11-29 13:24:55 +00:00
|
|
|
|
2018-07-13 12:21:59 +00:00
|
|
|
SkRRect allows implementing CSS properties that describe rounded corners.
|
|
|
|
SkRRect may have up to eight different radii, one for each axis on each of its four
|
|
|
|
corners.
|
2012-11-29 13:24:55 +00:00
|
|
|
|
2018-07-13 12:21:59 +00:00
|
|
|
SkRRect may modify the provided parameters when initializing bounds and radii.
|
2018-08-10 17:11:06 +00:00
|
|
|
If either axis radii is zero or less: radii are stored as zero; corner is square.
|
2018-07-13 12:21:59 +00:00
|
|
|
If corner curves overlap, radii are proportionally reduced to fit within bounds.
|
2012-11-29 13:24:55 +00:00
|
|
|
*/
|
|
|
|
class SK_API SkRRect {
|
|
|
|
public:
|
2018-07-13 12:21:59 +00:00
|
|
|
|
|
|
|
/** Initializes bounds at (0, 0), the origin, with zero width and height.
|
|
|
|
Initializes corner radii to (0, 0), and sets type of kEmpty_Type.
|
|
|
|
|
|
|
|
@return empty SkRRect
|
|
|
|
*/
|
2017-12-15 16:31:05 +00:00
|
|
|
SkRRect() = default;
|
|
|
|
|
2018-07-13 12:21:59 +00:00
|
|
|
/** Initializes to copy of rrect bounds and corner radii.
|
|
|
|
|
|
|
|
@param rrect bounds and corner to copy
|
|
|
|
@return copy of rrect
|
|
|
|
*/
|
2018-06-12 20:49:49 +00:00
|
|
|
SkRRect(const SkRRect& rrect) = default;
|
2018-07-13 12:21:59 +00:00
|
|
|
|
|
|
|
/** Copies rrect bounds and corner radii.
|
|
|
|
|
|
|
|
@param rrect bounds and corner to copy
|
|
|
|
@return copy of rrect
|
|
|
|
*/
|
2018-06-12 20:49:49 +00:00
|
|
|
SkRRect& operator=(const SkRRect& rrect) = default;
|
2016-08-15 21:49:10 +00:00
|
|
|
|
2018-07-13 12:21:59 +00:00
|
|
|
/** \enum SkRRect::Type
|
|
|
|
Type describes possible specializations of SkRRect. Each Type is
|
|
|
|
exclusive; a SkRRect may only have one type.
|
|
|
|
|
|
|
|
Type members become progressively less restrictive; larger values of
|
|
|
|
Type have more degrees of freedom than smaller values.
|
|
|
|
*/
|
2012-11-29 13:24:55 +00:00
|
|
|
enum Type {
|
2018-07-13 12:21:59 +00:00
|
|
|
kEmpty_Type, //!< zero width or height
|
|
|
|
kRect_Type, //!< non-zero width and height, and zeroed radii
|
|
|
|
kOval_Type, //!< non-zero width and height filled with radii
|
|
|
|
kSimple_Type, //!< non-zero width and height with equal radii
|
|
|
|
kNinePatch_Type, //!< non-zero width and height with axis-aligned radii
|
|
|
|
kComplex_Type, //!< non-zero width and height with arbitrary radii
|
|
|
|
kLastType = kComplex_Type, //!< largest Type value
|
2012-11-29 13:24:55 +00:00
|
|
|
};
|
|
|
|
|
2012-12-12 20:48:18 +00:00
|
|
|
Type getType() const {
|
2016-09-23 18:23:22 +00:00
|
|
|
SkASSERT(this->isValid());
|
2014-10-22 18:23:56 +00:00
|
|
|
return static_cast<Type>(fType);
|
2012-11-29 13:24:55 +00:00
|
|
|
}
|
|
|
|
|
2012-12-12 20:48:18 +00:00
|
|
|
Type type() const { return this->getType(); }
|
|
|
|
|
|
|
|
inline bool isEmpty() const { return kEmpty_Type == this->getType(); }
|
|
|
|
inline bool isRect() const { return kRect_Type == this->getType(); }
|
|
|
|
inline bool isOval() const { return kOval_Type == this->getType(); }
|
|
|
|
inline bool isSimple() const { return kSimple_Type == this->getType(); }
|
2014-03-17 21:17:30 +00:00
|
|
|
inline bool isNinePatch() const { return kNinePatch_Type == this->getType(); }
|
2012-12-12 20:48:18 +00:00
|
|
|
inline bool isComplex() const { return kComplex_Type == this->getType(); }
|
|
|
|
|
2018-07-13 12:21:59 +00:00
|
|
|
/** Returns span on the x-axis. This does not check if result fits in 32-bit float;
|
|
|
|
result may be infinity.
|
|
|
|
|
2018-10-31 14:54:50 +00:00
|
|
|
@return rect().fRight minus rect().fLeft
|
2018-07-13 12:21:59 +00:00
|
|
|
*/
|
2012-12-17 02:10:42 +00:00
|
|
|
SkScalar width() const { return fRect.width(); }
|
2018-07-13 12:21:59 +00:00
|
|
|
|
|
|
|
/** Returns span on the y-axis. This does not check if result fits in 32-bit float;
|
|
|
|
result may be infinity.
|
|
|
|
|
2018-10-31 14:54:50 +00:00
|
|
|
@return rect().fBottom minus rect().fTop
|
2018-07-13 12:21:59 +00:00
|
|
|
*/
|
2012-12-17 02:10:42 +00:00
|
|
|
SkScalar height() const { return fRect.height(); }
|
|
|
|
|
2018-08-10 17:11:06 +00:00
|
|
|
/** Returns top-left corner radii. If type() returns kEmpty_Type, kRect_Type,
|
2018-07-13 12:21:59 +00:00
|
|
|
kOval_Type, or kSimple_Type, returns a value representative of all corner radii.
|
|
|
|
If type() returns kNinePatch_Type or kComplex_Type, at least one of the
|
|
|
|
remaining three corners has a different value.
|
|
|
|
|
|
|
|
@return corner radii for simple types
|
|
|
|
*/
|
2018-02-22 18:41:39 +00:00
|
|
|
SkVector getSimpleRadii() const {
|
|
|
|
return fRadii[0];
|
|
|
|
}
|
|
|
|
|
2018-07-13 12:21:59 +00:00
|
|
|
/** Sets bounds to zero width and height at (0, 0), the origin. Sets
|
|
|
|
corner radii to zero and sets type to kEmpty_Type.
|
|
|
|
*/
|
2017-12-15 16:31:05 +00:00
|
|
|
void setEmpty() { *this = SkRRect(); }
|
2012-11-29 13:24:55 +00:00
|
|
|
|
2018-07-13 12:21:59 +00:00
|
|
|
/** Sets bounds to sorted rect, and sets corner radii to zero.
|
|
|
|
If set bounds has width and height, and sets type to kRect_Type;
|
|
|
|
otherwise, sets type to kEmpty_Type.
|
|
|
|
|
|
|
|
@param rect bounds to set
|
|
|
|
*/
|
2012-11-29 13:24:55 +00:00
|
|
|
void setRect(const SkRect& rect) {
|
2017-12-15 16:31:05 +00:00
|
|
|
if (!this->initializeRect(rect)) {
|
2012-11-29 13:24:55 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
memset(fRadii, 0, sizeof(fRadii));
|
|
|
|
fType = kRect_Type;
|
|
|
|
|
2016-09-23 18:23:22 +00:00
|
|
|
SkASSERT(this->isValid());
|
2012-11-29 13:24:55 +00:00
|
|
|
}
|
|
|
|
|
2018-07-13 12:21:59 +00:00
|
|
|
/** Initializes bounds at (0, 0), the origin, with zero width and height.
|
|
|
|
Initializes corner radii to (0, 0), and sets type of kEmpty_Type.
|
|
|
|
|
|
|
|
@return empty SkRRect
|
|
|
|
*/
|
2017-12-15 16:31:05 +00:00
|
|
|
static SkRRect MakeEmpty() { return SkRRect(); }
|
2016-06-06 21:01:25 +00:00
|
|
|
|
2018-07-13 12:21:59 +00:00
|
|
|
/** Initializes to copy of r bounds and zeroes corner radii.
|
|
|
|
|
|
|
|
@param r bounds to copy
|
|
|
|
@return copy of r
|
|
|
|
*/
|
2015-08-10 02:41:13 +00:00
|
|
|
static SkRRect MakeRect(const SkRect& r) {
|
|
|
|
SkRRect rr;
|
|
|
|
rr.setRect(r);
|
|
|
|
return rr;
|
|
|
|
}
|
2016-06-06 21:01:25 +00:00
|
|
|
|
2018-07-13 12:21:59 +00:00
|
|
|
/** Sets bounds to oval, x-axis radii to half oval.width(), and all y-axis radii
|
|
|
|
to half oval.height(). If oval bounds is empty, sets to kEmpty_Type.
|
|
|
|
Otherwise, sets to kOval_Type.
|
|
|
|
|
|
|
|
@param oval bounds of oval
|
|
|
|
@return oval
|
|
|
|
*/
|
2015-09-15 17:20:55 +00:00
|
|
|
static SkRRect MakeOval(const SkRect& oval) {
|
|
|
|
SkRRect rr;
|
|
|
|
rr.setOval(oval);
|
|
|
|
return rr;
|
|
|
|
}
|
|
|
|
|
2018-07-13 12:21:59 +00:00
|
|
|
/** Sets to rounded rectangle with the same radii for all four corners.
|
|
|
|
If rect is empty, sets to kEmpty_Type.
|
|
|
|
Otherwise, if xRad and yRad are zero, sets to kRect_Type.
|
|
|
|
Otherwise, if xRad is at least half rect.width() and yRad is at least half
|
|
|
|
rect.height(), sets to kOval_Type.
|
|
|
|
Otherwise, sets to kSimple_Type.
|
|
|
|
|
|
|
|
@param rect bounds of rounded rectangle
|
|
|
|
@param xRad x-axis radius of corners
|
|
|
|
@param yRad y-axis radius of corners
|
|
|
|
@return rounded rectangle
|
|
|
|
*/
|
2015-12-09 18:17:35 +00:00
|
|
|
static SkRRect MakeRectXY(const SkRect& rect, SkScalar xRad, SkScalar yRad) {
|
|
|
|
SkRRect rr;
|
|
|
|
rr.setRectXY(rect, xRad, yRad);
|
|
|
|
return rr;
|
|
|
|
}
|
|
|
|
|
2018-07-13 12:21:59 +00:00
|
|
|
/** Sets bounds to oval, x-axis radii to half oval.width(), and all y-axis radii
|
|
|
|
to half oval.height(). If oval bounds is empty, sets to kEmpty_Type.
|
|
|
|
Otherwise, sets to kOval_Type.
|
|
|
|
|
|
|
|
@param oval bounds of oval
|
|
|
|
*/
|
2012-11-29 13:24:55 +00:00
|
|
|
void setOval(const SkRect& oval) {
|
2017-12-15 16:31:05 +00:00
|
|
|
if (!this->initializeRect(oval)) {
|
2012-11-29 13:24:55 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-09-29 18:24:07 +00:00
|
|
|
SkScalar xRad = SkScalarHalf(fRect.width());
|
|
|
|
SkScalar yRad = SkScalarHalf(fRect.height());
|
2012-11-29 13:24:55 +00:00
|
|
|
|
|
|
|
for (int i = 0; i < 4; ++i) {
|
|
|
|
fRadii[i].set(xRad, yRad);
|
|
|
|
}
|
|
|
|
fType = kOval_Type;
|
|
|
|
|
2016-09-23 18:23:22 +00:00
|
|
|
SkASSERT(this->isValid());
|
2012-11-29 13:24:55 +00:00
|
|
|
}
|
|
|
|
|
2018-07-13 12:21:59 +00:00
|
|
|
/** Sets to rounded rectangle with the same radii for all four corners.
|
|
|
|
If rect is empty, sets to kEmpty_Type.
|
|
|
|
Otherwise, if xRad or yRad is zero, sets to kRect_Type.
|
|
|
|
Otherwise, if xRad is at least half rect.width() and yRad is at least half
|
|
|
|
rect.height(), sets to kOval_Type.
|
|
|
|
Otherwise, sets to kSimple_Type.
|
|
|
|
|
|
|
|
@param rect bounds of rounded rectangle
|
|
|
|
@param xRad x-axis radius of corners
|
|
|
|
@param yRad y-axis radius of corners
|
2019-03-15 19:47:01 +00:00
|
|
|
|
|
|
|
example: https://fiddle.skia.org/c/@RRect_setRectXY
|
2018-07-13 12:21:59 +00:00
|
|
|
*/
|
2012-11-29 13:24:55 +00:00
|
|
|
void setRectXY(const SkRect& rect, SkScalar xRad, SkScalar yRad);
|
|
|
|
|
2018-07-13 12:21:59 +00:00
|
|
|
/** Sets bounds to rect. Sets radii to (leftRad, topRad), (rightRad, topRad),
|
|
|
|
(rightRad, bottomRad), (leftRad, bottomRad).
|
|
|
|
|
|
|
|
If rect is empty, sets to kEmpty_Type.
|
|
|
|
Otherwise, if leftRad and rightRad are zero, sets to kRect_Type.
|
|
|
|
Otherwise, if topRad and bottomRad are zero, sets to kRect_Type.
|
|
|
|
Otherwise, if leftRad and rightRad are equal and at least half rect.width(), and
|
|
|
|
topRad and bottomRad are equal at least half rect.height(), sets to kOval_Type.
|
|
|
|
Otherwise, if leftRad and rightRad are equal, and topRad and bottomRad are equal,
|
|
|
|
sets to kSimple_Type. Otherwise, sets to kNinePatch_Type.
|
|
|
|
|
|
|
|
Nine patch refers to the nine parts defined by the radii: one center rectangle,
|
|
|
|
four edge patches, and four corner patches.
|
|
|
|
|
|
|
|
@param rect bounds of rounded rectangle
|
|
|
|
@param leftRad left-top and left-bottom x-axis radius
|
|
|
|
@param topRad left-top and right-top y-axis radius
|
|
|
|
@param rightRad right-top and right-bottom x-axis radius
|
|
|
|
@param bottomRad left-bottom and right-bottom y-axis radius
|
|
|
|
*/
|
2014-03-17 21:17:30 +00:00
|
|
|
void setNinePatch(const SkRect& rect, SkScalar leftRad, SkScalar topRad,
|
|
|
|
SkScalar rightRad, SkScalar bottomRad);
|
|
|
|
|
2018-07-13 12:21:59 +00:00
|
|
|
/** Sets bounds to rect. Sets radii array for individual control of all for corners.
|
|
|
|
|
|
|
|
If rect is empty, sets to kEmpty_Type.
|
|
|
|
Otherwise, if one of each corner radii are zero, sets to kRect_Type.
|
|
|
|
Otherwise, if all x-axis radii are equal and at least half rect.width(), and
|
|
|
|
all y-axis radii are equal at least half rect.height(), sets to kOval_Type.
|
|
|
|
Otherwise, if all x-axis radii are equal, and all y-axis radii are equal,
|
|
|
|
sets to kSimple_Type. Otherwise, sets to kNinePatch_Type.
|
|
|
|
|
|
|
|
@param rect bounds of rounded rectangle
|
|
|
|
@param radii corner x-axis and y-axis radii
|
2019-03-15 19:47:01 +00:00
|
|
|
|
|
|
|
example: https://fiddle.skia.org/c/@RRect_setRectRadii
|
2018-07-13 12:21:59 +00:00
|
|
|
*/
|
2012-11-29 13:24:55 +00:00
|
|
|
void setRectRadii(const SkRect& rect, const SkVector radii[4]);
|
|
|
|
|
2018-07-13 12:21:59 +00:00
|
|
|
/** \enum SkRRect::Corner
|
|
|
|
The radii are stored: top-left, top-right, bottom-right, bottom-left.
|
|
|
|
*/
|
2012-11-29 13:24:55 +00:00
|
|
|
enum Corner {
|
2018-07-13 12:21:59 +00:00
|
|
|
kUpperLeft_Corner, //!< index of top-left corner radii
|
|
|
|
kUpperRight_Corner, //!< index of top-right corner radii
|
|
|
|
kLowerRight_Corner, //!< index of bottom-right corner radii
|
|
|
|
kLowerLeft_Corner, //!< index of bottom-left corner radii
|
2012-11-29 13:24:55 +00:00
|
|
|
};
|
|
|
|
|
2018-07-13 12:21:59 +00:00
|
|
|
/** Returns bounds. Bounds may have zero width or zero height. Bounds right is
|
|
|
|
greater than or equal to left; bounds bottom is greater than or equal to top.
|
|
|
|
Result is identical to getBounds().
|
|
|
|
|
|
|
|
@return bounding box
|
|
|
|
*/
|
2012-11-29 13:24:55 +00:00
|
|
|
const SkRect& rect() const { return fRect; }
|
2018-07-13 12:21:59 +00:00
|
|
|
|
|
|
|
/** Returns scalar pair for radius of curve on x-axis and y-axis for one corner.
|
|
|
|
Both radii may be zero. If not zero, both are positive and finite.
|
|
|
|
|
|
|
|
@return x-axis and y-axis radii for one corner
|
|
|
|
*/
|
2018-02-22 18:41:39 +00:00
|
|
|
SkVector radii(Corner corner) const { return fRadii[corner]; }
|
2018-07-13 12:21:59 +00:00
|
|
|
|
|
|
|
/** Returns bounds. Bounds may have zero width or zero height. Bounds right is
|
|
|
|
greater than or equal to left; bounds bottom is greater than or equal to top.
|
|
|
|
Result is identical to rect().
|
|
|
|
|
|
|
|
@return bounding box
|
|
|
|
*/
|
2012-12-12 20:48:18 +00:00
|
|
|
const SkRect& getBounds() const { return fRect; }
|
|
|
|
|
2018-07-13 12:21:59 +00:00
|
|
|
/** Returns true if bounds and radii in a are equal to bounds and radii in b.
|
|
|
|
|
|
|
|
a and b are not equal if either contain NaN. a and b are equal if members
|
2018-10-31 14:54:50 +00:00
|
|
|
contain zeroes with different signs.
|
2018-07-13 12:21:59 +00:00
|
|
|
|
|
|
|
@param a SkRect bounds and radii to compare
|
|
|
|
@param b SkRect bounds and radii to compare
|
|
|
|
@return true if members are equal
|
|
|
|
*/
|
2012-11-29 13:24:55 +00:00
|
|
|
friend bool operator==(const SkRRect& a, const SkRRect& b) {
|
2017-11-08 16:44:31 +00:00
|
|
|
return a.fRect == b.fRect && SkScalarsEqual(&a.fRadii[0].fX, &b.fRadii[0].fX, 8);
|
2012-11-29 13:24:55 +00:00
|
|
|
}
|
|
|
|
|
2018-07-13 12:21:59 +00:00
|
|
|
/** Returns true if bounds and radii in a are not equal to bounds and radii in b.
|
|
|
|
|
|
|
|
a and b are not equal if either contain NaN. a and b are equal if members
|
2018-10-31 14:54:50 +00:00
|
|
|
contain zeroes with different signs.
|
2018-07-13 12:21:59 +00:00
|
|
|
|
|
|
|
@param a SkRect bounds and radii to compare
|
|
|
|
@param b SkRect bounds and radii to compare
|
|
|
|
@return true if members are not equal
|
|
|
|
*/
|
2012-11-29 13:24:55 +00:00
|
|
|
friend bool operator!=(const SkRRect& a, const SkRRect& b) {
|
2017-11-08 16:44:31 +00:00
|
|
|
return a.fRect != b.fRect || !SkScalarsEqual(&a.fRadii[0].fX, &b.fRadii[0].fX, 8);
|
2012-11-29 13:24:55 +00:00
|
|
|
}
|
|
|
|
|
2018-07-13 12:21:59 +00:00
|
|
|
/** Copies SkRRect to dst, then insets dst bounds by dx and dy, and adjusts dst
|
|
|
|
radii by dx and dy. dx and dy may be positive, negative, or zero. dst may be
|
|
|
|
SkRRect.
|
|
|
|
|
|
|
|
If either corner radius is zero, the corner has no curvature and is unchanged.
|
|
|
|
Otherwise, if adjusted radius becomes negative, pins radius to zero.
|
|
|
|
If dx exceeds half dst bounds width, dst bounds left and right are set to
|
|
|
|
bounds x-axis center. If dy exceeds half dst bounds height, dst bounds top and
|
|
|
|
bottom are set to bounds y-axis center.
|
|
|
|
|
|
|
|
If dx or dy cause the bounds to become infinite, dst bounds is zeroed.
|
|
|
|
|
|
|
|
@param dx added to rect().fLeft, and subtracted from rect().fRight
|
|
|
|
@param dy added to rect().fTop, and subtracted from rect().fBottom
|
|
|
|
@param dst insets bounds and radii
|
2019-03-15 19:47:01 +00:00
|
|
|
|
|
|
|
example: https://fiddle.skia.org/c/@RRect_inset
|
2018-07-13 12:21:59 +00:00
|
|
|
*/
|
2012-12-17 02:10:42 +00:00
|
|
|
void inset(SkScalar dx, SkScalar dy, SkRRect* dst) const;
|
2012-12-23 23:11:21 +00:00
|
|
|
|
2018-07-13 12:21:59 +00:00
|
|
|
/** Insets bounds by dx and dy, and adjusts radii by dx and dy. dx and dy may be
|
|
|
|
positive, negative, or zero.
|
|
|
|
|
|
|
|
If either corner radius is zero, the corner has no curvature and is unchanged.
|
|
|
|
Otherwise, if adjusted radius becomes negative, pins radius to zero.
|
|
|
|
If dx exceeds half bounds width, bounds left and right are set to
|
|
|
|
bounds x-axis center. If dy exceeds half bounds height, bounds top and
|
|
|
|
bottom are set to bounds y-axis center.
|
|
|
|
|
|
|
|
If dx or dy cause the bounds to become infinite, bounds is zeroed.
|
|
|
|
|
|
|
|
@param dx added to rect().fLeft, and subtracted from rect().fRight
|
|
|
|
@param dy added to rect().fTop, and subtracted from rect().fBottom
|
|
|
|
*/
|
2012-12-17 02:10:42 +00:00
|
|
|
void inset(SkScalar dx, SkScalar dy) {
|
|
|
|
this->inset(dx, dy, this);
|
|
|
|
}
|
2012-12-23 23:11:21 +00:00
|
|
|
|
2018-07-13 12:21:59 +00:00
|
|
|
/** Outsets dst bounds by dx and dy, and adjusts radii by dx and dy. dx and dy may be
|
|
|
|
positive, negative, or zero.
|
|
|
|
|
|
|
|
If either corner radius is zero, the corner has no curvature and is unchanged.
|
|
|
|
Otherwise, if adjusted radius becomes negative, pins radius to zero.
|
|
|
|
If dx exceeds half dst bounds width, dst bounds left and right are set to
|
|
|
|
bounds x-axis center. If dy exceeds half dst bounds height, dst bounds top and
|
|
|
|
bottom are set to bounds y-axis center.
|
|
|
|
|
|
|
|
If dx or dy cause the bounds to become infinite, dst bounds is zeroed.
|
|
|
|
|
|
|
|
@param dx subtracted from rect().fLeft, and added to rect().fRight
|
|
|
|
@param dy subtracted from rect().fTop, and added to rect().fBottom
|
|
|
|
@param dst outset bounds and radii
|
|
|
|
*/
|
2012-12-17 02:10:42 +00:00
|
|
|
void outset(SkScalar dx, SkScalar dy, SkRRect* dst) const {
|
|
|
|
this->inset(-dx, -dy, dst);
|
|
|
|
}
|
2018-07-13 12:21:59 +00:00
|
|
|
|
|
|
|
/** Outsets bounds by dx and dy, and adjusts radii by dx and dy. dx and dy may be
|
|
|
|
positive, negative, or zero.
|
|
|
|
|
|
|
|
If either corner radius is zero, the corner has no curvature and is unchanged.
|
|
|
|
Otherwise, if adjusted radius becomes negative, pins radius to zero.
|
|
|
|
If dx exceeds half bounds width, bounds left and right are set to
|
|
|
|
bounds x-axis center. If dy exceeds half bounds height, bounds top and
|
|
|
|
bottom are set to bounds y-axis center.
|
|
|
|
|
|
|
|
If dx or dy cause the bounds to become infinite, bounds is zeroed.
|
|
|
|
|
|
|
|
@param dx subtracted from rect().fLeft, and added to rect().fRight
|
|
|
|
@param dy subtracted from rect().fTop, and added to rect().fBottom
|
|
|
|
*/
|
2012-12-17 02:10:42 +00:00
|
|
|
void outset(SkScalar dx, SkScalar dy) {
|
|
|
|
this->inset(-dx, -dy, this);
|
|
|
|
}
|
2014-03-05 03:02:06 +00:00
|
|
|
|
2018-07-13 12:21:59 +00:00
|
|
|
/** Translates SkRRect by (dx, dy).
|
|
|
|
|
|
|
|
@param dx offset added to rect().fLeft and rect().fRight
|
|
|
|
@param dy offset added to rect().fTop and rect().fBottom
|
|
|
|
*/
|
2014-03-04 16:25:34 +00:00
|
|
|
void offset(SkScalar dx, SkScalar dy) {
|
|
|
|
fRect.offset(dx, dy);
|
|
|
|
}
|
2012-12-17 02:10:42 +00:00
|
|
|
|
2018-07-13 12:21:59 +00:00
|
|
|
/** Returns SkRRect translated by (dx, dy).
|
|
|
|
|
|
|
|
@param dx offset added to rect().fLeft and rect().fRight
|
|
|
|
@param dy offset added to rect().fTop and rect().fBottom
|
|
|
|
@return SkRRect bounds offset by (dx, dy), with unchanged corner radii
|
|
|
|
*/
|
2016-08-15 21:49:10 +00:00
|
|
|
SkRRect SK_WARN_UNUSED_RESULT makeOffset(SkScalar dx, SkScalar dy) const {
|
|
|
|
return SkRRect(fRect.makeOffset(dx, dy), fRadii, fType);
|
|
|
|
}
|
|
|
|
|
2018-07-13 12:21:59 +00:00
|
|
|
/** Returns true if rect is inside the bounds and corner radii, and if
|
|
|
|
SkRRect and rect are not empty.
|
|
|
|
|
|
|
|
@param rect area tested for containment
|
|
|
|
@return true if SkRRect contains rect
|
2019-03-15 19:47:01 +00:00
|
|
|
|
|
|
|
example: https://fiddle.skia.org/c/@RRect_contains
|
2018-07-13 12:21:59 +00:00
|
|
|
*/
|
2013-04-25 12:23:00 +00:00
|
|
|
bool contains(const SkRect& rect) const;
|
|
|
|
|
2018-07-13 12:21:59 +00:00
|
|
|
/** Returns true if bounds and radii values are finite and describe a SkRRect
|
|
|
|
SkRRect::Type that matches getType(). All SkRRect methods construct valid types,
|
|
|
|
even if the input values are not valid. Invalid SkRRect data can only
|
|
|
|
be generated by corrupting memory.
|
|
|
|
|
|
|
|
@return true if bounds and radii match type()
|
2019-03-15 19:47:01 +00:00
|
|
|
|
|
|
|
example: https://fiddle.skia.org/c/@RRect_isValid
|
2018-07-13 12:21:59 +00:00
|
|
|
*/
|
2016-09-23 18:23:22 +00:00
|
|
|
bool isValid() const;
|
2012-11-29 13:24:55 +00:00
|
|
|
|
2018-04-26 12:32:37 +00:00
|
|
|
static constexpr size_t kSizeInMemory = 12 * sizeof(SkScalar);
|
2012-12-13 02:01:33 +00:00
|
|
|
|
2018-07-13 12:21:59 +00:00
|
|
|
/** Writes SkRRect to buffer. Writes kSizeInMemory bytes, and returns
|
|
|
|
kSizeInMemory, the number of bytes written.
|
|
|
|
|
|
|
|
@param buffer storage for SkRRect
|
|
|
|
@return bytes written, kSizeInMemory
|
2019-03-15 19:47:01 +00:00
|
|
|
|
|
|
|
example: https://fiddle.skia.org/c/@RRect_writeToMemory
|
2018-07-13 12:21:59 +00:00
|
|
|
*/
|
2013-11-05 15:46:56 +00:00
|
|
|
size_t writeToMemory(void* buffer) const;
|
2012-12-12 20:48:18 +00:00
|
|
|
|
2018-07-13 12:21:59 +00:00
|
|
|
/** Reads SkRRect from buffer, reading kSizeInMemory bytes.
|
|
|
|
Returns kSizeInMemory, bytes read if length is at least kSizeInMemory.
|
|
|
|
Otherwise, returns zero.
|
|
|
|
|
|
|
|
@param buffer memory to read from
|
|
|
|
@param length size of buffer
|
|
|
|
@return bytes read, or 0 if length is less than kSizeInMemory
|
2019-03-15 19:47:01 +00:00
|
|
|
|
|
|
|
example: https://fiddle.skia.org/c/@RRect_readFromMemory
|
2018-07-13 12:21:59 +00:00
|
|
|
*/
|
2013-11-05 15:46:56 +00:00
|
|
|
size_t readFromMemory(const void* buffer, size_t length);
|
2012-12-12 20:48:18 +00:00
|
|
|
|
2018-07-13 12:21:59 +00:00
|
|
|
/** Transforms by SkRRect by matrix, storing result in dst.
|
|
|
|
Returns true if SkRRect transformed can be represented by another SkRRect.
|
2019-04-03 20:28:05 +00:00
|
|
|
Returns false if matrix contains transformations that are not axis aligned.
|
2018-07-13 12:21:59 +00:00
|
|
|
|
|
|
|
Asserts in debug builds if SkRRect equals dst.
|
|
|
|
|
|
|
|
@param matrix SkMatrix specifying the transform
|
|
|
|
@param dst SkRRect to store the result
|
|
|
|
@return true if transformation succeeded.
|
2019-03-15 19:47:01 +00:00
|
|
|
|
|
|
|
example: https://fiddle.skia.org/c/@RRect_transform
|
2018-07-13 12:21:59 +00:00
|
|
|
*/
|
2013-11-05 15:54:42 +00:00
|
|
|
bool transform(const SkMatrix& matrix, SkRRect* dst) const;
|
|
|
|
|
2018-07-13 12:21:59 +00:00
|
|
|
/** Writes text representation of SkRRect to standard output.
|
|
|
|
Set asHex true to generate exact binary representations
|
|
|
|
of floating point numbers.
|
|
|
|
|
|
|
|
@param asHex true if SkScalar values are written as hexadecimal
|
2019-03-15 19:47:01 +00:00
|
|
|
|
|
|
|
example: https://fiddle.skia.org/c/@RRect_dump
|
2018-07-13 12:21:59 +00:00
|
|
|
*/
|
2014-12-15 15:59:53 +00:00
|
|
|
void dump(bool asHex) const;
|
2020-09-28 15:39:09 +00:00
|
|
|
SkString dumpToString(bool asHex) const;
|
2018-07-13 12:21:59 +00:00
|
|
|
|
|
|
|
/** Writes text representation of SkRRect to standard output. The representation
|
|
|
|
may be directly compiled as C++ code. Floating point values are written
|
|
|
|
with limited precision; it may not be possible to reconstruct original
|
|
|
|
SkRRect from output.
|
|
|
|
*/
|
2014-12-15 15:59:53 +00:00
|
|
|
void dump() const { this->dump(false); }
|
2018-07-13 12:21:59 +00:00
|
|
|
|
|
|
|
/** Writes text representation of SkRRect to standard output. The representation
|
|
|
|
may be directly compiled as C++ code. Floating point values are written
|
|
|
|
in hexadecimal to preserve their exact bit pattern. The output reconstructs the
|
|
|
|
original SkRRect.
|
|
|
|
*/
|
2014-12-15 15:59:53 +00:00
|
|
|
void dumpHex() const { this->dump(true); }
|
2014-06-09 14:59:06 +00:00
|
|
|
|
2012-11-29 13:24:55 +00:00
|
|
|
private:
|
2018-02-22 18:41:39 +00:00
|
|
|
static bool AreRectAndRadiiValid(const SkRect&, const SkVector[4]);
|
|
|
|
|
2016-08-15 21:49:10 +00:00
|
|
|
SkRRect(const SkRect& rect, const SkVector radii[4], int32_t type)
|
|
|
|
: fRect(rect)
|
|
|
|
, fRadii{radii[0], radii[1], radii[2], radii[3]}
|
|
|
|
, fType(type) {}
|
|
|
|
|
2017-12-15 16:31:05 +00:00
|
|
|
/**
|
|
|
|
* Initializes fRect. If the passed in rect is not finite or empty the rrect will be fully
|
|
|
|
* initialized and false is returned. Otherwise, just fRect is initialized and true is returned.
|
|
|
|
*/
|
|
|
|
bool initializeRect(const SkRect&);
|
2012-11-29 13:24:55 +00:00
|
|
|
|
2014-12-18 21:29:54 +00:00
|
|
|
void computeType();
|
2013-04-25 12:23:00 +00:00
|
|
|
bool checkCornerContainment(SkScalar x, SkScalar y) const;
|
2020-05-05 22:29:32 +00:00
|
|
|
// Returns true if the radii had to be scaled to fit rect
|
|
|
|
bool scaleRadii();
|
2012-12-12 20:48:18 +00:00
|
|
|
|
2017-12-15 16:31:05 +00:00
|
|
|
SkRect fRect = SkRect::MakeEmpty();
|
|
|
|
// Radii order is UL, UR, LR, LL. Use Corner enum to index into fRadii[]
|
|
|
|
SkVector fRadii[4] = {{0, 0}, {0, 0}, {0,0}, {0,0}};
|
|
|
|
// use an explicitly sized type so we're sure the class is dense (no uninitialized bytes)
|
|
|
|
int32_t fType = kEmpty_Type;
|
|
|
|
// TODO: add padding so we can use memcpy for flattening and not copy uninitialized data
|
|
|
|
|
2012-12-12 20:48:18 +00:00
|
|
|
// to access fRadii directly
|
|
|
|
friend class SkPath;
|
2018-02-22 18:41:39 +00:00
|
|
|
friend class SkRRectPriv;
|
2012-11-29 13:24:55 +00:00
|
|
|
};
|
|
|
|
|
2012-11-29 13:49:33 +00:00
|
|
|
#endif
|