| bsalomon@google.com | 82aa748 | 2012-08-13 14:22:17 +0000 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright 2012 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | |
| 8 | #include "gm.h" |
| 9 | #include "SkMagnifierImageFilter.h" |
| 10 | |
| 11 | #define WIDTH 500 |
| 12 | #define HEIGHT 500 |
| 13 | |
| 14 | namespace skiagm { |
| 15 | |
| 16 | class ImageMagnifierGM : public GM { |
| 17 | public: |
| 18 | ImageMagnifierGM() { |
| 19 | this->setBGColor(0xFF000000); |
| 20 | } |
| 21 | |
| 22 | protected: |
| 23 | virtual SkString onShortName() { |
| 24 | return SkString("imagemagnifier"); |
| 25 | } |
| 26 | |
| 27 | virtual SkISize onISize() { |
| 28 | return make_isize(WIDTH, HEIGHT); |
| 29 | } |
| 30 | |
| 31 | virtual void onDraw(SkCanvas* canvas) { |
| 32 | SkPaint paint; |
| 33 | paint.setImageFilter( |
| 34 | new SkMagnifierImageFilter( |
| 35 | SkRect::MakeXYWH(SkIntToScalar(125), SkIntToScalar(125), |
| 36 | SkIntToScalar(WIDTH / 2), |
| 37 | SkIntToScalar(HEIGHT / 2)), |
| 38 | 100))->unref(); |
| 39 | canvas->saveLayer(NULL, &paint); |
| 40 | paint.setAntiAlias(true); |
| 41 | const char* str = "The quick brown fox jumped over the lazy dog."; |
| 42 | srand(1234); |
| 43 | for (int i = 0; i < 25; ++i) { |
| 44 | int x = rand() % WIDTH; |
| 45 | int y = rand() % HEIGHT; |
| 46 | paint.setColor(rand() % 0x1000000 | 0xFF000000); |
| 47 | paint.setTextSize(SkIntToScalar(rand() % 300)); |
| 48 | canvas->drawText(str, strlen(str), SkIntToScalar(x), |
| 49 | SkIntToScalar(y), paint); |
| 50 | } |
| 51 | canvas->restore(); |
| 52 | } |
| 53 | |
| 54 | private: |
| 55 | typedef GM INHERITED; |
| 56 | }; |
| 57 | |
| 58 | ////////////////////////////////////////////////////////////////////////////// |
| 59 | |
| 60 | static GM* MyFactory(void*) { return new ImageMagnifierGM; } |
| 61 | static GMRegistry reg(MyFactory); |
| 62 | |
| 63 | } |