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 #include "SkRRect.h" | 8 #include "SkRRect.h" |
9 #include "SkMatrix.h" | |
9 | 10 |
10 /////////////////////////////////////////////////////////////////////////////// | 11 /////////////////////////////////////////////////////////////////////////////// |
11 | 12 |
12 void SkRRect::setRectXY(const SkRect& rect, SkScalar xRad, SkScalar yRad) { | 13 void SkRRect::setRectXY(const SkRect& rect, SkScalar xRad, SkScalar yRad) { |
13 if (rect.isEmpty()) { | 14 if (rect.isEmpty()) { |
14 this->setEmpty(); | 15 this->setEmpty(); |
15 return; | 16 return; |
16 } | 17 } |
17 | 18 |
18 if (xRad <= 0 || yRad <= 0) { | 19 if (xRad <= 0 || yRad <= 0) { |
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
247 fType = kOval_Type; | 248 fType = kOval_Type; |
248 } else { | 249 } else { |
249 fType = kSimple_Type; | 250 fType = kSimple_Type; |
250 } | 251 } |
251 return; | 252 return; |
252 } | 253 } |
253 | 254 |
254 fType = kComplex_Type; | 255 fType = kComplex_Type; |
255 } | 256 } |
256 | 257 |
258 static bool matrix_only_scale_and_translate(const SkMatrix& matrix) { | |
259 const SkMatrix::TypeMask m = (SkMatrix::TypeMask) (SkMatrix::kAffine_Mask | |
260 | SkMatrix::kPerspective_Mask); | |
261 return (matrix.getType() & m) == 0; | |
262 } | |
263 | |
264 bool SkRRect::transform(const SkMatrix& matrix, SkRRect* dst) const { | |
robertphillips
2013/10/30 23:55:02
This seems like a complete abrogation of the const
scroggo
2013/10/31 17:40:35
Agreed. This is to be consistent with SkPath::tran
| |
265 if (NULL == dst) { | |
266 dst = const_cast<SkRRect*>(this); | |
267 } | |
268 | |
269 if (matrix.isIdentity()) { | |
270 *dst = *this; | |
271 return true; | |
272 } | |
273 | |
274 if (!matrix_only_scale_and_translate(matrix)) { | |
275 return false; | |
276 } | |
277 | |
278 SkRect newRect; | |
279 if (!matrix.mapRect(&newRect, fRect)) { | |
280 return false; | |
281 } | |
282 | |
robertphillips
2013/10/30 23:55:02
Will this do the right thing if the matrix is a re
scroggo
2013/10/31 17:40:35
No. Fixed.
| |
283 // Now scale each corner | |
284 SkScalar xScale = matrix.getScaleX(); | |
285 if (xScale < 0) { | |
286 xScale = -xScale; | |
287 } | |
288 SkScalar yScale = matrix.getScaleY(); | |
289 if (yScale < 0) { | |
290 yScale = -yScale; | |
291 } | |
robertphillips
2013/10/30 23:55:02
Do we actually need "radii" here? Can't we do this
scroggo
2013/10/31 17:40:35
Done.
| |
292 SkVector radii[4]; | |
293 for (int i = 0; i < 4; ++i) { | |
294 radii[i].fX = fRadii[i].fX * xScale; | |
295 radii[i].fY = fRadii[i].fY * yScale; | |
296 } | |
297 dst->setRectRadii(newRect, radii); | |
298 return true; | |
299 } | |
300 | |
257 /////////////////////////////////////////////////////////////////////////////// | 301 /////////////////////////////////////////////////////////////////////////////// |
258 | 302 |
259 void SkRRect::inset(SkScalar dx, SkScalar dy, SkRRect* dst) const { | 303 void SkRRect::inset(SkScalar dx, SkScalar dy, SkRRect* dst) const { |
260 SkRect r = fRect; | 304 SkRect r = fRect; |
261 | 305 |
262 r.inset(dx, dy); | 306 r.inset(dx, dy); |
263 if (r.isEmpty()) { | 307 if (r.isEmpty()) { |
264 dst->setEmpty(); | 308 dst->setEmpty(); |
265 return; | 309 return; |
266 } | 310 } |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
352 SkASSERT(!allRadiiZero && !allRadiiSame && !allCornersSquare); | 396 SkASSERT(!allRadiiZero && !allRadiiSame && !allCornersSquare); |
353 break; | 397 break; |
354 case kUnknown_Type: | 398 case kUnknown_Type: |
355 // no limits on this | 399 // no limits on this |
356 break; | 400 break; |
357 } | 401 } |
358 } | 402 } |
359 #endif // SK_DEBUG | 403 #endif // SK_DEBUG |
360 | 404 |
361 /////////////////////////////////////////////////////////////////////////////// | 405 /////////////////////////////////////////////////////////////////////////////// |
OLD | NEW |