skia2/site/user/api/SkRRect_Reference.md
Cary Clark 224c700a1f sync docs up with tip of tree
Also check in work in progress for blend modes,
round rects, and a placeholder for pictures.

One minor include change to add a parameter name
for SkBlendMode function.

TBR=reed@google.com
R=caryclark@google.com

Docs-Preview: https://skia.org/?cl=134200
Bug: skia:6898
Change-Id: I5d2a9221d61edb32d9c7edbb3193401605b2b513
Reviewed-on: https://skia-review.googlesource.com/134200
Reviewed-by: Cary Clark <caryclark@google.com>
Reviewed-by: Cary Clark <caryclark@skia.org>
Commit-Queue: Cary Clark <caryclark@skia.org>
Auto-Submit: Cary Clark <caryclark@skia.org>
2018-06-27 15:47:45 +00:00

57 KiB

SkRRect Reference

RRect

Class SkRRect

Constant

SkRRect related constants are defined by enum, enum class, #define, const, and constexpr.

Topic Description
Corner incomplete
Type incomplete
kComplex Type incomplete
kEmpty Type incomplete
kLastType incomplete
kLowerLeft Corner incomplete
kLowerRight Corner incomplete
kNinePatch Type incomplete
kOval Type incomplete
kRect Type incomplete
kSimple Type incomplete
kSizeInMemory incomplete
kUpperLeft Corner incomplete
kUpperRight Corner incomplete

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 allows implementing CSS properties that describe rounded corners. A rectangle may have up to eight radii, one for each axis on each of its four corners.

If either corner's radii are zero, the corner is square. Negative radii are treated as zero. If corner curves overlap, they are proportionally reduced to fit.

Overview

Topic Description
Constants enum and enum class, and their const values
Constructors functions that construct SkRRect
Functions global and class member functions
Operators operator overloading methods

Constructor

SkRRect can be constructed or initialized by these functions, including C++ class constructors.

Topic Description
MakeEmpty incomplete
MakeOval incomplete
MakeRect incomplete
MakeRectXY incomplete
SkRRect() incomplete
SkRRect(const SkRRect& rrect) incomplete
makeOffset incomplete

Operator

SkRRect operators inline class member functions with arithmetic equivalents.

Topic Description
operator!=(const SkRRect& a, const SkRRect& b) incomplete
operator=(const SkRRect& rrect) incomplete
operator==(const SkRRect& a, const SkRRect& b) incomplete

Member Function

SkRRect member functions read and modify the structure properties.

Topic Description
MakeEmpty incomplete
MakeOval incomplete
MakeRect incomplete
MakeRectXY incomplete
contains incomplete
dump incomplete
dumpHex incomplete
getBounds incomplete
getSimpleRadii returns corner radii for simple types
getType incomplete
height returns span in y
inset incomplete
isComplex returns true if not empty, rect, oval, simple, or nine-patch
isEmpty returns true if width or height are zero
isNinePatch returns true if not empty, rect, oval or simple; and radii are axis-aligned
isOval returns true if not empty, axes radii are equal, radii fill bounds
isRect returns true if not empty, and one radius at each corner is zero
isSimple returns true if not empty, rect or oval; and axes radii are equal
isValid incomplete
makeOffset incomplete
offset incomplete
outset incomplete
radii incomplete
readFromMemory incomplete
rect incomplete
setEmpty zeroes width, height, and corner radii
setNinePatch incomplete
setOval incomplete
setRect sets rect bounds with zeroed corners
setRectRadii incomplete
setRectXY incomplete
transform incomplete
type incomplete
width returns span in x
writeToMemory incomplete

SkRRect

SkRRect() = default

Default initialized to a rrect at the origin with zero width and height.

Return Value

incomplete

Example

See Also

incomplete


SkRRect

SkRRect(const SkRRect& rrect) = default

Parameters

rrect incomplete

Return Value

incomplete

Example

See Also

incomplete


operator=

SkRRect& operator=(const SkRRect& rrect) = default

Parameters

rrect incomplete

Return Value

incomplete

Example

See Also

incomplete


Enum SkRRect::Type

    enum Type {
        kEmpty Type,
        kRect Type,
        kOval Type,
        kSimple Type,
        kNinePatch Type,
        kComplex Type,
        kLastType = kComplex Type,
    };

Enum to capture the various possible subtypes of Round Rect. Accessed by type. The subtypes become progressively less restrictive.

Constants

Const Value Description
SkRRect::kEmpty_Type #Line # incomplete ## Round Rect has zero width or height. All radii are zero.
SkRRect::kRect_Type #Line # incomplete ## Round Rect has width and height. All radii are zero.
SkRRect::kOval_Type #Line # incomplete ## Round Rect has width and height. All four x-radii are equal, and at least half the width. All four y-radii are equal, and at least half the height.
SkRRect::kSimple_Type #Line # incomplete ## Round Rect has width and height. All four x-radii are equal and greater than zero, and all four y-radii are equal and greater than zero. Either x-radii are less than half the width, or y-radii is less than half the height, or both.
SkRRect::kNinePatch_Type #Line # incomplete ## Round Rect has width and height. Left x-radii are equal, top y-radii are equal, right x-radii are equal, and bottom y-radii are equal. The radii do not descript a rect, oval, or simple type.

