Skia
2DGraphicsLibrary
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
SkRRect Class Reference

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
 
SkRRectoperator= (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 SkRectrect () const
 
const SkVectorradii (Corner corner) const
 
const SkRectgetBounds () const
 
const SkVectorgetSimpleRadii () 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)
 

Detailed Description

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.

Member Enumeration Documentation

Enum to capture the various possible subtypes of RR.

Accessed by type(). The subtypes become progressively less restrictive.

Enumerator
kEmpty_Type 

The RR is actually a (non-empty) rect (i.e., at least one radius at each corner is zero)

kRect_Type 

The RR is actually a (non-empty) oval (i.e., all x radii are equal and >= width/2 and all the y radii are equal and >= height/2.

kOval_Type 

The RR is non-empty and all the x radii are equal & all y radii are equal but it is not an oval (i.e., there are lines between the curves) nor a rect (i.e., both radii are non-zero)

kSimple_Type 

The RR is non-empty and the two left x radii are equal, the two top y radii are equal, and the same for the right and bottom but it is neither an rect, oval, nor a simple RR.

It is called "nine patch" because the centers of the corner ellipses form an axis aligned rect with edges that divide the RR into an 9 rectangular patches: an interior patch, four edge patches, and four corner patches.

kNinePatch_Type 

A fully general (non-empty) RR.

Some of the x and/or y radii are different from the others and there must be one corner where both radii are non-zero.

Member Function Documentation

const SkVector& SkRRect::getSimpleRadii ( ) const
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.

void SkRRect::outset ( SkScalar  dx,
SkScalar  dy,
SkRRect dst 
) const
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.

Parameters
bufferMemory to read from
lengthAmount of memory available in the buffer
Returns
number of bytes read (must be a multiple of 4) or 0 if there was not enough memory available
void SkRRect::setOval ( const SkRect oval)
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.

void SkRRect::setRect ( const SkRect rect)
inline

Set this RR to match the supplied rect.

All radii will be 0.

bool SkRRect::transform ( const SkMatrix matrix,
SkRRect dst 
) const

Transform by the specified matrix, and put the result in dst.

Parameters
matrixSkMatrix specifying the transform. Must only contain scale and/or translate, or this call will fail.
dstSkRRect to store the result. It is an error to use this, which would make this function no longer const.
Returns
true on success, false on failure. If false, dst is unmodified.
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.


The documentation for this class was generated from the following file: