OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 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 "SkNinePatchIter.h" | 8 #include "SkNinePatchIter.h" |
9 #include "SkRect.h" | 9 #include "SkRect.h" |
10 | 10 |
11 bool SkNinePatchIter::Valid(int width, int height, const SkIRect& center) { | 11 bool SkNinePatchIter::Valid(int width, int height, const SkIRect& center) { |
12 return !center.isEmpty() && SkIRect::MakeWH(width, height).contains(center); | 12 return !center.isEmpty() && SkIRect::MakeWH(width, height).contains(center); |
13 } | 13 } |
14 | 14 |
15 SkNinePatchIter::SkNinePatchIter(int w, int h, const SkIRect& c, const SkRect& d
st) { | 15 SkNinePatchIter::SkNinePatchIter(int w, int h, const SkIRect& c, const SkRect& d
st) { |
16 SkASSERT(SkIRect::MakeWH(w, h).contains(c)); | 16 SkASSERT(SkIRect::MakeWH(w, h).contains(c)); |
17 | 17 |
18 fSrcX[0] = 0; | 18 fSrcX[0] = 0; |
19 fSrcX[1] = SkIntToScalar(c.fLeft); | 19 fSrcX[1] = SkIntToScalar(c.fLeft); |
20 fSrcX[2] = SkIntToScalar(c.fRight); | 20 fSrcX[2] = SkIntToScalar(c.fRight); |
21 fSrcX[3] = SkIntToScalar(w); | 21 fSrcX[3] = SkIntToScalar(w); |
22 | 22 |
23 fSrcY[0] = 0; | 23 fSrcY[0] = 0; |
24 fSrcY[1] = SkIntToScalar(c.fTop); | 24 fSrcY[1] = SkIntToScalar(c.fTop); |
25 fSrcY[2] = SkIntToScalar(c.fBottom); | 25 fSrcY[2] = SkIntToScalar(c.fBottom); |
26 fSrcY[3] = SkIntToScalar(h); | 26 fSrcY[3] = SkIntToScalar(h); |
27 | 27 |
28 fDstX[0] = dst.fLeft; | 28 fDstX[0] = dst.fLeft; |
29 fDstX[1] = dst.fLeft + SkIntToScalar(c.fLeft); | 29 fDstX[1] = dst.fLeft + SkIntToScalar(c.fLeft); |
30 fDstX[2] = dst.fRight - SkIntToScalar(w - c.fRight); | 30 fDstX[2] = dst.fRight - SkIntToScalar(w - c.fRight); |
31 fDstX[3] = dst.fRight; | 31 fDstX[3] = dst.fRight; |
32 | 32 |
33 fDstY[0] = dst.fTop; | 33 fDstY[0] = dst.fTop; |
34 fDstY[1] = dst.fTop + SkIntToScalar(c.fTop); | 34 fDstY[1] = dst.fTop + SkIntToScalar(c.fTop); |
35 fDstY[2] = dst.fBottom - SkIntToScalar(h - c.fBottom); | 35 fDstY[2] = dst.fBottom - SkIntToScalar(h - c.fBottom); |
36 fDstY[3] = dst.fBottom; | 36 fDstY[3] = dst.fBottom; |
37 | 37 |
38 if (fDstX[1] > fDstX[2]) { | 38 if (fDstX[1] > fDstX[2]) { |
39 fDstX[1] = fDstX[0] + (fDstX[3] - fDstX[0]) * c.fLeft / (w - c.width()); | 39 fDstX[1] = fDstX[0] + (fDstX[3] - fDstX[0]) * c.fLeft / (w - c.width()); |
40 fDstX[2] = fDstX[1]; | 40 fDstX[2] = fDstX[1]; |
41 } | 41 } |
42 | 42 |
43 if (fDstY[1] > fDstY[2]) { | 43 if (fDstY[1] > fDstY[2]) { |
44 fDstY[1] = fDstY[0] + (fDstY[3] - fDstY[0]) * c.fTop / (h - c.height()); | 44 fDstY[1] = fDstY[0] + (fDstY[3] - fDstY[0]) * c.fTop / (h - c.height()); |
45 fDstY[2] = fDstY[1]; | 45 fDstY[2] = fDstY[1]; |
46 } | 46 } |
47 | 47 |
(...skipping 15 matching lines...) Expand all Loading... |
63 dst->set(fDstX[x], fDstY[y], fDstX[x + 1], fDstY[y + 1]); | 63 dst->set(fDstX[x], fDstY[y], fDstX[x + 1], fDstY[y + 1]); |
64 if (3 == ++fCurrX) { | 64 if (3 == ++fCurrX) { |
65 fCurrX = 0; | 65 fCurrX = 0; |
66 fCurrY += 1; | 66 fCurrY += 1; |
67 if (fCurrY >= 3) { | 67 if (fCurrY >= 3) { |
68 fDone = true; | 68 fDone = true; |
69 } | 69 } |
70 } | 70 } |
71 return true; | 71 return true; |
72 } | 72 } |
OLD | NEW |