Skia
2DGraphicsLibrary
|
The SkRRect class represents a rounded rect with a potentially different radii for each corner. More...
#include <SkRRect.h>
Public Types | |
enum | Type { kEmpty_Type, kRect_Type, kOval_Type, kSimple_Type, kNinePatch_Type, kComplex_Type } |
Enum to capture the various possible subtypes of RR. More... | |
enum | Corner { kUpperLeft_Corner, kUpperRight_Corner, kLowerRight_Corner, kLowerLeft_Corner } |
enum | { kSizeInMemory = 12 * sizeof(SkScalar) } |
Public Member Functions | |
SkRRect (const SkRRect &)=default | |
SkRRect & | operator= (const SkRRect &)=default |
Type | getType () const |
Returns the RR's sub type. | |
Type | type () const |
bool | isEmpty () const |
bool | isRect () const |
bool | isOval () const |
bool | isSimple () const |
bool | isSimpleCircular () const |
bool | isCircle () const |
bool | isNinePatch () const |
bool | isComplex () const |
bool | allCornersCircular (SkScalar tolerance=SK_ScalarNearlyZero) const |
SkScalar | width () const |
SkScalar | height () const |
void | setEmpty () |
Set this RR to the empty rectangle (0,0,0,0) with 0 x & y radii. | |
void | setRect (const SkRect &rect) |
Set this RR to match the supplied rect. More... | |
void | setOval (const SkRect &oval) |
Set this RR to match the supplied oval. More... | |
void | setRectXY (const SkRect &rect, SkScalar xRad, SkScalar yRad) |
Initialize the RR with the same radii for all four corners. | |
void | setNinePatch (const SkRect &rect, SkScalar leftRad, SkScalar topRad, SkScalar rightRad, SkScalar bottomRad) |
Initialize the rr with one radius per-side. | |
void | setRectRadii (const SkRect &rect, const SkVector radii[4]) |
Initialize the RR with potentially different radii for all four corners. | |
const SkRect & | rect () const |
const SkVector & | radii (Corner corner) const |
const SkRect & | getBounds () const |
const SkVector & | getSimpleRadii () const |
When a rrect is simple, all of its radii are equal. More... | |
void | inset (SkScalar dx, SkScalar dy, SkRRect *dst) const |
Call inset on the bounds, and adjust the radii to reflect what happens in stroking: If the corner is sharp (no curvature), leave it alone, otherwise we grow/shrink the radii by the amount of the inset. More... | |
void | inset (SkScalar dx, SkScalar dy) |
void | outset (SkScalar dx, SkScalar dy, SkRRect *dst) const |
Call outset on the bounds, and adjust the radii to reflect what happens in stroking: If the corner is sharp (no curvature), leave it alone, otherwise we grow/shrink the radii by the amount of the inset. More... | |
void | outset (SkScalar dx, SkScalar dy) |
void | offset (SkScalar dx, SkScalar dy) |
Translate the rrect by (dx, dy). | |
SkRRect SK_WARN_UNUSED_RESULT | makeOffset (SkScalar dx, SkScalar dy) const |
bool | contains (const SkRect &rect) const |
Returns true if 'rect' is wholy inside the RR, and both are not empty. | |
bool | isValid () const |
size_t | writeToMemory (void *buffer) const |
Write the rrect into the specified buffer. More... | |
size_t | readFromMemory (const void *buffer, size_t length) |
Reads the rrect from the specified buffer. More... | |
bool | transform (const SkMatrix &matrix, SkRRect *dst) const |
Transform by the specified matrix, and put the result in dst. More... | |
void | dump (bool asHex) const |
void | dump () const |
void | dumpHex () const |
Static Public Member Functions | |
static SkRRect | MakeEmpty () |
static SkRRect | MakeRect (const SkRect &r) |
static SkRRect | MakeOval (const SkRect &oval) |
static SkRRect | MakeRectXY (const SkRect &rect, SkScalar xRad, SkScalar yRad) |
Private Member Functions | |
SkRRect (const SkRect &rect, const SkVector radii[4], int32_t type) | |
void | computeType () |
bool | checkCornerContainment (SkScalar x, SkScalar y) const |
void | scaleRadii () |
Private Attributes | |
SkRect | fRect |
SkVector | fRadii [4] |
int32_t | fType |
Friends | |
class | SkPath |
bool | operator== (const SkRRect &a, const SkRRect &b) |
bool | operator!= (const SkRRect &a, const SkRRect &b) |
The SkRRect class represents a rounded rect with a potentially different radii for each corner.
It does not have a constructor so must be initialized with one of the initialization functions (e.g., setEmpty, setRectRadii, etc.)
This class is intended to roughly match CSS' border-*-*-radius capabilities. This means: If either of a corner's radii are 0 the corner will be square. Negative radii are not allowed (they are clamped to zero). If the corner curves overlap they will be proportionally reduced to fit.
enum SkRRect::Type |
Enum to capture the various possible subtypes of RR.
Accessed by type(). The subtypes become progressively less restrictive.
|
inline |
When a rrect is simple, all of its radii are equal.
This returns one of those radii. This call requires the rrect to be non-complex.
void SkRRect::inset | ( | SkScalar | dx, |
SkScalar | dy, | ||
SkRRect * | dst | ||
) | const |
Call inset on the bounds, and adjust the radii to reflect what happens in stroking: If the corner is sharp (no curvature), leave it alone, otherwise we grow/shrink the radii by the amount of the inset.
If a given radius becomes negative, it is pinned to 0.
It is valid for dst == this.
|
inline |
Call outset on the bounds, and adjust the radii to reflect what happens in stroking: If the corner is sharp (no curvature), leave it alone, otherwise we grow/shrink the radii by the amount of the inset.
If a given radius becomes negative, it is pinned to 0.
It is valid for dst == this.
size_t SkRRect::readFromMemory | ( | const void * | buffer, |
size_t | length | ||
) |
Reads the rrect from the specified buffer.
If the specified buffer is large enough, this will read kSizeInMemory bytes, and that value is guaranteed to always be a multiple of 4.
buffer | Memory to read from |
length | Amount of memory available in the buffer |
|
inline |
Set this RR to match the supplied oval.
All x radii will equal half the width and all y radii will equal half the height.
|
inline |
Set this RR to match the supplied rect.
All radii will be 0.
Transform by the specified matrix, and put the result in dst.
matrix | SkMatrix specifying the transform. Must only contain scale and/or translate, or this call will fail. |
dst | SkRRect to store the result. It is an error to use this, which would make this function no longer const. |
size_t SkRRect::writeToMemory | ( | void * | buffer | ) | const |
Write the rrect into the specified buffer.
This is guaranteed to always write kSizeInMemory bytes, and that value is guaranteed to always be a multiple of 4. Return kSizeInMemory.