The centers of the corner ellipses form an axis-aligned rectangle that divides the Round Rect into nine rectangular patches; an interior rectangle, four edges, and four corners.

SkRRect::kComplex_Type #Line # incomplete ## both radii are non-zero.
SkRRect::kLastType = kComplex_Type incomplete

Example

See Also

incomplete

getType

Type getType() const

Returns the RR's sub type.

Return Value

incomplete

Example

See Also

incomplete


type

Type type() const

Return Value

incomplete

Example

See Also

incomplete


isEmpty

inline bool isEmpty() const

Returns true if rect.fLeft is equal to rect.fRight, or if rect.fTop is equal to rect.fBottom.

Return Value

true if width or height are zero

Example

See Also

SkRect::isEmpty height width


isRect

inline bool isRect() const

Returns true if not empty, and if either x or y radius at each corner is zero.

Return Value

true if not empty, and one radius at each corner is zero

Example

See Also

isEmpty radii


isOval

inline bool isOval() const

Returns true if not empty, if all x-axis radii are equal, if all y-axis radii are equal, x-axis radii are at least half the width, and y-axis radii are at least half the height.

Return Value

true if has identical geometry to Oval

Example

The first radii are scaled down proportionately until both x-axis and y-axis fit within the bounds. After scaling, x-axis radius is smaller than half the width; left round rect is not an oval. The second radii are equal to half the dimensions; right round rect is an oval.

See Also

isEmpty isSimple SkCanvas::drawOval


isSimple

inline bool isSimple() const

Returns true if not empty, if all x-axis radii are equal but not zero, if all y-axis radii are equal but not zero; and x-axis radius is less than half width, or y-axis radius is less than half height.

Return Value

true if not empty, rect or oval; and axes radii are equal

Example

See Also

isEmpty isRect isOval isNinePatch


isNinePatch

inline bool isNinePatch() const

Returns true if isEmpty, isRect, isOval, and isSimple return false; and if left x-axis radii are equal, right x-axis radii are equal, top y-axis radii are equal, and bottom y-axis radii are equal.

Return Value

true if not empty, rect, oval or simple; and radii are axis-aligned

Example

See Also

isEmpty isRect isOval isSimple isComplex


isComplex

inline bool isComplex() const

Returns true if isEmpty, isRect, isOval, isSimple, and isNinePatch return false. If true: width and height are greater than zero, at least one corner radii are both greater than zero; left x-axis radii are not equal, or right x-axis radii are not equal, or top y-axis radii are not equal, or bottom y-axis radii are not equal.

Return Value

true if not empty, rect, oval, simple, or nine-patch

Example

See Also

isEmpty isRect isOval isSimple isNinePatch


width

SkScalar width() const

Returns span on the x-axis. This does not check if result fits in 32-bit float; result may be infinity.

Return Value

bounds().fRight minus bounds().fLeft

Example

SkRRect::MakeRect sorts its input, so width is always zero or larger.

Example Output

unsorted width: 5
large width: inf

See Also

SkRect::width height getBounds


height

SkScalar height() const

Returns span on the y-axis. This does not check if result fits in 32-bit float; result may be infinity.

Return Value

bounds().fBottom minus bounds().fTop

Example

SkRRect::MakeRect sorts its input, so height is always zero or larger.

Example Output

unsorted height: 5
large height: inf

See Also

SkRect.height width getBounds


getSimpleRadii

SkVector getSimpleRadii() const

Returns top-left corner x-radii. If type returns kEmpty Type, kRect Type, 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 Value

corner radii for simple types

Example

See Also

radii getBounds getType isSimple


setEmpty

void setEmpty()

Sets bounds to zero width and height at (0, 0), the origin. Sets corner radii to zero and sets type to kEmpty Type.

Example

Nothing blue is drawn because rrect is set to empty.

See Also

MakeEmpty setRect


setRect

void setRect(const SkRect& rect)

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.

Parameters

rect bounds to set

Example

See Also

MakeRect setRectXY


MakeEmpty

static SkRRect MakeEmpty()

Makes an empty rrect at the origin with zero width and height.

Return Value

incomplete

Example

See Also

incomplete


MakeRect

static SkRRect MakeRect(const SkRect& r)

Parameters

r incomplete

Return Value

incomplete

Example

See Also

incomplete


MakeOval

static SkRRect MakeOval(const SkRect& oval)

Parameters

oval incomplete

Return Value

incomplete

Example

See Also

incomplete


MakeRectXY

static SkRRect MakeRectXY(const SkRect& rect, SkScalar xRad, SkScalar yRad)

