OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2012 Google Inc. | 2 * Copyright 2012 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #ifndef SkRRect_DEFINED | 8 #ifndef SkRRect_DEFINED |
9 #define SkRRect_DEFINED | 9 #define SkRRect_DEFINED |
10 | 10 |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
64 | 64 |
65 //!< The RR is actually a (non-empty) oval (i.e., all x radii are equal | 65 //!< The RR is actually a (non-empty) oval (i.e., all x radii are equal |
66 //!< and >= width/2 and all the y radii are equal and >= height/2 | 66 //!< and >= width/2 and all the y radii are equal and >= height/2 |
67 kOval_Type, | 67 kOval_Type, |
68 | 68 |
69 //!< The RR is non-empty and all the x radii are equal & all y radii | 69 //!< The RR is non-empty and all the x radii are equal & all y radii |
70 //!< are equal but it is not an oval (i.e., there are lines between | 70 //!< are equal but it is not an oval (i.e., there are lines between |
71 //!< the curves) nor a rect (i.e., both radii are non-zero) | 71 //!< the curves) nor a rect (i.e., both radii are non-zero) |
72 kSimple_Type, | 72 kSimple_Type, |
73 | 73 |
| 74 //!< The RR is non-empty and the two left x radii are equal, the two top |
| 75 //!< y radii are equal, and the same for the right and bottom but it is |
| 76 //!< neither an rect, oval, nor a simple RR. It is called "nine patch" |
| 77 //!< because the centers of the corner ellipses form an axis aligned |
| 78 //!< rect with edges that divide the RR into an 9 rectangular patches: |
| 79 //!< an interior patch, four edge patches, and four corner patches. |
| 80 kNinePatch_Type, |
| 81 |
74 //!< A fully general (non-empty) RR. Some of the x and/or y radii are | 82 //!< A fully general (non-empty) RR. Some of the x and/or y radii are |
75 //!< different from the others and there must be one corner where | 83 //!< different from the others and there must be one corner where |
76 //!< both radii are non-zero. | 84 //!< both radii are non-zero. |
77 kComplex_Type, | 85 kComplex_Type, |
78 }; | 86 }; |
79 | 87 |
80 /** | 88 /** |
81 * Returns the RR's sub type. | 89 * Returns the RR's sub type. |
82 */ | 90 */ |
83 Type getType() const { | 91 Type getType() const { |
84 SkDEBUGCODE(this->validate();) | 92 SkDEBUGCODE(this->validate();) |
85 | 93 |
86 if (kUnknown_Type == fType) { | 94 if (kUnknown_Type == fType) { |
87 this->computeType(); | 95 this->computeType(); |
88 } | 96 } |
89 SkASSERT(kUnknown_Type != fType); | 97 SkASSERT(kUnknown_Type != fType); |
90 return fType; | 98 return fType; |
91 } | 99 } |
92 | 100 |
93 Type type() const { return this->getType(); } | 101 Type type() const { return this->getType(); } |
94 | 102 |
95 inline bool isEmpty() const { return kEmpty_Type == this->getType(); } | 103 inline bool isEmpty() const { return kEmpty_Type == this->getType(); } |
96 inline bool isRect() const { return kRect_Type == this->getType(); } | 104 inline bool isRect() const { return kRect_Type == this->getType(); } |
97 inline bool isOval() const { return kOval_Type == this->getType(); } | 105 inline bool isOval() const { return kOval_Type == this->getType(); } |
98 inline bool isSimple() const { return kSimple_Type == this->getType(); } | 106 inline bool isSimple() const { return kSimple_Type == this->getType(); } |
99 inline bool isSimpleCircular() const { | 107 inline bool isSimpleCircular() const { |
100 return this->isSimple() && fRadii[0].fX == fRadii[0].fY; | 108 return this->isSimple() && fRadii[0].fX == fRadii[0].fY; |
101 } | 109 } |
| 110 inline bool isNinePatch() const { return kNinePatch_Type == this->getType();
} |
102 inline bool isComplex() const { return kComplex_Type == this->getType(); } | 111 inline bool isComplex() const { return kComplex_Type == this->getType(); } |
103 | 112 |
104 bool allCornersCircular() const; | 113 bool allCornersCircular() const; |
105 | 114 |
106 /** | |
107 * Are both x-radii the same on the two left corners, and similar for the to
p, right, and | |
108 * bottom. When this is the case the four ellipse centers form a rectangle. | |
109 */ | |
110 bool isNinePatch() const { | |
111 return fRadii[kUpperLeft_Corner].fX == fRadii[kLowerLeft_Corner].fX && | |
112 fRadii[kUpperRight_Corner].fX == fRadii[kLowerRight_Corner].fX && | |
113 fRadii[kUpperLeft_Corner].fY == fRadii[kUpperRight_Corner].fY && | |
114 fRadii[kLowerLeft_Corner].fY == fRadii[kLowerRight_Corner].fY; | |
115 } | |
116 | |
117 SkScalar width() const { return fRect.width(); } | 115 SkScalar width() const { return fRect.width(); } |
118 SkScalar height() const { return fRect.height(); } | 116 SkScalar height() const { return fRect.height(); } |
119 | 117 |
120 /** | 118 /** |
121 * Set this RR to the empty rectangle (0,0,0,0) with 0 x & y radii. | 119 * Set this RR to the empty rectangle (0,0,0,0) with 0 x & y radii. |
122 */ | 120 */ |
123 void setEmpty() { | 121 void setEmpty() { |
124 fRect.setEmpty(); | 122 fRect.setEmpty(); |
125 memset(fRadii, 0, sizeof(fRadii)); | 123 memset(fRadii, 0, sizeof(fRadii)); |
126 fType = kEmpty_Type; | 124 fType = kEmpty_Type; |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
165 | 163 |
166 SkDEBUGCODE(this->validate();) | 164 SkDEBUGCODE(this->validate();) |
167 } | 165 } |
168 | 166 |
169 /** | 167 /** |
170 * Initialize the RR with the same radii for all four corners. | 168 * Initialize the RR with the same radii for all four corners. |
171 */ | 169 */ |
172 void setRectXY(const SkRect& rect, SkScalar xRad, SkScalar yRad); | 170 void setRectXY(const SkRect& rect, SkScalar xRad, SkScalar yRad); |
173 | 171 |
174 /** | 172 /** |
| 173 * Initialize the rr with one radius per-side. |
| 174 */ |
| 175 void setNinePatch(const SkRect& rect, SkScalar leftRad, SkScalar topRad, |
| 176 SkScalar rightRad, SkScalar bottomRad); |
| 177 |
| 178 /** |
175 * Initialize the RR with potentially different radii for all four corners. | 179 * Initialize the RR with potentially different radii for all four corners. |
176 */ | 180 */ |
177 void setRectRadii(const SkRect& rect, const SkVector radii[4]); | 181 void setRectRadii(const SkRect& rect, const SkVector radii[4]); |
178 | 182 |
179 // The radii are stored in UL, UR, LR, LL order. | 183 // The radii are stored in UL, UR, LR, LL order. |
180 enum Corner { | 184 enum Corner { |
181 kUpperLeft_Corner, | 185 kUpperLeft_Corner, |
182 kUpperRight_Corner, | 186 kUpperRight_Corner, |
183 kLowerRight_Corner, | 187 kLowerRight_Corner, |
184 kLowerLeft_Corner | 188 kLowerLeft_Corner |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
297 // uninitialized data | 301 // uninitialized data |
298 | 302 |
299 void computeType() const; | 303 void computeType() const; |
300 bool checkCornerContainment(SkScalar x, SkScalar y) const; | 304 bool checkCornerContainment(SkScalar x, SkScalar y) const; |
301 | 305 |
302 // to access fRadii directly | 306 // to access fRadii directly |
303 friend class SkPath; | 307 friend class SkPath; |
304 }; | 308 }; |
305 | 309 |
306 #endif | 310 #endif |
OLD | NEW |