| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 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 "gm.h" | 8 #include "gm.h" |
| 9 #include "SkSurface.h" | 9 #include "SkSurface.h" |
| 10 | 10 |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 protected: | 63 protected: |
| 64 SkString onShortName() override { | 64 SkString onShortName() override { |
| 65 return SkString("ninepatch-stretch"); | 65 return SkString("ninepatch-stretch"); |
| 66 } | 66 } |
| 67 | 67 |
| 68 SkISize onISize() override { | 68 SkISize onISize() override { |
| 69 return SkISize::Make(760, 400); | 69 return SkISize::Make(760, 400); |
| 70 } | 70 } |
| 71 | 71 |
| 72 void onDraw(SkCanvas* canvas) override { | 72 void onDraw(SkCanvas* canvas) override { |
| 73 if (NULL == fBitmap.pixelRef()) { | 73 if (nullptr == fBitmap.pixelRef()) { |
| 74 fImage.reset(make_image(canvas, &fCenter)); | 74 fImage.reset(make_image(canvas, &fCenter)); |
| 75 image_to_bitmap(fImage, &fBitmap); | 75 image_to_bitmap(fImage, &fBitmap); |
| 76 } | 76 } |
| 77 | 77 |
| 78 // amount of bm that should not be stretched (unless we have to) | 78 // amount of bm that should not be stretched (unless we have to) |
| 79 const SkScalar fixed = SkIntToScalar(fBitmap.width() - fCenter.width()); | 79 const SkScalar fixed = SkIntToScalar(fBitmap.width() - fCenter.width()); |
| 80 | 80 |
| 81 const SkTSize<SkScalar> size[] = { | 81 const SkTSize<SkScalar> size[] = { |
| 82 { fixed * 4 / 5, fixed * 4 / 5 }, // shrink in both axes | 82 { fixed * 4 / 5, fixed * 4 / 5 }, // shrink in both axes |
| 83 { fixed * 4 / 5, fixed * 4 }, // shrink in X | 83 { fixed * 4 / 5, fixed * 4 }, // shrink in X |
| 84 { fixed * 4, fixed * 4 / 5 }, // shrink in Y | 84 { fixed * 4, fixed * 4 / 5 }, // shrink in Y |
| 85 { fixed * 4, fixed * 4 } | 85 { fixed * 4, fixed * 4 } |
| 86 }; | 86 }; |
| 87 | 87 |
| 88 canvas->drawBitmap(fBitmap, 10, 10, NULL); | 88 canvas->drawBitmap(fBitmap, 10, 10, nullptr); |
| 89 | 89 |
| 90 SkScalar x = SkIntToScalar(100); | 90 SkScalar x = SkIntToScalar(100); |
| 91 SkScalar y = SkIntToScalar(100); | 91 SkScalar y = SkIntToScalar(100); |
| 92 | 92 |
| 93 SkPaint paint; | 93 SkPaint paint; |
| 94 paint.setFilterQuality(kLow_SkFilterQuality); | 94 paint.setFilterQuality(kLow_SkFilterQuality); |
| 95 | 95 |
| 96 for (int iy = 0; iy < 2; ++iy) { | 96 for (int iy = 0; iy < 2; ++iy) { |
| 97 for (int ix = 0; ix < 2; ++ix) { | 97 for (int ix = 0; ix < 2; ++ix) { |
| 98 int i = ix * 2 + iy; | 98 int i = ix * 2 + iy; |
| 99 SkRect r = SkRect::MakeXYWH(x + ix * fixed, y + iy * fixed, | 99 SkRect r = SkRect::MakeXYWH(x + ix * fixed, y + iy * fixed, |
| 100 size[i].width(), size[i].height()); | 100 size[i].width(), size[i].height()); |
| 101 canvas->drawBitmapNine(fBitmap, fCenter, r, &paint); | 101 canvas->drawBitmapNine(fBitmap, fCenter, r, &paint); |
| 102 canvas->drawImageNine(fImage, fCenter, r.makeOffset(360, 0), &pa
int); | 102 canvas->drawImageNine(fImage, fCenter, r.makeOffset(360, 0), &pa
int); |
| 103 | 103 |
| 104 } | 104 } |
| 105 } | 105 } |
| 106 } | 106 } |
| 107 | 107 |
| 108 private: | 108 private: |
| 109 typedef skiagm::GM INHERITED; | 109 typedef skiagm::GM INHERITED; |
| 110 }; | 110 }; |
| 111 DEF_GM( return new NinePatchStretchGM; ) | 111 DEF_GM( return new NinePatchStretchGM; ) |
| 112 | 112 |
| OLD | NEW |