Parameters

rect incomplete
xRad incomplete
yRad incomplete

Return Value

incomplete

Example

See Also

incomplete


setOval

void setOval(const SkRect& oval)

Sets Round Rect to match the supplied oval. All x-radii will equal half the width and all y-radii will equal half the height.

Parameters

oval incomplete

Example

See Also

incomplete


setRectXY

void setRectXY(const SkRect& rect, SkScalar xRad, SkScalar yRad)

Initializes Round Rect with the same radii for all four corners.

Parameters

rect incomplete
xRad incomplete
yRad incomplete

Example

See Also

incomplete


setNinePatch

void setNinePatch(const SkRect& rect, SkScalar leftRad, SkScalar topRad, SkScalar rightRad,
                  SkScalar bottomRad)

Initializes Round Rect with one radius per-side.

Parameters

rect incomplete
leftRad incomplete
topRad incomplete
rightRad incomplete
bottomRad incomplete

Example

See Also

incomplete


setRectRadii

void setRectRadii(const SkRect& rect, const SkVector radii[4])

Initializes Round Rect with potentially different radii for all four corners.

Parameters

rect incomplete
radii incomplete

Example

See Also

incomplete


Enum SkRRect::Corner

    enum Corner {
        kUpperLeft Corner,
        kUpperRight Corner,
        kLowerRight Corner,
        kLowerLeft Corner,
    };

The radii are stored: top-left, top-right, bottom-right, bottom-left.

Constants

Const Value Description
SkRRect::kUpperLeft_Corner #Line # incomplete ## incomplete
SkRRect::kUpperRight_Corner #Line # incomplete ## incomplete
SkRRect::kLowerRight_Corner #Line # incomplete ## incomplete
SkRRect::kLowerLeft_Corner #Line # incomplete ## incomplete

Example

See Also

incomplete

rect

const SkRect& rect() const

Return Value

incomplete

Example

See Also

incomplete


radii

SkVector radii(Corner corner) const

Parameters

corner incomplete

Return Value

incomplete

Example

See Also

incomplete


getBounds

const SkRect& getBounds() const

Return Value

incomplete

Example

See Also

incomplete


operator==

bool operator==(const SkRRect& a, const SkRRect& b)

Parameters

a incomplete
b incomplete

Return Value

incomplete

Example

See Also

incomplete


operator!=

bool operator!=(const SkRRect& a, const SkRRect& b)

Parameters

a incomplete
b incomplete

Return Value

incomplete

Example

See Also

incomplete


inset

void inset(SkScalar dx, SkScalar dy, SkRRect* dst) const

Calls inset on the bounds, and adjust the radii to reflect what happens. 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. If the inset amount is larger than the width/height then the rrect collapses to a degenerate line or point. If the inset is sufficiently negative to cause the bounds to become infinite then the result is a default initialized rrect. It is valid for dst == this.

Parameters

dx incomplete
dy incomplete
dst incomplete

Example

See Also

incomplete


void inset(SkScalar dx, SkScalar dy)

Parameters

dx incomplete
dy incomplete

Example

See Also

incomplete


outset

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. If a given radius becomes negative, it is pinned to 0. It is valid for dst == this.

Parameters

dx incomplete
dy incomplete
dst incomplete

Example

See Also

incomplete


void outset(SkScalar dx, SkScalar dy)

Parameters

dx incomplete
dy incomplete

Example

See Also

incomplete


offset

void offset(SkScalar dx, SkScalar dy)

Translate the rrect by (dx, dy).

Parameters

dx incomplete
dy incomplete

Example

See Also

incomplete


makeOffset

SkRRect SK_WARN_UNUSED_RESULT makeOffset(SkScalar dx, SkScalar dy) const

Parameters

dx incomplete
dy incomplete

Return Value

incomplete

Example

See Also

incomplete


contains

bool contains(const SkRect& rect) const

Returns true if 'rect' is wholy inside the RR, and both are not empty.

Parameters

rect incomplete

Return Value

incomplete

Example

See Also

incomplete


isValid

bool isValid() const

Return Value

incomplete

Example

See Also

incomplete


Constants

Const Value Description
SkRRect::kSizeInMemory 48

Example

incomplete

writeToMemory

size_t 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.

Parameters

buffer incomplete

Return Value

incomplete

Example

See Also

incomplete


readFromMemory

size_t 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

buffer memory to read from
length amount of memory available in the buffer

Return Value

number of bytes read (must be a multiple of 4) or 0 if there was not enough memory available

Example

See Also

incomplete


transform

bool transform(const SkMatrix& matrix, SkRRect* dst) const

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

Parameters

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.

Return Value

true on success, false on failure.

Example

See Also

incomplete


dump

void dump(bool asHex) const

Parameters

asHex incomplete

Example

See Also

incomplete


void dump() const

Example

See Also

incomplete


dumpHex

void dumpHex() const

Example

See Also

incomplete