blob: 674b394b2ba18ee01d487392a39c4d2ff05c00dd [file] [log] [blame]
Cary Clark224c7002018-06-27 11:00:21 -04001#Topic RRect
2#Alias Round_Rect ##
3#Alias RRect_Reference ##
4
5#Class SkRRect
6
Cary Clark61313f32018-10-08 14:57:48 -04007#Code
8class SkRRect {
9public:
10 SkRRect() = default;
11 SkRRect(const SkRRect& rrect) = default;
12 SkRRect& operator=(const SkRRect& rrect) = default;
13
14 enum Type {
15 kEmpty_Type,
16 kRect_Type,
17 kOval_Type,
18 kSimple_Type,
19 kNinePatch_Type,
20 kComplex_Type,
21 kLastType = kComplex_Type,
22 };
23
24 Type getType() const;
25 Type type() const;
26 bool isEmpty() const;
27 bool isRect() const;
28 bool isOval() const;
29 bool isSimple() const;
30 bool isNinePatch() const;
31 bool isComplex() const;
32 SkScalar width() const;
33 SkScalar height() const;
34 SkVector getSimpleRadii() const;
35 void setEmpty();
36 void setRect(const SkRect& rect);
37 static SkRRect MakeEmpty();
38 static SkRRect MakeRect(const SkRect& r);
39 static SkRRect MakeOval(const SkRect& oval);
40 static SkRRect MakeRectXY(const SkRect& rect, SkScalar xRad, SkScalar yRad);
41 void setOval(const SkRect& oval);
42 void setRectXY(const SkRect& rect, SkScalar xRad, SkScalar yRad);
43 void setNinePatch(const SkRect& rect, SkScalar leftRad, SkScalar topRad,
44 SkScalar rightRad, SkScalar bottomRad);
45 void setRectRadii(const SkRect& rect, const SkVector radii[4]);
46
47 enum Corner {
48 kUpperLeft_Corner,
49 kUpperRight_Corner,
50 kLowerRight_Corner,
51 kLowerLeft_Corner,
52 };
53
54 const SkRect& rect() const;
55 SkVector radii(Corner corner) const;
56 const SkRect& getBounds() const;
57 friend bool operator==(const SkRRect& a, const SkRRect& b);
58 friend bool operator!=(const SkRRect& a, const SkRRect& b);
59 void inset(SkScalar dx, SkScalar dy, SkRRect* dst) const;
60 void inset(SkScalar dx, SkScalar dy);
61 void outset(SkScalar dx, SkScalar dy, SkRRect* dst) const;
62 void outset(SkScalar dx, SkScalar dy);
63 void offset(SkScalar dx, SkScalar dy);
64 SkRRect makeOffset(SkScalar dx, SkScalar dy) const;
65 bool contains(const SkRect& rect) const;
66 bool isValid() const;
67
68 static constexpr size_t kSizeInMemory = 12 * sizeof(SkScalar);
69
70 size_t writeToMemory(void* buffer) const;
71 size_t readFromMemory(const void* buffer, size_t length);
72 bool transform(const SkMatrix& matrix, SkRRect* dst) const;
73 void dump(bool asHex) const;
74 void dump() const;
75 void dumpHex() const;
76};
77##
78
Cary Clark80247e52018-07-11 16:18:41 -040079SkRRect describes a rounded rectangle with a bounds and a pair of radii for each corner.
Cary Clarkf9603982018-07-17 08:20:27 -040080The bounds and radii can be set so that SkRRect describes: a rectangle with sharp corners;
81a Circle; an Oval; or a rectangle with one or more rounded corners.
Cary Clark224c7002018-06-27 11:00:21 -040082
Cary Clark80247e52018-07-11 16:18:41 -040083SkRRect allows implementing CSS properties that describe rounded corners.
84SkRRect may have up to eight different radii, one for each axis on each of its four
Cary Clark224c7002018-06-27 11:00:21 -040085corners.
86
Cary Clark80247e52018-07-11 16:18:41 -040087SkRRect may modify the provided parameters when initializing bounds and radii.
Cary Clarkf9603982018-07-17 08:20:27 -040088If either axis radii is zero or less: radii are stored as zero; corner is square.
Cary Clark80247e52018-07-11 16:18:41 -040089If corner curves overlap, radii are proportionally reduced to fit within bounds.
Cary Clark224c7002018-06-27 11:00:21 -040090
Cary Clark224c7002018-06-27 11:00:21 -040091# ------------------------------------------------------------------------------
92
Cary Clark82f1f742018-06-28 08:50:35 -040093#Method SkRRect()
Cary Clark61313f32018-10-08 14:57:48 -040094#In Constructors
Cary Clark82f1f742018-06-28 08:50:35 -040095#Line # creates with zeroed bounds and corner radii ##
Cary Clark224c7002018-06-27 11:00:21 -040096
Cary Clark82f1f742018-06-28 08:50:35 -040097Initializes bounds at (0, 0), the origin, with zero width and height.
98Initializes corner radii to (0, 0), and sets type of kEmpty_Type.
Cary Clark224c7002018-06-27 11:00:21 -040099
Cary Clark82f1f742018-06-28 08:50:35 -0400100#Return empty Round_Rect ##
Cary Clark224c7002018-06-27 11:00:21 -0400101
102#Example
Cary Clark82f1f742018-06-28 08:50:35 -0400103#Height 60
104 SkRRect rrect;
105 SkPaint p;
106 p.setStyle(SkPaint::kStroke_Style);
107 p.setStrokeWidth(10);
108 canvas->drawRRect(rrect, p);
109 rrect.setRect({10, 10, 100, 50});
110 canvas->drawRRect(rrect, p);
Cary Clark224c7002018-06-27 11:00:21 -0400111##
112
Cary Clark82f1f742018-06-28 08:50:35 -0400113#SeeAlso setEmpty isEmpty
Cary Clark224c7002018-06-27 11:00:21 -0400114
115#Method ##
116
117# ------------------------------------------------------------------------------
118
Cary Clark82f1f742018-06-28 08:50:35 -0400119#Method SkRRect(const SkRRect& rrect)
Cary Clark61313f32018-10-08 14:57:48 -0400120#In Constructors
Cary Clark82f1f742018-06-28 08:50:35 -0400121#Line # copies bounds and corner radii ##
Cary Clark224c7002018-06-27 11:00:21 -0400122
Cary Clark82f1f742018-06-28 08:50:35 -0400123Initializes to copy of rrect bounds and corner radii.
Cary Clark224c7002018-06-27 11:00:21 -0400124
Cary Clark82f1f742018-06-28 08:50:35 -0400125#Param rrect bounds and corner to copy ##
Cary Clark224c7002018-06-27 11:00:21 -0400126
Cary Clark82f1f742018-06-28 08:50:35 -0400127#Return copy of rrect ##
128
129#Bug 8115
Cary Clark224c7002018-06-27 11:00:21 -0400130#Example
Cary Clark80247e52018-07-11 16:18:41 -0400131#Height 60
Cary Clark82f1f742018-06-28 08:50:35 -0400132 SkRRect rrect = SkRRect::MakeRect({10, 10, 100, 50});
133 SkRRect rrect2(rrect);
134 rrect2.inset(20, 20);
135 SkPaint p;
136 p.setStyle(SkPaint::kStroke_Style);
137 p.setStrokeWidth(10);
138 canvas->drawRRect(rrect, p);
139 canvas->drawRRect(rrect2, p);
Cary Clark224c7002018-06-27 11:00:21 -0400140##
141
Cary Clark82f1f742018-06-28 08:50:35 -0400142#SeeAlso operator=(const SkRRect& rrect) MakeRect
Cary Clark224c7002018-06-27 11:00:21 -0400143
144#Method ##
145
146# ------------------------------------------------------------------------------
147
Cary Clark82f1f742018-06-28 08:50:35 -0400148#Method SkRRect& operator=(const SkRRect& rrect)
Cary Clark61313f32018-10-08 14:57:48 -0400149#In Operators
Cary Clark82f1f742018-06-28 08:50:35 -0400150#Line # copies bounds and corner radii ##
Cary Clark224c7002018-06-27 11:00:21 -0400151
Cary Clark82f1f742018-06-28 08:50:35 -0400152Copies rrect bounds and corner radii.
Cary Clark224c7002018-06-27 11:00:21 -0400153
Cary Clark82f1f742018-06-28 08:50:35 -0400154#Param rrect bounds and corner to copy ##
155
156#Return copy of rrect ##
Cary Clark224c7002018-06-27 11:00:21 -0400157
158#Example
Cary Clark80247e52018-07-11 16:18:41 -0400159#Height 110
Cary Clark82f1f742018-06-28 08:50:35 -0400160 SkRRect rrect = SkRRect::MakeRect({40, 40, 100, 70});
161 SkRRect rrect2 = rrect;
162 rrect2.inset(-20, -20);
163 SkPaint p;
164 p.setStyle(SkPaint::kStroke_Style);
165 p.setStrokeWidth(10);
166 canvas->drawRRect(rrect, p);
167 canvas->drawRRect(rrect2, p);
Cary Clark224c7002018-06-27 11:00:21 -0400168##
169
Cary Clark82f1f742018-06-28 08:50:35 -0400170#SeeAlso SkRRect(const SkRRect& rrect) MakeRect
Cary Clark224c7002018-06-27 11:00:21 -0400171
172#Method ##
173
174# ------------------------------------------------------------------------------
Cary Clark82f1f742018-06-28 08:50:35 -0400175#Subtopic Type
176#Line # specialization of Round_Rect geometry ##
177
178#PhraseDef list_of_rrect_types
179kEmpty_Type, kRect_Type, kOval_Type, kSimple_Type, kNinePatch_Type,
180kComplex_Type
181##
Cary Clark224c7002018-06-27 11:00:21 -0400182
183#Enum Type
Cary Clark82f1f742018-06-28 08:50:35 -0400184#Line # specialization of Round_Rect geometry ##
Cary Clark224c7002018-06-27 11:00:21 -0400185
186#Code
187 enum Type {
188 kEmpty_Type,
189 kRect_Type,
190 kOval_Type,
191 kSimple_Type,
192 kNinePatch_Type,
193 kComplex_Type,
194 kLastType = kComplex_Type,
195 };
196##
197
Cary Clark82f1f742018-06-28 08:50:35 -0400198Type describes possible specializations of Round_Rect. Each Type is
199exclusive; a Round_Rect may only have one type.
200
Cary Clark80247e52018-07-11 16:18:41 -0400201Type members become progressively less restrictive; larger values of
Cary Clark82f1f742018-06-28 08:50:35 -0400202Type have more degrees of freedom than smaller values.
Cary Clark224c7002018-06-27 11:00:21 -0400203
Cary Clark80247e52018-07-11 16:18:41 -0400204#Const kEmpty_Type 0
Cary Clark82f1f742018-06-28 08:50:35 -0400205#Line # zero width or height ##
Cary Clark224c7002018-06-27 11:00:21 -0400206Round_Rect has zero width or height. All radii are zero.
207##
Cary Clark80247e52018-07-11 16:18:41 -0400208#Const kRect_Type 1
Cary Clark82f1f742018-06-28 08:50:35 -0400209#Line # non-zero width and height, and zeroed radii ##
Cary Clark224c7002018-06-27 11:00:21 -0400210Round_Rect has width and height. All radii are zero.
211##
Cary Clark80247e52018-07-11 16:18:41 -0400212#Const kOval_Type 2
Cary Clark82f1f742018-06-28 08:50:35 -0400213#Line # non-zero width and height filled with radii ##
Cary Clark224c7002018-06-27 11:00:21 -0400214Round_Rect has width and height. All four x-radii are equal,
215and at least half the width. All four y-radii are equal,
216and at least half the height.
217##
Cary Clark80247e52018-07-11 16:18:41 -0400218#Const kSimple_Type 3
Cary Clark82f1f742018-06-28 08:50:35 -0400219#Line # non-zero width and height with equal radii ##
Cary Clark224c7002018-06-27 11:00:21 -0400220Round_Rect has width and height. All four x-radii are equal and
221greater than zero, and all four y-radii are equal and greater than
222zero. Either x-radii are less than half the width, or y-radii is
223less than half the height, or both.
224##
Cary Clark80247e52018-07-11 16:18:41 -0400225#Const kNinePatch_Type 4
Cary Clark82f1f742018-06-28 08:50:35 -0400226#Line # non-zero width and height with axis-aligned radii ##
Cary Clark224c7002018-06-27 11:00:21 -0400227Round_Rect has width and height. Left x-radii are equal, top
228y-radii are equal, right x-radii are equal, and bottom y-radii
Cary Clarkf9603982018-07-17 08:20:27 -0400229are equal. The radii do not describe Rect, Oval, or simple type.
Cary Clark224c7002018-06-27 11:00:21 -0400230
231The centers of the corner ellipses form an axis-aligned rectangle
232that divides the Round_Rect into nine rectangular patches; an
233interior rectangle, four edges, and four corners.
234##
Cary Clark80247e52018-07-11 16:18:41 -0400235#Const kComplex_Type 5
Cary Clark82f1f742018-06-28 08:50:35 -0400236#Line # non-zero width and height with arbitrary radii ##
Cary Clark224c7002018-06-27 11:00:21 -0400237both radii are non-zero.
238##
Cary Clark80247e52018-07-11 16:18:41 -0400239#Const kLastType 5
Cary Clark82f1f742018-06-28 08:50:35 -0400240#Line # largest Type value ##
Cary Clark224c7002018-06-27 11:00:21 -0400241##
242
243#Example
Cary Clark82f1f742018-06-28 08:50:35 -0400244#Height 128
245 struct Radii { SkVector data[4]; };
246 auto drawRRectType = [=](const SkRect& rect, const Radii& radii) {
247 SkRRect rrect;
248 rrect.setRectRadii(rect, radii.data);
249 SkPaint paint;
250 paint.setAntiAlias(true);
251 const char* typeStr[] = { "empty", "rect", "oval", "simple", "nine patch", "complex" };
252 paint.setTextAlign(SkPaint::kCenter_Align);
253 canvas->drawString(typeStr[(int) rrect.type()], rect.centerX(), rect.bottom() + 20, paint);
254 paint.setStyle(SkPaint::kStroke_Style);
255 canvas->drawRRect(rrect, paint);
256 };
257 drawRRectType({ 45, 30, 45, 30}, {{{ 5, 5}, { 5, 5}, { 5, 5}, { 5, 5}}});
258 drawRRectType({ 90, 10, 140, 30}, {{{ 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}}});
259 drawRRectType({160, 10, 210, 30}, {{{25, 10}, {25, 10}, {25, 10}, {25, 10}}});
260 drawRRectType({ 20, 80, 70, 100}, {{{ 5, 5}, { 5, 5}, { 5, 5}, { 5, 5}}});
261 drawRRectType({ 90, 80, 140, 100}, {{{ 5, 5}, {10, 5}, {10, 5}, { 5, 5}}});
262 drawRRectType({160, 80, 210, 100}, {{{ 5, 5}, {10, 5}, { 5, 5}, { 5, 5}}});
Cary Clark224c7002018-06-27 11:00:21 -0400263##
264
Cary Clark82f1f742018-06-28 08:50:35 -0400265#SeeAlso Rect Path
Cary Clark224c7002018-06-27 11:00:21 -0400266
267#Enum ##
268
269# ------------------------------------------------------------------------------
270
271#Method Type getType() const
Cary Clark82f1f742018-06-28 08:50:35 -0400272#In Property
273#Line # returns Type ##
Cary Clark224c7002018-06-27 11:00:21 -0400274
Cary Clark82f1f742018-06-28 08:50:35 -0400275Returns Type, one of: #list_of_rrect_types#.
Cary Clark224c7002018-06-27 11:00:21 -0400276
Cary Clark82f1f742018-06-28 08:50:35 -0400277#Return Type ##
Cary Clark224c7002018-06-27 11:00:21 -0400278
279#Example
Cary Clark80247e52018-07-11 16:18:41 -0400280#Height 100
Cary Clark82f1f742018-06-28 08:50:35 -0400281#Description
282rrect2 is not a Rect; inset() has made it empty.
283##
284 SkRRect rrect = SkRRect::MakeRect({10, 10, 100, 50});
285 SkRRect rrect2(rrect);
286 rrect2.inset(20, 20);
287 SkPaint p;
288 p.setStyle(SkPaint::kStroke_Style);
289 p.setStrokeWidth(10);
290 std::string str("Type ");
291 str += SkRRect::kRect_Type == rrect2.getType() ? "=" : "!";
292 str += "= SkRRect::kRect_Type";
293 canvas->drawString(str.c_str(), 20, 80, SkPaint());
294 canvas->drawRRect(rrect2, p);
Cary Clark224c7002018-06-27 11:00:21 -0400295##
296
Cary Clark82f1f742018-06-28 08:50:35 -0400297#SeeAlso Type type
Cary Clark224c7002018-06-27 11:00:21 -0400298
299#Method ##
300
301# ------------------------------------------------------------------------------
302
303#Method Type type() const
Cary Clark82f1f742018-06-28 08:50:35 -0400304#In Property
305#Line # returns Type ##
Cary Clark224c7002018-06-27 11:00:21 -0400306
Cary Clark82f1f742018-06-28 08:50:35 -0400307Returns Type, one of: #list_of_rrect_types#.
308
309#Return Type ##
Cary Clark224c7002018-06-27 11:00:21 -0400310
311#Example
Cary Clark80247e52018-07-11 16:18:41 -0400312#Height 100
Cary Clark82f1f742018-06-28 08:50:35 -0400313#Description
314inset() has made rrect2 empty.
315##
316 SkRRect rrect = SkRRect::MakeRect({10, 10, 100, 50});
317 SkRRect rrect2(rrect);
318 rrect2.inset(20, 20);
319 SkPaint p;
320 p.setStyle(SkPaint::kStroke_Style);
321 p.setStrokeWidth(10);
322 std::string str("Type ");
323 str += SkRRect::kEmpty_Type == rrect2.type() ? "=" : "!";
324 str += "= SkRRect::kEmpty_Type";
325 canvas->drawString(str.c_str(), 20, 80, SkPaint());
326 canvas->drawRRect(rrect2, p);
Cary Clark224c7002018-06-27 11:00:21 -0400327##
328
Cary Clark82f1f742018-06-28 08:50:35 -0400329#SeeAlso Type getType
Cary Clark224c7002018-06-27 11:00:21 -0400330
331#Method ##
332
Cary Clark82f1f742018-06-28 08:50:35 -0400333#Subtopic Type ##
334
Cary Clark224c7002018-06-27 11:00:21 -0400335# ------------------------------------------------------------------------------
336
Cary Clark61313f32018-10-08 14:57:48 -0400337#Method bool isEmpty() const
Cary Clark224c7002018-06-27 11:00:21 -0400338#In Property
339#Line # returns true if width or height are zero ##
340Returns true if rect().fLeft is equal to rect().fRight, or if rect().fTop is equal
341to rect().fBottom.
342
343#Return true if width() or height() are zero ##
344
345#Example
346#Height 100
347 SkPaint paint;
348 paint.setAntiAlias(true);
349 paint.setTextAlign(SkPaint::kCenter_Align);
350 paint.setTextSize(16);
351 SkRRect rrect = SkRRect::MakeRectXY({30, 10, 100, 60}, 10, 5);
352 canvas->drawRRect(rrect, paint);
353 canvas->drawString(rrect.isEmpty() ? "empty" : "not empty", 64, 90, paint);
354 rrect.inset(40, 0);
355 canvas->translate(128, 0);
356 canvas->drawRRect(rrect, paint);
357 canvas->drawString(rrect.isEmpty() ? "empty" : "not empty", 64, 90, paint);
358##
359
360#SeeAlso SkRect::isEmpty height width
361
362#Method ##
363
364# ------------------------------------------------------------------------------
365
Cary Clark61313f32018-10-08 14:57:48 -0400366#Method bool isRect() const
Cary Clark224c7002018-06-27 11:00:21 -0400367#In Property
368#Line # returns true if not empty, and one radius at each corner is zero ##
Cary Clark80247e52018-07-11 16:18:41 -0400369Returns true if not empty, and if either x-axis or y-axis radius at each corner
370is zero.
Cary Clark224c7002018-06-27 11:00:21 -0400371
372#Return true if not empty, and one radius at each corner is zero ##
373
374#Example
375#Height 100
376 SkPaint paint;
377 paint.setAntiAlias(true);
378 paint.setTextAlign(SkPaint::kCenter_Align);
379 paint.setTextSize(16);
380 SkRRect rrect = SkRRect::MakeRect({30, 10, 100, 60});
381 canvas->drawRRect(rrect, paint);
382 canvas->drawString(rrect.isRect() ? "rect" : "not rect", 64, 90, paint);
383 SkVector radii[] = {{10, 10}, {0, 0}, {0, 0}, {0, 0}};
384 rrect.setRectRadii(rrect.getBounds(), radii);
385 canvas->translate(128, 0);
386 canvas->drawRRect(rrect, paint);
387 canvas->drawString(rrect.isRect() ? "rect" : "not rect", 64, 90, paint);
388##
389
390#SeeAlso isEmpty radii
391
392#Method ##
393
394# ------------------------------------------------------------------------------
395
Cary Clark61313f32018-10-08 14:57:48 -0400396#Method bool isOval() const
Cary Clark224c7002018-06-27 11:00:21 -0400397#In Property
398#Line # returns true if not empty, axes radii are equal, radii fill bounds ##
399Returns true if not empty, if all x-axis radii are equal, if all y-axis radii
400are equal, x-axis radii are at least half the width, and y-axis radii are at
401least half the height.
402
403#Return true if has identical geometry to Oval ##
404
405#Example
406#Height 100
407#Description
408The first radii are scaled down proportionately until both x-axis and y-axis fit
409within the bounds. After scaling, x-axis radius is smaller than half the width;
Cary Clark80247e52018-07-11 16:18:41 -0400410left Round_Rect is not an oval. The second radii are equal to half the
411dimensions; right Round_Rect is an oval.
Cary Clark224c7002018-06-27 11:00:21 -0400412##
413 SkPaint paint;
414 paint.setAntiAlias(true);
415 paint.setTextAlign(SkPaint::kCenter_Align);
416 paint.setTextSize(16);
417 SkRRect rrect = SkRRect::MakeRectXY({30, 10, 100, 60}, 40, 30);
418 canvas->drawRRect(rrect, paint);
419 canvas->drawString(rrect.isOval() ? "oval" : "not oval", 64, 90, paint);
420 rrect.setRectXY(rrect.getBounds(), 35, 25);
421 canvas->translate(128, 0);
422 canvas->drawRRect(rrect, paint);
423 canvas->drawString(rrect.isOval() ? "oval" : "not oval", 64, 90, paint);
424##
425
426#SeeAlso isEmpty isSimple SkCanvas::drawOval
427
428#Method ##
429
430# ------------------------------------------------------------------------------
431
Cary Clark61313f32018-10-08 14:57:48 -0400432#Method bool isSimple() const
Cary Clark224c7002018-06-27 11:00:21 -0400433#In Property
Cary Clark80247e52018-07-11 16:18:41 -0400434#Line # returns true if not empty, Rect or Oval; and axes radii are equal ##
Cary Clark224c7002018-06-27 11:00:21 -0400435Returns true if not empty, if all x-axis radii are equal but not zero,
436if all y-axis radii are equal but not zero; and x-axis radius is less than half
437width(), or y-axis radius is less than half height().
438
Cary Clark80247e52018-07-11 16:18:41 -0400439#Return true if not empty, Rect or Oval; and axes radii are equal ##
Cary Clark224c7002018-06-27 11:00:21 -0400440
441#Bug 8107
442#Example
443#Height 100
444 SkPaint paint;
445 paint.setAntiAlias(true);
446 paint.setTextAlign(SkPaint::kCenter_Align);
447 paint.setTextSize(16);
448 SkVector radii[] = {{40, 30}, {40, 30}, {40, 30}, {40, 30}};
449 SkRRect rrect;
450 rrect.setRectRadii({30, 10, 100, 60}, radii);
451 canvas->drawRRect(rrect, paint);
452 canvas->drawString(rrect.isSimple() ? "simple" : "not simple", 64, 90, paint);
453 radii[0].fX = 35;
454 rrect.setRectRadii(rrect.getBounds(), radii);
455 canvas->translate(128, 0);
456 canvas->drawRRect(rrect, paint);
457 canvas->drawString(rrect.isSimple() ? "simple" : "not simple", 64, 90, paint);
458##
459
460#SeeAlso isEmpty isRect isOval isNinePatch
461
462#Method ##
463
464# ------------------------------------------------------------------------------
465
Cary Clark61313f32018-10-08 14:57:48 -0400466#Method bool isNinePatch() const
Cary Clark224c7002018-06-27 11:00:21 -0400467#In Property
Cary Clark80247e52018-07-11 16:18:41 -0400468#Line # returns true if not empty, Rect, Oval or simple; and radii are axis-aligned ##
Cary Clark224c7002018-06-27 11:00:21 -0400469Returns true if isEmpty, isRect, isOval, and isSimple return false; and if
470left x-axis radii are equal, right x-axis radii are equal, top y-axis radii are
471equal, and bottom y-axis radii are equal.
472
Cary Clark80247e52018-07-11 16:18:41 -0400473#Return true if not empty, Rect, Oval or simple; and radii are axis-aligned ##
Cary Clark224c7002018-06-27 11:00:21 -0400474
475#Bug 8107
476#Example
477#Height 100
478 SkPaint paint;
479 paint.setAntiAlias(true);
480 paint.setTextAlign(SkPaint::kCenter_Align);
481 paint.setTextSize(16);
482 SkVector radii[] = {{20, 30}, {40, 30}, {40, 30}, {20, 30}};
483 SkRRect rrect;
484 rrect.setRectRadii({30, 10, 100, 60}, radii);
485 canvas->drawRRect(rrect, paint);
486 canvas->drawString(rrect.isNinePatch() ? "9 patch" : "not 9 patch", 64, 90, paint);
487 radii[0].fX = 35;
488 rrect.setRectRadii(rrect.getBounds(), radii);
489 canvas->translate(128, 0);
490 canvas->drawRRect(rrect, paint);
491 canvas->drawString(rrect.isNinePatch() ? "9 patch" : "not 9 patch", 64, 90, paint);
492##
493
494#SeeAlso isEmpty isRect isOval isSimple isComplex
495
496#Method ##
497
498# ------------------------------------------------------------------------------
499
Cary Clark61313f32018-10-08 14:57:48 -0400500#Method bool isComplex() const
Cary Clark224c7002018-06-27 11:00:21 -0400501#In Property
Cary Clark80247e52018-07-11 16:18:41 -0400502#Line # returns true if not empty, Rect, Oval, simple, or nine-patch ##
Cary Clark224c7002018-06-27 11:00:21 -0400503
504Returns true if isEmpty, isRect, isOval, isSimple, and isNinePatch return false.
505If true: width and height are greater than zero, at least one corner radii are
506both greater than zero; left x-axis radii are not equal, or right x-axis radii
507are not equal, or top y-axis radii are not equal, or bottom y-axis radii are not
508equal.
509
Cary Clark80247e52018-07-11 16:18:41 -0400510#Return true if not empty, Rect, Oval, simple, or nine-patch ##
Cary Clark224c7002018-06-27 11:00:21 -0400511
512#Example
Cary Clark80247e52018-07-11 16:18:41 -0400513#Height 100
Cary Clark224c7002018-06-27 11:00:21 -0400514 SkPaint paint;
515 paint.setAntiAlias(true);
516 paint.setTextAlign(SkPaint::kCenter_Align);
517 paint.setTextSize(16);
518 SkVector radii[] = {{25, 30}, {40, 30}, {40, 30}, {20, 30}};
519 SkRRect rrect;
520 rrect.setRectRadii({30, 10, 100, 60}, radii);
521 canvas->drawRRect(rrect, paint);
522 canvas->drawString(rrect.isComplex() ? "complex" : "not complex", 64, 90, paint);
523 radii[0].fX = 20;
524 rrect.setRectRadii(rrect.getBounds(), radii);
525 canvas->translate(128, 0);
526 canvas->drawRRect(rrect, paint);
527 canvas->drawString(rrect.isComplex() ? "complex" : "not complex", 64, 90, paint);
528##
529
530#SeeAlso isEmpty isRect isOval isSimple isNinePatch
531
532#Method ##
533
534# ------------------------------------------------------------------------------
535
536#Method SkScalar width() const
537#In Property
Cary Clark80247e52018-07-11 16:18:41 -0400538#Line # returns span in x-axis ##
Cary Clark224c7002018-06-27 11:00:21 -0400539Returns span on the x-axis. This does not check if result fits in 32-bit float;
540result may be infinity.
541
542#Return bounds().fRight minus bounds().fLeft ##
543
544#Example
545#Description
546SkRRect::MakeRect sorts its input, so width() is always zero or larger.
547##
548 SkRRect unsorted = SkRRect::MakeRect({ 15, 25, 10, 5 });
549 SkDebugf("unsorted width: %g\n", unsorted.width());
550 SkRRect large = SkRRect::MakeRect({ -FLT_MAX, 1, FLT_MAX, 2 });
551 SkDebugf("large width: %.0f\n", large.width());
552#StdOut
553unsorted width: 5
554large width: inf
555##
556##
557
558#SeeAlso SkRect::width height getBounds
559
560#Method ##
561
562# ------------------------------------------------------------------------------
563
564#Method SkScalar height() const
565#In Property
Cary Clark80247e52018-07-11 16:18:41 -0400566#Line # returns span in y-axis ##
Cary Clark224c7002018-06-27 11:00:21 -0400567Returns span on the y-axis. This does not check if result fits in 32-bit float;
568result may be infinity.
569
570#Return bounds().fBottom minus bounds().fTop ##
571
572#Example
573#Description
574SkRRect::MakeRect sorts its input, so height() is always zero or larger.
575##
576 SkRRect unsorted = SkRRect::MakeRect({ 15, 25, 10, 20 });
577 SkDebugf("unsorted height: %g\n", unsorted.height());
578 SkRRect large = SkRRect::MakeRect({ 1, -FLT_MAX, 2, FLT_MAX });
579 SkDebugf("large height: %.0f\n", large.height());
580#StdOut
581unsorted height: 5
582large height: inf
583##
584##
585
586#SeeAlso SkRect.height width getBounds
587
588#Method ##
589
590# ------------------------------------------------------------------------------
591
592#Method SkVector getSimpleRadii() const
593#In Property
594#Line # returns corner radii for simple types ##
595
Cary Clarkd2ca79c2018-08-10 13:09:13 -0400596Returns top-left corner radii. If type() returns kEmpty_Type, kRect_Type,
Cary Clark224c7002018-06-27 11:00:21 -0400597kOval_Type, or kSimple_Type, returns a value representative of all corner radii.
598If type() returns kNinePatch_Type or kComplex_Type, at least one of the
599remaining three corners has a different value.
600
601#Return corner radii for simple types ##
602
603#Example
Cary Clark80247e52018-07-11 16:18:41 -0400604#Height 100
Cary Clark224c7002018-06-27 11:00:21 -0400605 auto drawDetails = [=](const SkRRect& rrect) {
606 SkPaint paint;
607 paint.setAntiAlias(true);
608 paint.setTextAlign(SkPaint::kCenter_Align);
609 paint.setTextSize(12);
610 canvas->drawRRect(rrect, paint);
611 SkVector corner = rrect.getSimpleRadii();
612 std::string label = "corner: " + std::to_string(corner.fX).substr(0, 3) + ", " +
613 std::to_string(corner.fY).substr(0, 3);
614 canvas->drawString(label.c_str(), 64, 90, paint);
615 canvas->translate(128, 0);
616 };
617 SkRRect rrect = SkRRect::MakeRect({30, 10, 100, 60});
618 drawDetails(rrect);
619 rrect.setRectXY(rrect.getBounds(), 5, 8);
620 drawDetails(rrect);
621##
622
623#SeeAlso radii getBounds getType isSimple
624
625#Method ##
626
627# ------------------------------------------------------------------------------
628
629#Method void setEmpty()
630#In Set
631#Line # zeroes width, height, and corner radii ##
632
633Sets bounds to zero width and height at (0, 0), the origin. Sets
634corner radii to zero and sets type to kEmpty_Type.
635
636#Example
Cary Clark80247e52018-07-11 16:18:41 -0400637#Height 80
Cary Clark224c7002018-06-27 11:00:21 -0400638#Description
Cary Clark80247e52018-07-11 16:18:41 -0400639Nothing blue is drawn because Round_Rect is set to empty.
Cary Clark224c7002018-06-27 11:00:21 -0400640##
641 SkPaint paint;
642 SkRRect rrect = SkRRect::MakeRect({30, 10, 100, 60});
643 canvas->drawRRect(rrect, paint);
644 rrect.setEmpty();
645 paint.setColor(SK_ColorBLUE);
646 canvas->drawRRect(rrect, paint);
647##
648
649#SeeAlso MakeEmpty setRect
650
651#Method ##
652
653# ------------------------------------------------------------------------------
654
655#Method void setRect(const SkRect& rect)
656#In Set
Cary Clark80247e52018-07-11 16:18:41 -0400657#Line # sets Round_Rect bounds with zeroed corners ##
Cary Clark224c7002018-06-27 11:00:21 -0400658
659Sets bounds to sorted rect, and sets corner radii to zero.
660If set bounds has width and height, and sets type to kRect_Type;
661otherwise, sets type to kEmpty_Type.
662
663#Param rect bounds to set ##
664
665#Example
Cary Clark82f1f742018-06-28 08:50:35 -0400666#Height 90
Cary Clark224c7002018-06-27 11:00:21 -0400667 SkPaint paint;
668 SkRRect rrect = SkRRect::MakeRect({30, 10, 100, 60});
669 canvas->drawRRect(rrect, paint);
670 rrect.setRect({60, 30, 120, 80});
671 paint.setColor(SK_ColorBLUE);
672 canvas->drawRRect(rrect, paint);
673##
674
675#SeeAlso MakeRect setRectXY
676
677#Method ##
678
679# ------------------------------------------------------------------------------
680
681#Method static SkRRect MakeEmpty()
Cary Clark61313f32018-10-08 14:57:48 -0400682#In Constructors
Cary Clark82f1f742018-06-28 08:50:35 -0400683#Line # creates with zeroed bounds and corner radii ##
Cary Clark224c7002018-06-27 11:00:21 -0400684
Cary Clark82f1f742018-06-28 08:50:35 -0400685Initializes bounds at (0, 0), the origin, with zero width and height.
686Initializes corner radii to (0, 0), and sets type of kEmpty_Type.
Cary Clark224c7002018-06-27 11:00:21 -0400687
Cary Clark82f1f742018-06-28 08:50:35 -0400688#Return empty Round_Rect ##
Cary Clark224c7002018-06-27 11:00:21 -0400689
690#Example
Cary Clark82f1f742018-06-28 08:50:35 -0400691#Height 90
692 SkRRect rrect = SkRRect::MakeEmpty();
693 SkRRect rrect2(rrect);
694 rrect2.inset(-20, -20);
695 SkPaint p;
696 p.setStyle(SkPaint::kStroke_Style);
697 p.setStrokeWidth(10);
698 std::string str("Type ");
699 str += SkRRect::kEmpty_Type == rrect2.type() ? "=" : "!";
700 str += "= SkRRect::kEmpty_Type";
701 canvas->drawString(str.c_str(), 20, 80, SkPaint());
702 canvas->drawRRect(rrect2, p);
Cary Clark224c7002018-06-27 11:00:21 -0400703##
704
Cary Clark82f1f742018-06-28 08:50:35 -0400705#SeeAlso SkRRect() SkRect::MakeEmpty
Cary Clark224c7002018-06-27 11:00:21 -0400706
707#Method ##
708
709# ------------------------------------------------------------------------------
710
711#Method static SkRRect MakeRect(const SkRect& r)
Cary Clark61313f32018-10-08 14:57:48 -0400712#In Constructors
Cary Clark82f1f742018-06-28 08:50:35 -0400713#Line # copies bounds and zeroes corner radii ##
Cary Clark224c7002018-06-27 11:00:21 -0400714
Cary Clark82f1f742018-06-28 08:50:35 -0400715Initializes to copy of r bounds and zeroes corner radii.
Cary Clark224c7002018-06-27 11:00:21 -0400716
Cary Clark82f1f742018-06-28 08:50:35 -0400717#Param r bounds to copy ##
718
719#Return copy of r ##
Cary Clark224c7002018-06-27 11:00:21 -0400720
721#Example
Cary Clark82f1f742018-06-28 08:50:35 -0400722#Height 70
723 SkPaint paint;
724 SkRRect rrect = SkRRect::MakeRect({30, 10, 100, 60});
725 canvas->drawRRect(rrect, paint);
726 rrect.setOval(rrect.getBounds());
727 paint.setColor(SK_ColorBLUE);
728 canvas->drawRRect(rrect, paint);
Cary Clark224c7002018-06-27 11:00:21 -0400729##
730
Cary Clark82f1f742018-06-28 08:50:35 -0400731#SeeAlso setRect MakeOval MakeRectXY
Cary Clark224c7002018-06-27 11:00:21 -0400732
733#Method ##
734
735# ------------------------------------------------------------------------------
736
737#Method static SkRRect MakeOval(const SkRect& oval)
Cary Clark61313f32018-10-08 14:57:48 -0400738#In Constructors
Cary Clark82f1f742018-06-28 08:50:35 -0400739#Line # creates Oval to fit bounds ##
Cary Clark224c7002018-06-27 11:00:21 -0400740
Cary Clark82f1f742018-06-28 08:50:35 -0400741Sets bounds to oval, x-axis radii to half oval.width(), and all y-axis radii
Cary Clark80247e52018-07-11 16:18:41 -0400742to half oval.height(). If oval bounds is empty, sets to kEmpty_Type.
Cary Clark82f1f742018-06-28 08:50:35 -0400743Otherwise, sets to kOval_Type.
Cary Clark224c7002018-06-27 11:00:21 -0400744
Cary Clark82f1f742018-06-28 08:50:35 -0400745#Param oval bounds of Oval ##
746
747#Return Oval ##
Cary Clark224c7002018-06-27 11:00:21 -0400748
749#Example
Cary Clark82f1f742018-06-28 08:50:35 -0400750#Height 70
751 SkPaint paint;
752 SkRRect rrect = SkRRect::MakeOval({30, 10, 100, 60});
753 canvas->drawRRect(rrect, paint);
754 rrect.setRect(rrect.getBounds());
755 paint.setColor(SK_ColorBLUE);
756 paint.setBlendMode(SkBlendMode::kDifference);
757 canvas->drawRRect(rrect, paint);
Cary Clark224c7002018-06-27 11:00:21 -0400758##
759
Cary Clark82f1f742018-06-28 08:50:35 -0400760#SeeAlso setOval MakeRect MakeRectXY
Cary Clark224c7002018-06-27 11:00:21 -0400761
762#Method ##
763
764# ------------------------------------------------------------------------------
765
766#Method static SkRRect MakeRectXY(const SkRect& rect, SkScalar xRad, SkScalar yRad)
Cary Clark61313f32018-10-08 14:57:48 -0400767#In Constructors
Cary Clark82f1f742018-06-28 08:50:35 -0400768#Line # creates rounded rectangle ##
Cary Clark224c7002018-06-27 11:00:21 -0400769
Cary Clark82f1f742018-06-28 08:50:35 -0400770Sets to rounded rectangle with the same radii for all four corners.
771If rect is empty, sets to kEmpty_Type.
772Otherwise, if xRad and yRad are zero, sets to kRect_Type.
773Otherwise, if xRad is at least half rect.width() and yRad is at least half
774rect.height(), sets to kOval_Type.
775Otherwise, sets to kSimple_Type.
Cary Clark224c7002018-06-27 11:00:21 -0400776
Cary Clark82f1f742018-06-28 08:50:35 -0400777#Param rect bounds of rounded rectangle ##
778#Param xRad x-axis radius of corners ##
779#Param yRad y-axis radius of corners ##
780
781#Return rounded rectangle ##
Cary Clark224c7002018-06-27 11:00:21 -0400782
783#Example
Cary Clark82f1f742018-06-28 08:50:35 -0400784#Height 70
785 SkPaint paint;
786 SkRRect rrect = SkRRect::MakeRectXY({30, 10, 100, 60}, 20, 20);
787 canvas->drawRRect(rrect, paint);
788 rrect.setRect(rrect.getBounds());
789 paint.setColor(SK_ColorBLUE);
790 paint.setBlendMode(SkBlendMode::kModulate);
791 canvas->drawRRect(rrect, paint);
Cary Clark224c7002018-06-27 11:00:21 -0400792##
793
Cary Clark82f1f742018-06-28 08:50:35 -0400794#SeeAlso setRectXY
Cary Clark224c7002018-06-27 11:00:21 -0400795
796#Method ##
797
798# ------------------------------------------------------------------------------
799
800#Method void setOval(const SkRect& oval)
Cary Clark82f1f742018-06-28 08:50:35 -0400801#In Set
802#Line # replaces with Oval to fit bounds ##
Cary Clark224c7002018-06-27 11:00:21 -0400803
Cary Clark82f1f742018-06-28 08:50:35 -0400804Sets bounds to oval, x-axis radii to half oval.width(), and all y-axis radii
Cary Clark80247e52018-07-11 16:18:41 -0400805to half oval.height(). If oval bounds is empty, sets to kEmpty_Type.
Cary Clark82f1f742018-06-28 08:50:35 -0400806Otherwise, sets to kOval_Type.
Cary Clark224c7002018-06-27 11:00:21 -0400807
Cary Clark82f1f742018-06-28 08:50:35 -0400808#Param oval bounds of Oval ##
Cary Clark224c7002018-06-27 11:00:21 -0400809
810#Example
Cary Clark82f1f742018-06-28 08:50:35 -0400811#Height 70
812 SkPaint paint;
813 SkRRect rrect = SkRRect::MakeRectXY({30, 10, 100, 60}, 20, 20);
814 canvas->drawRRect(rrect, paint);
815 rrect.setOval(rrect.getBounds());
816 paint.setColor(SK_ColorWHITE);
817 paint.setBlendMode(SkBlendMode::kExclusion);
818 canvas->drawRRect(rrect, paint);
Cary Clark224c7002018-06-27 11:00:21 -0400819##
820
Cary Clark82f1f742018-06-28 08:50:35 -0400821#SeeAlso MakeOval
Cary Clark224c7002018-06-27 11:00:21 -0400822
823#Method ##
824
825# ------------------------------------------------------------------------------
826
827#Method void setRectXY(const SkRect& rect, SkScalar xRad, SkScalar yRad)
Cary Clark82f1f742018-06-28 08:50:35 -0400828#In Set
829#Line # replaces with rounded rectangle ##
Cary Clark224c7002018-06-27 11:00:21 -0400830
Cary Clark82f1f742018-06-28 08:50:35 -0400831Sets to rounded rectangle with the same radii for all four corners.
832If rect is empty, sets to kEmpty_Type.
833Otherwise, if xRad or yRad is zero, sets to kRect_Type.
834Otherwise, if xRad is at least half rect.width() and yRad is at least half
835rect.height(), sets to kOval_Type.
836Otherwise, sets to kSimple_Type.
Cary Clark224c7002018-06-27 11:00:21 -0400837
Cary Clark82f1f742018-06-28 08:50:35 -0400838#Param rect bounds of rounded rectangle ##
839#Param xRad x-axis radius of corners ##
840#Param yRad y-axis radius of corners ##
Cary Clark224c7002018-06-27 11:00:21 -0400841
842#Example
Cary Clark82f1f742018-06-28 08:50:35 -0400843#Height 70
844 SkPaint paint;
845 SkRRect rrect = SkRRect::MakeRectXY({30, 10, 100, 60}, 20, 20);
846 canvas->drawRRect(rrect, paint);
847 rrect.setRectXY(rrect.getBounds(), 5, 5);
848 paint.setColor(SK_ColorWHITE);
849 paint.setBlendMode(SkBlendMode::kExclusion);
850 canvas->drawRRect(rrect, paint);
Cary Clark224c7002018-06-27 11:00:21 -0400851##
852
Cary Clark82f1f742018-06-28 08:50:35 -0400853#SeeAlso MakeRectXY SkPath::addRoundRect
Cary Clark224c7002018-06-27 11:00:21 -0400854
855#Method ##
856
857# ------------------------------------------------------------------------------
858
859#Method void setNinePatch(const SkRect& rect, SkScalar leftRad, SkScalar topRad,
860 SkScalar rightRad, SkScalar bottomRad)
Cary Clark82f1f742018-06-28 08:50:35 -0400861#In Set
862#Line # replaces with rounded rectangle ##
Cary Clark224c7002018-06-27 11:00:21 -0400863
Cary Clark82f1f742018-06-28 08:50:35 -0400864Sets bounds to rect. Sets radii to (leftRad, topRad), (rightRad, topRad),
865(rightRad, bottomRad), (leftRad, bottomRad).
Cary Clark224c7002018-06-27 11:00:21 -0400866
Cary Clark82f1f742018-06-28 08:50:35 -0400867If rect is empty, sets to kEmpty_Type.
868Otherwise, if leftRad and rightRad are zero, sets to kRect_Type.
869Otherwise, if topRad and bottomRad are zero, sets to kRect_Type.
870Otherwise, if leftRad and rightRad are equal and at least half rect.width(), and
871topRad and bottomRad are equal at least half rect.height(), sets to kOval_Type.
872Otherwise, if leftRad and rightRad are equal, and topRad and bottomRad are equal,
873sets to kSimple_Type. Otherwise, sets to kNinePatch_Type.
874
875Nine patch refers to the nine parts defined by the radii: one center rectangle,
876four edge patches, and four corner patches.
877
878#Param rect bounds of rounded rectangle ##
879#Param leftRad left-top and left-bottom x-axis radius ##
880#Param topRad left-top and right-top y-axis radius ##
881#Param rightRad right-top and right-bottom x-axis radius ##
882#Param bottomRad left-bottom and right-bottom y-axis radius ##
Cary Clark224c7002018-06-27 11:00:21 -0400883
884#Example
Cary Clark82f1f742018-06-28 08:50:35 -0400885#Height 70
886 SkPaint paint;
887 paint.setAntiAlias(true);
888 SkRRect rrect;
889 rrect.setNinePatch({30, 10, 100, 60}, 10, 20, 20, 10);
890 canvas->drawRRect(rrect, paint);
891 paint.setColor(SK_ColorWHITE);
892 const SkRect r = rrect.getBounds();
893 canvas->drawLine(r.fLeft, r.fTop + rrect.radii(SkRRect::kUpperLeft_Corner).fY,
894 r.fRight, r.fTop + rrect.radii(SkRRect::kUpperRight_Corner).fY, paint);
895 canvas->drawLine(r.fLeft, r.fBottom - rrect.radii(SkRRect::kLowerLeft_Corner).fY,
896 r.fRight, r.fBottom - rrect.radii(SkRRect::kLowerRight_Corner).fY, paint);
897 canvas->drawLine(r.fLeft + rrect.radii(SkRRect::kUpperLeft_Corner).fX, r.fTop,
898 r.fLeft + rrect.radii(SkRRect::kLowerLeft_Corner).fX, r.fBottom, paint);
899 canvas->drawLine(r.fRight - rrect.radii(SkRRect::kUpperRight_Corner).fX, r.fTop,
900 r.fRight - rrect.radii(SkRRect::kLowerRight_Corner).fX, r.fBottom, paint);
Cary Clark224c7002018-06-27 11:00:21 -0400901##
902
Cary Clark82f1f742018-06-28 08:50:35 -0400903#SeeAlso setRectRadii
Cary Clark224c7002018-06-27 11:00:21 -0400904
905#Method ##
906
907# ------------------------------------------------------------------------------
908
909#Method void setRectRadii(const SkRect& rect, const SkVector radii[4])
Cary Clark82f1f742018-06-28 08:50:35 -0400910#In Set
911#Line # replaces with rounded rectangle ##
Cary Clark224c7002018-06-27 11:00:21 -0400912
Cary Clark82f1f742018-06-28 08:50:35 -0400913Sets bounds to rect. Sets radii array for individual control of all for corners.
Cary Clark224c7002018-06-27 11:00:21 -0400914
Cary Clark82f1f742018-06-28 08:50:35 -0400915If rect is empty, sets to kEmpty_Type.
916Otherwise, if one of each corner radii are zero, sets to kRect_Type.
917Otherwise, if all x-axis radii are equal and at least half rect.width(), and
918all y-axis radii are equal at least half rect.height(), sets to kOval_Type.
919Otherwise, if all x-axis radii are equal, and all y-axis radii are equal,
920sets to kSimple_Type. Otherwise, sets to kNinePatch_Type.
921
922#Param rect bounds of rounded rectangle ##
923#Param radii corner x-axis and y-axis radii ##
Cary Clark224c7002018-06-27 11:00:21 -0400924
925#Example
Cary Clark80247e52018-07-11 16:18:41 -0400926#Height 128
Cary Clark53498e92018-06-28 19:13:56 -0400927 SkPaint paint;
928 paint.setStrokeWidth(15);
929 paint.setStrokeCap(SkPaint::kSquare_Cap);
930 paint.setAntiAlias(true);
931 float intervals[] = { 5, 21.75f };
932 paint.setStyle(SkPaint::kStroke_Style);
933 paint.setPathEffect(SkDashPathEffect::Make(intervals, SK_ARRAY_COUNT(intervals), 0));
934 SkPath path;
935 SkRRect rrect;
936 SkVector corners[] = {{15, 17}, {17, 19}, {19, 15}, {15, 15}};
937 rrect.setRectRadii({20, 20, 100, 100}, corners);
938 path.addRRect(rrect, SkPath::kCW_Direction);
939 canvas->drawPath(path, paint);
940 path.rewind();
941 path.addRRect(rrect, SkPath::kCCW_Direction, 1);
942 canvas->translate(120, 0);
943 canvas->drawPath(path, paint);
Cary Clark224c7002018-06-27 11:00:21 -0400944##
945
Cary Clark82f1f742018-06-28 08:50:35 -0400946#SeeAlso setNinePatch SkPath::addRoundRect
Cary Clark224c7002018-06-27 11:00:21 -0400947
948#Method ##
949
950# ------------------------------------------------------------------------------
951
952#Enum Corner
Cary Clark53498e92018-06-28 19:13:56 -0400953#Line # corner radii order ##
Cary Clark224c7002018-06-27 11:00:21 -0400954
955#Code
956 enum Corner {
957 kUpperLeft_Corner,
958 kUpperRight_Corner,
959 kLowerRight_Corner,
960 kLowerLeft_Corner,
961 };
962##
963
964The radii are stored: top-left, top-right, bottom-right, bottom-left.
965
Cary Clark53498e92018-06-28 19:13:56 -0400966#Const kUpperLeft_Corner 0
967#Line # index of top-left corner radii ##
Cary Clark224c7002018-06-27 11:00:21 -0400968##
Cary Clark53498e92018-06-28 19:13:56 -0400969#Const kUpperRight_Corner 1
970#Line # index of top-right corner radii ##
Cary Clark224c7002018-06-27 11:00:21 -0400971##
Cary Clark53498e92018-06-28 19:13:56 -0400972#Const kLowerRight_Corner 2
973#Line # index of bottom-right corner radii ##
Cary Clark224c7002018-06-27 11:00:21 -0400974##
Cary Clark53498e92018-06-28 19:13:56 -0400975#Const kLowerLeft_Corner 3
976#Line # index of bottom-left corner radii ##
Cary Clark224c7002018-06-27 11:00:21 -0400977##
978
979#Example
Cary Clark53498e92018-06-28 19:13:56 -0400980#Height 70
981 SkPaint paint;
982 paint.setAntiAlias(true);
983 SkRRect rrect;
984 SkVector corners[] = {{25, 17}, {17, 19}, {19, 15}, {15, 15}};
985 rrect.setRectRadii({30, 10, 100, 60}, corners);
986 canvas->drawRRect(rrect, paint);
987 paint.setColor(SK_ColorWHITE);
988 const SkRect r = rrect.getBounds();
989 canvas->drawLine(r.fLeft, r.fTop + rrect.radii(SkRRect::kUpperLeft_Corner).fY,
990 r.fRight, r.fTop + rrect.radii(SkRRect::kUpperRight_Corner).fY, paint);
991 canvas->drawLine(r.fLeft, r.fBottom - rrect.radii(SkRRect::kLowerLeft_Corner).fY,
992 r.fRight, r.fBottom - rrect.radii(SkRRect::kLowerRight_Corner).fY, paint);
993 canvas->drawLine(r.fLeft + rrect.radii(SkRRect::kUpperLeft_Corner).fX, r.fTop,
994 r.fLeft + rrect.radii(SkRRect::kLowerLeft_Corner).fX, r.fBottom, paint);
995 canvas->drawLine(r.fRight - rrect.radii(SkRRect::kUpperRight_Corner).fX, r.fTop,
996 r.fRight - rrect.radii(SkRRect::kLowerRight_Corner).fX, r.fBottom, paint);
Cary Clark224c7002018-06-27 11:00:21 -0400997##
998
Cary Clark53498e92018-06-28 19:13:56 -0400999#SeeAlso radii
Cary Clark224c7002018-06-27 11:00:21 -04001000
1001#Enum ##
1002
1003# ------------------------------------------------------------------------------
1004
1005#Method const SkRect& rect() const
Cary Clark53498e92018-06-28 19:13:56 -04001006#In Property
1007#Line # returns bounds ##
1008Returns bounds. Bounds may have zero width or zero height. Bounds right is
1009greater than or equal to left; bounds bottom is greater than or equal to top.
1010Result is identical to getBounds.
Cary Clark224c7002018-06-27 11:00:21 -04001011
Cary Clark53498e92018-06-28 19:13:56 -04001012#Return bounding box ##
Cary Clark224c7002018-06-27 11:00:21 -04001013
1014#Example
Cary Clark53498e92018-06-28 19:13:56 -04001015 for (SkScalar left : { SK_ScalarNaN, SK_ScalarInfinity, 100.f, 50.f, 25.f} ) {
1016 SkRRect rrect1 = SkRRect::MakeRectXY({left, 20, 60, 220}, 50, 200);
1017 SkDebugf("left bounds: (%g) %g\n", left, rrect1.rect().fLeft);
1018 }
1019#StdOut
1020left bounds: (nan) 0
1021left bounds: (inf) 0
1022left bounds: (100) 60
1023left bounds: (50) 50
1024left bounds: (25) 25
1025##
Cary Clark224c7002018-06-27 11:00:21 -04001026##
1027
Cary Clark53498e92018-06-28 19:13:56 -04001028#SeeAlso getBounds
Cary Clark224c7002018-06-27 11:00:21 -04001029
1030#Method ##
1031
1032# ------------------------------------------------------------------------------
1033
1034#Method SkVector radii(Corner corner) const
Cary Clark53498e92018-06-28 19:13:56 -04001035#In Property
1036#Line # returns x-axis and y-axis radii for one corner ##
1037Returns Scalar pair for radius of curve on x-axis and y-axis for one corner.
1038Both radii may be zero. If not zero, both are positive and finite.
Cary Clark224c7002018-06-27 11:00:21 -04001039
Cary Clark224c7002018-06-27 11:00:21 -04001040
Cary Clark53498e92018-06-28 19:13:56 -04001041#Param corner one of: kUpperLeft_Corner, kUpperRight_Corner,
1042 kLowerRight_Corner, kLowerLeft_Corner
Cary Clark224c7002018-06-27 11:00:21 -04001043##
1044
Cary Clark53498e92018-06-28 19:13:56 -04001045#Return x-axis and y-axis radii for one corner ##
1046
1047#Example
1048#Description
1049Finite values are scaled proportionately to fit; other values are set to zero.
Cary Clark80247e52018-07-11 16:18:41 -04001050Scaled values cannot be larger than 25, half the bounding Round_Rect width.
Cary Clark53498e92018-06-28 19:13:56 -04001051Small scaled values are halved to scale in proportion to the y-axis corner
1052radius, which is twice the bounds height.
1053##
1054 for (SkScalar radiusX : { SK_ScalarNaN, SK_ScalarInfinity, 100.f, 50.f, 25.f} ) {
1055 SkRRect rrect1 = SkRRect::MakeRectXY({10, 20, 60, 220}, radiusX, 200);
1056 SkDebugf("left corner: (%g) %g\n", radiusX, rrect1.radii(SkRRect::kUpperLeft_Corner).fX);
1057 }
1058#StdOut
1059left corner: (nan) 0
1060left corner: (inf) 0
1061left corner: (100) 25
1062left corner: (50) 25
1063left corner: (25) 12.5
1064##
1065##
1066
1067#SeeAlso Corner
Cary Clark224c7002018-06-27 11:00:21 -04001068
1069#Method ##
1070
1071# ------------------------------------------------------------------------------
1072
1073#Method const SkRect& getBounds() const
Cary Clark53498e92018-06-28 19:13:56 -04001074#In Property
1075#Line # returns bounds ##
1076Returns bounds. Bounds may have zero width or zero height. Bounds right is
1077greater than or equal to left; bounds bottom is greater than or equal to top.
1078Result is identical to rect().
Cary Clark224c7002018-06-27 11:00:21 -04001079
Cary Clark53498e92018-06-28 19:13:56 -04001080#Return bounding box ##
Cary Clark224c7002018-06-27 11:00:21 -04001081
1082#Example
Cary Clark53498e92018-06-28 19:13:56 -04001083#Height 120
1084 SkPaint paint;
1085 SkRRect rrect = SkRRect::MakeRectXY({20, 20, 220, 100}, 15, 15);
1086 canvas->drawRRect(rrect, paint);
1087 paint.setColor(SK_ColorWHITE);
1088 rrect = SkRRect::MakeOval(rrect.getBounds());
1089 canvas->drawRRect(rrect, paint);
Cary Clark224c7002018-06-27 11:00:21 -04001090##
1091
Cary Clark53498e92018-06-28 19:13:56 -04001092#SeeAlso rect
Cary Clark224c7002018-06-27 11:00:21 -04001093
1094#Method ##
1095
1096# ------------------------------------------------------------------------------
1097
1098#Method bool operator==(const SkRRect& a, const SkRRect& b)
Cary Clark61313f32018-10-08 14:57:48 -04001099#In Operators
Cary Clark53498e92018-06-28 19:13:56 -04001100#Line # returns true if members are equal ##
1101Returns true if bounds and radii in a are equal to bounds and radii in b.
Cary Clark224c7002018-06-27 11:00:21 -04001102
Cary Clark53498e92018-06-28 19:13:56 -04001103a and b are not equal if either contain NaN. a and b are equal if members
1104contain zeroes width different signs.
Cary Clark224c7002018-06-27 11:00:21 -04001105
Cary Clark53498e92018-06-28 19:13:56 -04001106#Param a Rect bounds and radii to compare ##
1107#Param b Rect bounds and radii to compare ##
1108
1109#Return true if members are equal ##
Cary Clark224c7002018-06-27 11:00:21 -04001110
1111#Example
Cary Clark53498e92018-06-28 19:13:56 -04001112 SkRRect rrect1 = SkRRect::MakeRectXY({10, 20, 60, 220}, 50, 200);
1113 SkRRect rrect2 = SkRRect::MakeRectXY(rrect1.rect(), 25, 100);
1114 SkRRect rrect3 = SkRRect::MakeOval(rrect1.rect());
1115 canvas->drawRRect(rrect1, SkPaint());
1116 std::string str = "rrect1 " + std::string(rrect1 == rrect2 ? "=" : "!") + "= rrect2";
1117 canvas->drawString(str.c_str(), 10, 240, SkPaint());
1118 canvas->translate(70, 0);
1119 canvas->drawRRect(rrect2, SkPaint());
1120 canvas->translate(70, 0);
1121 canvas->drawRRect(rrect3, SkPaint());
1122 str = "rrect2 " + std::string(rrect2 == rrect3 ? "=" : "!") + "= rrect3";
1123 canvas->drawString(str.c_str(), -20, 240, SkPaint());
Cary Clark224c7002018-06-27 11:00:21 -04001124##
1125
Cary Clark53498e92018-06-28 19:13:56 -04001126#SeeAlso operator!=(const SkRRect& a, const SkRRect& b)
Cary Clark224c7002018-06-27 11:00:21 -04001127
1128#Method ##
1129
1130# ------------------------------------------------------------------------------
1131
1132#Method bool operator!=(const SkRRect& a, const SkRRect& b)
Cary Clark61313f32018-10-08 14:57:48 -04001133#In Operators
Cary Clark53498e92018-06-28 19:13:56 -04001134#Line # returns true if members are unequal ##
1135Returns true if bounds and radii in a are not equal to bounds and radii in b.
Cary Clark224c7002018-06-27 11:00:21 -04001136
Cary Clark53498e92018-06-28 19:13:56 -04001137a and b are not equal if either contain NaN. a and b are equal if members
1138contain zeroes width different signs.
Cary Clark224c7002018-06-27 11:00:21 -04001139
Cary Clark53498e92018-06-28 19:13:56 -04001140#Param a Rect bounds and radii to compare ##
1141#Param b Rect bounds and radii to compare ##
1142
1143#Return true if members are not equal ##
Cary Clark224c7002018-06-27 11:00:21 -04001144
1145#Example
Cary Clark53498e92018-06-28 19:13:56 -04001146 SkRRect rrect1 = SkRRect::MakeRectXY({10, 20, 60, 220}, 50, 100);
1147 SkRRect rrect2 = SkRRect::MakeRectXY(rrect1.rect(), 50, 50);
1148 SkRRect rrect3 = SkRRect::MakeOval(rrect1.rect());
1149 canvas->drawRRect(rrect1, SkPaint());
1150 std::string str = "rrect1 " + std::string(rrect1 == rrect2 ? "=" : "!") + "= rrect2";
1151 canvas->drawString(str.c_str(), 10, 240, SkPaint());
1152 canvas->translate(70, 0);
1153 canvas->drawRRect(rrect2, SkPaint());
1154 canvas->translate(70, 0);
1155 canvas->drawRRect(rrect3, SkPaint());
1156 str = "rrect2 " + std::string(rrect2 == rrect3 ? "=" : "!") + "= rrect3";
1157 canvas->drawString(str.c_str(), -20, 240, SkPaint());
Cary Clark224c7002018-06-27 11:00:21 -04001158##
1159
Cary Clark53498e92018-06-28 19:13:56 -04001160#SeeAlso operator==(const SkRRect& a, const SkRRect& b)
Cary Clark224c7002018-06-27 11:00:21 -04001161
1162#Method ##
1163
1164# ------------------------------------------------------------------------------
1165
1166#Method void inset(SkScalar dx, SkScalar dy, SkRRect* dst) const
Cary Clark53498e92018-06-28 19:13:56 -04001167#In Inset_Outset_Offset
1168#Line # insets bounds and radii ##
Cary Clark224c7002018-06-27 11:00:21 -04001169
Cary Clark80247e52018-07-11 16:18:41 -04001170Copies Round_Rect to dst, then insets dst bounds by dx and dy, and adjusts dst
1171radii by dx and dy. dx and dy may be positive, negative, or zero. dst may be
1172Round_Rect.
1173
1174If either corner radius is zero, the corner has no curvature and is unchanged.
1175Otherwise, if adjusted radius becomes negative, pins radius to zero.
1176If dx exceeds half dst bounds width, dst bounds left and right are set to
1177bounds x-axis center. If dy exceeds half dst bounds height, dst bounds top and
1178bottom are set to bounds y-axis center.
1179
1180If dx or dy cause the bounds to become infinite, dst bounds is zeroed.
Cary Clark224c7002018-06-27 11:00:21 -04001181
Cary Clark53498e92018-06-28 19:13:56 -04001182#Param dx added to rect().fLeft, and subtracted from rect().fRight ##
1183#Param dy added to rect().fTop, and subtracted from rect().fBottom ##
1184#Param dst insets bounds and radii ##
Cary Clark224c7002018-06-27 11:00:21 -04001185
1186#Example
Cary Clark53498e92018-06-28 19:13:56 -04001187 SkPaint paint;
1188 paint.setAntiAlias(true);
1189 paint.setStyle(SkPaint::kStroke_Style);
1190 SkRRect rrect = SkRRect::MakeRectXY({100, 20, 140, 220}, 50, 100);
1191 for (int index = 0; index < 25; ++index) {
1192 canvas->drawRRect(rrect, paint);
1193 rrect.inset(-3, 3, &rrect);
1194 }
Cary Clark224c7002018-06-27 11:00:21 -04001195##
1196
Cary Clark53498e92018-06-28 19:13:56 -04001197#SeeAlso outset offset makeOffset
Cary Clark224c7002018-06-27 11:00:21 -04001198
1199#Method ##
1200
1201# ------------------------------------------------------------------------------
1202
1203#Method void inset(SkScalar dx, SkScalar dy)
Cary Clark53498e92018-06-28 19:13:56 -04001204#In Inset_Outset_Offset
1205#Line # insets bounds and radii ##
Cary Clark80247e52018-07-11 16:18:41 -04001206Insets bounds by dx and dy, and adjusts radii by dx and dy. dx and dy may be
1207positive, negative, or zero.
1208
1209If either corner radius is zero, the corner has no curvature and is unchanged.
1210Otherwise, if adjusted radius becomes negative, pins radius to zero.
1211If dx exceeds half bounds width, bounds left and right are set to
1212bounds x-axis center. If dy exceeds half bounds height, bounds top and
1213bottom are set to bounds y-axis center.
1214
1215If dx or dy cause the bounds to become infinite, bounds is zeroed.
Cary Clark224c7002018-06-27 11:00:21 -04001216
Cary Clark53498e92018-06-28 19:13:56 -04001217#Param dx added to rect().fLeft, and subtracted from rect().fRight ##
1218#Param dy added to rect().fTop, and subtracted from rect().fBottom ##
Cary Clark224c7002018-06-27 11:00:21 -04001219
1220#Example
Cary Clark53498e92018-06-28 19:13:56 -04001221 SkPaint paint;
1222 paint.setAntiAlias(true);
1223 paint.setStyle(SkPaint::kStroke_Style);
1224 SkRRect rrect = SkRRect::MakeRectXY({10, 20, 180, 220}, 50, 100);
1225 for (int index = 0; index < 25; ++index) {
1226 canvas->drawRRect(rrect, paint);
1227 rrect.inset(3, 3);
1228 }
Cary Clark224c7002018-06-27 11:00:21 -04001229##
1230
Cary Clark53498e92018-06-28 19:13:56 -04001231#SeeAlso outset offset makeOffset
1232
Cary Clark224c7002018-06-27 11:00:21 -04001233
1234#Method ##
1235
1236# ------------------------------------------------------------------------------
1237
1238#Method void outset(SkScalar dx, SkScalar dy, SkRRect* dst) const
Cary Clark53498e92018-06-28 19:13:56 -04001239#In Inset_Outset_Offset
1240#Line # outsets bounds and radii ##
Cary Clark224c7002018-06-27 11:00:21 -04001241
Cary Clark80247e52018-07-11 16:18:41 -04001242Outsets dst bounds by dx and dy, and adjusts radii by dx and dy. dx and dy may be
1243positive, negative, or zero.
1244
1245If either corner radius is zero, the corner has no curvature and is unchanged.
1246Otherwise, if adjusted radius becomes negative, pins radius to zero.
1247If dx exceeds half dst bounds width, dst bounds left and right are set to
1248bounds x-axis center. If dy exceeds half dst bounds height, dst bounds top and
1249bottom are set to bounds y-axis center.
1250
1251If dx or dy cause the bounds to become infinite, dst bounds is zeroed.
Cary Clark224c7002018-06-27 11:00:21 -04001252
Cary Clark53498e92018-06-28 19:13:56 -04001253#Param dx subtracted from rect().fLeft, and added to rect().fRight ##
1254#Param dy subtracted from rect().fTop, and added to rect().fBottom ##
1255#Param dst outset bounds and radii ##
Cary Clark224c7002018-06-27 11:00:21 -04001256
1257#Example
Cary Clark53498e92018-06-28 19:13:56 -04001258 SkPaint paint;
1259 paint.setAntiAlias(true);
1260 paint.setStyle(SkPaint::kStroke_Style);
1261 SkRRect rrect = SkRRect::MakeRectXY({100, 20, 140, 220}, 50, 100);
1262 for (int index = 0; index < 25; ++index) {
1263 canvas->drawRRect(rrect, paint);
1264 rrect.outset(-3, 3, &rrect);
1265 }
Cary Clark224c7002018-06-27 11:00:21 -04001266##
1267
Cary Clark53498e92018-06-28 19:13:56 -04001268#SeeAlso inset offset makeOffset
1269
Cary Clark224c7002018-06-27 11:00:21 -04001270
1271#Method ##
1272
1273# ------------------------------------------------------------------------------
1274
1275#Method void outset(SkScalar dx, SkScalar dy)
Cary Clark53498e92018-06-28 19:13:56 -04001276#In Inset_Outset_Offset
1277#Line # outsets bounds and radii ##
Cary Clark224c7002018-06-27 11:00:21 -04001278
Cary Clark80247e52018-07-11 16:18:41 -04001279Outsets bounds by dx and dy, and adjusts radii by dx and dy. dx and dy may be
1280positive, negative, or zero.
1281
1282If either corner radius is zero, the corner has no curvature and is unchanged.
1283Otherwise, if adjusted radius becomes negative, pins radius to zero.
1284If dx exceeds half bounds width, bounds left and right are set to
1285bounds x-axis center. If dy exceeds half bounds height, bounds top and
1286bottom are set to bounds y-axis center.
1287
1288If dx or dy cause the bounds to become infinite, bounds is zeroed.
1289
Cary Clark53498e92018-06-28 19:13:56 -04001290#Param dx subtracted from rect().fLeft, and added to rect().fRight ##
1291#Param dy subtracted from rect().fTop, and added to rect().fBottom ##
Cary Clark224c7002018-06-27 11:00:21 -04001292
1293#Example
Cary Clark53498e92018-06-28 19:13:56 -04001294 SkPaint paint;
1295 paint.setAntiAlias(true);
1296 paint.setStyle(SkPaint::kStroke_Style);
1297 SkRRect rrect = SkRRect::MakeRectXY({100, 20, 140, 220}, 50, 100);
1298 for (int index = 0; index < 25; ++index) {
1299 canvas->drawRRect(rrect, paint);
1300 rrect.outset(3, 3);
1301 }
Cary Clark224c7002018-06-27 11:00:21 -04001302##
1303
Cary Clark53498e92018-06-28 19:13:56 -04001304#SeeAlso inset offset makeOffset
Cary Clark224c7002018-06-27 11:00:21 -04001305
1306#Method ##
1307
1308# ------------------------------------------------------------------------------
1309
1310#Method void offset(SkScalar dx, SkScalar dy)
Cary Clark53498e92018-06-28 19:13:56 -04001311#In Inset_Outset_Offset
1312#Line # offsets bounds and radii ##
Cary Clark224c7002018-06-27 11:00:21 -04001313
Cary Clark80247e52018-07-11 16:18:41 -04001314Translates Round_Rect by (dx, dy).
Cary Clark224c7002018-06-27 11:00:21 -04001315
Cary Clark53498e92018-06-28 19:13:56 -04001316#Param dx offset added to rect().fLeft and rect().fRight ##
1317#Param dy offset added to rect().fTop and rect().fBottom ##
Cary Clark224c7002018-06-27 11:00:21 -04001318
1319#Example
Cary Clark53498e92018-06-28 19:13:56 -04001320 SkPaint paint;
1321 paint.setAntiAlias(true);
1322 paint.setStyle(SkPaint::kStroke_Style);
1323 SkRRect rrect = SkRRect::MakeRectXY({100, 20, 140, 220}, 50, 100);
1324 for (int index = 0; index < 25; ++index) {
1325 canvas->drawRRect(rrect, paint);
1326 rrect.offset(3, 3);
1327 }
Cary Clark224c7002018-06-27 11:00:21 -04001328##
1329
Cary Clark53498e92018-06-28 19:13:56 -04001330#SeeAlso makeOffset inset outset
Cary Clark224c7002018-06-27 11:00:21 -04001331
1332#Method ##
1333
1334# ------------------------------------------------------------------------------
1335
Cary Clark61313f32018-10-08 14:57:48 -04001336#Method SkRRect makeOffset(SkScalar dx, SkScalar dy) const
Cary Clark53498e92018-06-28 19:13:56 -04001337#In Inset_Outset_Offset
1338#Line # offsets bounds and radii ##
Cary Clark224c7002018-06-27 11:00:21 -04001339
Cary Clark80247e52018-07-11 16:18:41 -04001340Returns Round_Rect translated by (dx, dy).
1341
Cary Clark53498e92018-06-28 19:13:56 -04001342#Param dx offset added to rect().fLeft and rect().fRight ##
1343#Param dy offset added to rect().fTop and rect().fBottom ##
Cary Clark224c7002018-06-27 11:00:21 -04001344
Cary Clark53498e92018-06-28 19:13:56 -04001345#Return Round_Rect bounds offset by (dx, dy), with unchanged corner radii ##
Cary Clark224c7002018-06-27 11:00:21 -04001346
1347#Example
Cary Clark53498e92018-06-28 19:13:56 -04001348 SkPaint paint;
1349 paint.setAntiAlias(true);
1350 paint.setStyle(SkPaint::kStroke_Style);
1351 SkRRect rrect = SkRRect::MakeRectXY({100, 20, 140, 220}, 50, 100);
1352 for (int index = 0; index < 25; ++index) {
1353 canvas->drawRRect(rrect, paint);
1354 rrect = rrect.makeOffset(-3, 3);
1355 }
Cary Clark224c7002018-06-27 11:00:21 -04001356##
1357
Cary Clark53498e92018-06-28 19:13:56 -04001358#SeeAlso offset inset outset
Cary Clark224c7002018-06-27 11:00:21 -04001359
1360#Method ##
1361
1362# ------------------------------------------------------------------------------
1363
1364#Method bool contains(const SkRect& rect) const
Cary Clark53498e92018-06-28 19:13:56 -04001365#In Intersection
1366#Line # returns true if Rect is inside ##
Cary Clark224c7002018-06-27 11:00:21 -04001367
Cary Clark53498e92018-06-28 19:13:56 -04001368Returns true if rect is inside the bounds and corner radii, and if
1369Round_Rect and rect are not empty.
Cary Clark224c7002018-06-27 11:00:21 -04001370
Cary Clark53498e92018-06-28 19:13:56 -04001371#Param rect area tested for containment ##
Cary Clark224c7002018-06-27 11:00:21 -04001372
Cary Clark53498e92018-06-28 19:13:56 -04001373#Return true if Round_Rect contains rect ##
Cary Clark224c7002018-06-27 11:00:21 -04001374
1375#Example
Cary Clark80247e52018-07-11 16:18:41 -04001376#Height 110
1377 SkRect test = {10, 10, 110, 80};
1378 SkRRect rrect = SkRRect::MakeRect(test);
1379 SkRRect oval = SkRRect::MakeOval(test);
1380 test.inset(10, 10);
1381 SkPaint paint;
1382 paint.setAntiAlias(true);
1383 paint.setTextAlign(SkPaint::kCenter_Align);
1384 canvas->drawString(rrect.contains(test) ? "contains" : "does not contain", 55, 100, paint);
1385 canvas->drawString(oval.contains(test) ? "contains" : "does not contain", 185, 100, paint);
1386 paint.setStyle(SkPaint::kStroke_Style);
1387 canvas->drawRRect(rrect, paint);
1388 canvas->drawRect(test, paint);
1389 canvas->translate(120, 0);
1390 canvas->drawRRect(oval, paint);
1391 canvas->drawRect(test, paint);
Cary Clark224c7002018-06-27 11:00:21 -04001392##
1393
Cary Clark53498e92018-06-28 19:13:56 -04001394#SeeAlso SkRect::contains
Cary Clark224c7002018-06-27 11:00:21 -04001395
1396#Method ##
1397
1398# ------------------------------------------------------------------------------
1399
1400#Method bool isValid() const
Cary Clark53498e92018-06-28 19:13:56 -04001401#In Utility
Cary Clark80247e52018-07-11 16:18:41 -04001402#Line # returns if type() matches bounds and radii ##
1403Returns true if bounds and radii values are finite and describe a Round_Rect
1404Type that matches getType. All Round_Rect methods construct valid types,
1405even if the input values are not valid. Invalid Round_Rect data can only
1406be generated by corrupting memory.
Cary Clark224c7002018-06-27 11:00:21 -04001407
Cary Clark80247e52018-07-11 16:18:41 -04001408#Return true if bounds and radii match type() ##
Cary Clark224c7002018-06-27 11:00:21 -04001409
1410#Example
Cary Clark80247e52018-07-11 16:18:41 -04001411#Height 110
1412 SkRRect rrect = SkRRect::MakeRect({10, 10, 110, 80});
1413 SkRRect corrupt = rrect;
1414 *((float*) &corrupt) = 120;
1415 SkPaint paint;
1416 paint.setAntiAlias(true);
1417 paint.setTextAlign(SkPaint::kCenter_Align);
1418 canvas->drawString(rrect.isValid() ? "is valid" : "is corrupted", 55, 100, paint);
1419 canvas->drawString(corrupt.isValid() ? "is valid" : "is corrupted", 185, 100, paint);
1420 paint.setStyle(SkPaint::kStroke_Style);
1421 canvas->drawRRect(rrect, paint);
1422 canvas->translate(120, 0);
1423 canvas->drawRRect(corrupt, paint);
Cary Clark224c7002018-06-27 11:00:21 -04001424##
1425
Cary Clark80247e52018-07-11 16:18:41 -04001426#SeeAlso Type getType
Cary Clark224c7002018-06-27 11:00:21 -04001427
1428#Method ##
1429
1430# ------------------------------------------------------------------------------
1431
1432#Const kSizeInMemory 48
Cary Clark80247e52018-07-11 16:18:41 -04001433#Line # storage space for Round_Rect ##
Cary Clark224c7002018-06-27 11:00:21 -04001434
Cary Clark80247e52018-07-11 16:18:41 -04001435Space required to serialize SkRRect into a buffer. Always a multiple of four.
Cary Clark224c7002018-06-27 11:00:21 -04001436
1437#Const ##
1438
1439# ------------------------------------------------------------------------------
1440
1441#Method size_t writeToMemory(void* buffer) const
Cary Clark53498e92018-06-28 19:13:56 -04001442#In Utility
Cary Clark80247e52018-07-11 16:18:41 -04001443#Line # writes Round_Rect to buffer ##
Cary Clark224c7002018-06-27 11:00:21 -04001444
Cary Clark80247e52018-07-11 16:18:41 -04001445Writes Round_Rect to buffer. Writes kSizeInMemory bytes, and returns
1446kSizeInMemory, the number of bytes written.
Cary Clark224c7002018-06-27 11:00:21 -04001447
Cary Clark80247e52018-07-11 16:18:41 -04001448#Param buffer storage for Round_Rect ##
Cary Clark224c7002018-06-27 11:00:21 -04001449
Cary Clark80247e52018-07-11 16:18:41 -04001450#Return bytes written, kSizeInMemory ##
Cary Clark224c7002018-06-27 11:00:21 -04001451
1452#Example
Cary Clark80247e52018-07-11 16:18:41 -04001453#Height 110
1454 SkRRect rrect = SkRRect::MakeRect({10, 10, 110, 80});
1455 char storage[SkRRect::kSizeInMemory];
1456 rrect.writeToMemory(storage);
1457 SkRRect copy;
1458 copy.readFromMemory(storage, sizeof(storage));
1459 SkPaint paint;
1460 paint.setAntiAlias(true);
1461 paint.setTextAlign(SkPaint::kCenter_Align);
1462 canvas->drawString("rrect", 55, 100, paint);
1463 canvas->drawString("copy", 185, 100, paint);
1464 paint.setStyle(SkPaint::kStroke_Style);
1465 canvas->drawRRect(rrect, paint);
1466 canvas->translate(120, 0);
1467 canvas->drawRRect(copy, paint);
Cary Clark224c7002018-06-27 11:00:21 -04001468##
1469
Cary Clark80247e52018-07-11 16:18:41 -04001470#SeeAlso readFromMemory
Cary Clark224c7002018-06-27 11:00:21 -04001471
1472#Method ##
1473
1474# ------------------------------------------------------------------------------
1475
1476#Method size_t readFromMemory(const void* buffer, size_t length)
Cary Clark53498e92018-06-28 19:13:56 -04001477#In Utility
Cary Clark80247e52018-07-11 16:18:41 -04001478#Line # reads Round_Rect from buffer ##
Cary Clark224c7002018-06-27 11:00:21 -04001479
Cary Clark80247e52018-07-11 16:18:41 -04001480Reads Round_Rect from buffer, reading kSizeInMemory bytes.
1481Returns kSizeInMemory, bytes read if length is at least kSizeInMemory.
1482Otherwise, returns zero.
Cary Clark224c7002018-06-27 11:00:21 -04001483
Cary Clark80247e52018-07-11 16:18:41 -04001484#Param buffer memory to read from ##
1485#Param length size of buffer ##
Cary Clark224c7002018-06-27 11:00:21 -04001486
Cary Clark80247e52018-07-11 16:18:41 -04001487#Return bytes read, or 0 if length is less than kSizeInMemory
Cary Clark224c7002018-06-27 11:00:21 -04001488##
1489
1490#Example
Cary Clark80247e52018-07-11 16:18:41 -04001491#Height 110
1492 SkVector radii[] = {{5, 5}, {10, 10}, {15, 15}, {5, 5}};
1493 SkRRect rrect;
1494 rrect.setRectRadii({10, 10, 110, 80}, radii);
1495 char storage[SkRRect::kSizeInMemory];
1496 rrect.writeToMemory(storage);
1497 SkRRect copy;
1498 copy.readFromMemory(storage, sizeof(storage));
1499 SkPaint paint;
1500 paint.setAntiAlias(true);
1501 paint.setTextAlign(SkPaint::kCenter_Align);
1502 canvas->drawString("rrect", 55, 100, paint);
1503 canvas->drawString("copy", 185, 100, paint);
1504 paint.setStyle(SkPaint::kStroke_Style);
1505 canvas->drawRRect(rrect, paint);
1506 canvas->translate(120, 0);
1507 canvas->drawRRect(copy, paint);
Cary Clark224c7002018-06-27 11:00:21 -04001508##
1509
Cary Clark80247e52018-07-11 16:18:41 -04001510#SeeAlso writeToMemory
Cary Clark224c7002018-06-27 11:00:21 -04001511
1512#Method ##
1513
1514# ------------------------------------------------------------------------------
1515
1516#Method bool transform(const SkMatrix& matrix, SkRRect* dst) const
Cary Clark53498e92018-06-28 19:13:56 -04001517#In Inset_Outset_Offset
1518#Line # scales and offsets into copy ##
Cary Clark224c7002018-06-27 11:00:21 -04001519
Cary Clark53498e92018-06-28 19:13:56 -04001520Transforms by Round_Rect by matrix, storing result in dst.
1521Returns true if Round_Rect transformed can be represented by another Round_Rect.
1522Returns false if matrix contains transformations other than scale and translate.
Cary Clark224c7002018-06-27 11:00:21 -04001523
Cary Clark53498e92018-06-28 19:13:56 -04001524Asserts in debug builds if Round_Rect equals dst.
Cary Clark224c7002018-06-27 11:00:21 -04001525
Cary Clark53498e92018-06-28 19:13:56 -04001526#Param matrix SkMatrix specifying the transform ##
1527#Param dst SkRRect to store the result ##
1528
1529#Return true if transformation succeeded.
Cary Clark224c7002018-06-27 11:00:21 -04001530##
1531
1532#Example
Cary Clark80247e52018-07-11 16:18:41 -04001533#Height 110
1534 SkVector radii[] = {{5, 5}, {10, 10}, {15, 15}, {5, 5}};
1535 SkRRect rrect;
1536 rrect.setRectRadii({10, 10, 110, 80}, radii);
1537 SkRRect transformed;
1538 SkMatrix matrix = SkMatrix::MakeRectToRect(rrect.rect(), {140, 30, 220, 80},
1539 SkMatrix::kCenter_ScaleToFit);
1540 bool success = rrect.transform(matrix, &transformed);
1541 SkPaint paint;
1542 paint.setAntiAlias(true);
1543 paint.setTextAlign(SkPaint::kCenter_Align);
1544 canvas->drawString("rrect", 55, 100, paint);
1545 canvas->drawString(success ? "transformed" : "transform failed", 185, 100, paint);
1546 paint.setStyle(SkPaint::kStroke_Style);
1547 canvas->drawRRect(rrect, paint);
1548 canvas->drawRRect(transformed, paint);
Cary Clark224c7002018-06-27 11:00:21 -04001549##
1550
Cary Clark80247e52018-07-11 16:18:41 -04001551#SeeAlso SkPath::transform
Cary Clark224c7002018-06-27 11:00:21 -04001552
1553#Method ##
1554
1555# ------------------------------------------------------------------------------
1556
1557#Method void dump(bool asHex) const
Cary Clark53498e92018-06-28 19:13:56 -04001558#In Utility
1559#Line # sends text representation to standard output ##
1560Writes text representation of Round_Rect to standard output.
1561Set asHex true to generate exact binary representations
1562of floating point numbers.
Cary Clark224c7002018-06-27 11:00:21 -04001563
Cary Clark53498e92018-06-28 19:13:56 -04001564#Param asHex true if SkScalar values are written as hexadecimal ##
Cary Clark224c7002018-06-27 11:00:21 -04001565
1566#Example
Cary Clark53498e92018-06-28 19:13:56 -04001567SkRRect rrect = SkRRect::MakeRect({6.f / 7, 2.f / 3, 6.f / 7, 2.f / 3});
1568for (bool dumpAsHex : { false, true } ) {
1569 rrect.dump(dumpAsHex);
1570}
1571#StdOut
1572SkRect::MakeLTRB(0.857143f, 0.666667f, 0.857143f, 0.666667f);
1573const SkPoint corners[] = {
1574 { 0, 0 },
1575 { 0, 0 },
1576 { 0, 0 },
1577 { 0, 0 },
1578};
1579SkRect::MakeLTRB(SkBits2Float(0x3f5b6db7), /* 0.857143 */
1580 SkBits2Float(0x3f2aaaab), /* 0.666667 */
1581 SkBits2Float(0x3f5b6db7), /* 0.857143 */
1582 SkBits2Float(0x3f2aaaab) /* 0.666667 */);
1583const SkPoint corners[] = {
1584 { SkBits2Float(0x00000000), SkBits2Float(0x00000000) }, /* 0.000000 0.000000 */
1585 { SkBits2Float(0x00000000), SkBits2Float(0x00000000) }, /* 0.000000 0.000000 */
1586 { SkBits2Float(0x00000000), SkBits2Float(0x00000000) }, /* 0.000000 0.000000 */
1587 { SkBits2Float(0x00000000), SkBits2Float(0x00000000) }, /* 0.000000 0.000000 */
1588};
1589##
Cary Clark224c7002018-06-27 11:00:21 -04001590##
1591
Cary Clark53498e92018-06-28 19:13:56 -04001592#SeeAlso dumpHex SkRect::dump SkPath::dump SkPathMeasure::dump
Cary Clark224c7002018-06-27 11:00:21 -04001593
1594#Method ##
1595
1596# ------------------------------------------------------------------------------
1597
1598#Method void dump() const
Cary Clark53498e92018-06-28 19:13:56 -04001599#In Utility
1600#Line # sends text representation using floats to standard output ##
1601Writes text representation of Round_Rect to standard output. The representation
1602may be directly compiled as C++ code. Floating point values are written
1603with limited precision; it may not be possible to reconstruct original
1604Round_Rect from output.
Cary Clark224c7002018-06-27 11:00:21 -04001605
1606#Example
Cary Clark53498e92018-06-28 19:13:56 -04001607SkRRect rrect = SkRRect::MakeRect({6.f / 7, 2.f / 3, 6.f / 7, 2.f / 3});
1608rrect.dump();
1609SkRect bounds = SkRect::MakeLTRB(0.857143f, 0.666667f, 0.857143f, 0.666667f);
1610const SkPoint corners[] = {
1611 { 0, 0 },
1612 { 0, 0 },
1613 { 0, 0 },
1614 { 0, 0 },
1615};
1616SkRRect copy;
1617copy.setRectRadii(bounds, corners);
1618SkDebugf("rrect is " "%s" "equal to copy\n", rrect == copy ? "" : "not ");
1619#StdOut
1620SkRect::MakeLTRB(0.857143f, 0.666667f, 0.857143f, 0.666667f);
1621const SkPoint corners[] = {
1622 { 0, 0 },
1623 { 0, 0 },
1624 { 0, 0 },
1625 { 0, 0 },
1626};
1627rrect is not equal to copy
1628##
Cary Clark224c7002018-06-27 11:00:21 -04001629##
1630
Cary Clark53498e92018-06-28 19:13:56 -04001631#SeeAlso dumpHex SkRect::dump SkPath::dump SkPathMeasure::dump
Cary Clark224c7002018-06-27 11:00:21 -04001632
1633#Method ##
1634
1635# ------------------------------------------------------------------------------
1636
1637#Method void dumpHex() const
Cary Clark53498e92018-06-28 19:13:56 -04001638#In Utility
1639#Line # sends text representation using hexadecimal to standard output ##
1640Writes text representation of Round_Rect to standard output. The representation
1641may be directly compiled as C++ code. Floating point values are written
1642in hexadecimal to preserve their exact bit pattern. The output reconstructs the
1643original Round_Rect.
Cary Clark224c7002018-06-27 11:00:21 -04001644
1645#Example
Cary Clark53498e92018-06-28 19:13:56 -04001646SkRRect rrect = SkRRect::MakeRect({6.f / 7, 2.f / 3, 6.f / 7, 2.f / 3});
1647rrect.dumpHex();
1648SkRect bounds = SkRect::MakeLTRB(SkBits2Float(0x3f5b6db7), /* 0.857143 */
1649 SkBits2Float(0x3f2aaaab), /* 0.666667 */
1650 SkBits2Float(0x3f5b6db7), /* 0.857143 */
1651 SkBits2Float(0x3f2aaaab) /* 0.666667 */);
1652const SkPoint corners[] = {
1653 { SkBits2Float(0x00000000), SkBits2Float(0x00000000) }, /* 0.000000 0.000000 */
1654 { SkBits2Float(0x00000000), SkBits2Float(0x00000000) }, /* 0.000000 0.000000 */
1655 { SkBits2Float(0x00000000), SkBits2Float(0x00000000) }, /* 0.000000 0.000000 */
1656 { SkBits2Float(0x00000000), SkBits2Float(0x00000000) }, /* 0.000000 0.000000 */
1657};
1658SkRRect copy;
1659copy.setRectRadii(bounds, corners);
1660SkDebugf("rrect is " "%s" "equal to copy\n", rrect == copy ? "" : "not ");
1661#StdOut
1662SkRect::MakeLTRB(SkBits2Float(0x3f5b6db7), /* 0.857143 */
1663 SkBits2Float(0x3f2aaaab), /* 0.666667 */
1664 SkBits2Float(0x3f5b6db7), /* 0.857143 */
1665 SkBits2Float(0x3f2aaaab) /* 0.666667 */);
1666const SkPoint corners[] = {
1667 { SkBits2Float(0x00000000), SkBits2Float(0x00000000) }, /* 0.000000 0.000000 */
1668 { SkBits2Float(0x00000000), SkBits2Float(0x00000000) }, /* 0.000000 0.000000 */
1669 { SkBits2Float(0x00000000), SkBits2Float(0x00000000) }, /* 0.000000 0.000000 */
1670 { SkBits2Float(0x00000000), SkBits2Float(0x00000000) }, /* 0.000000 0.000000 */
1671};
1672rrect is equal to copy
1673##
Cary Clark224c7002018-06-27 11:00:21 -04001674##
1675
Cary Clark53498e92018-06-28 19:13:56 -04001676#SeeAlso dump SkRect::dumpHex SkPath::dumpHex
Cary Clark224c7002018-06-27 11:00:21 -04001677
1678#Method ##
1679
1680#Class SkRRect ##
1681
1682#Topic RRect ##