reed@google.com | c96e5c2 | 2011-02-16 21:50:04 +0000 | [diff] [blame] | 1 | #include "gm.h" |
| 2 | #include "SkBlurMaskFilter.h" |
| 3 | |
| 4 | namespace skiagm { |
| 5 | |
| 6 | class BlursGM : public GM { |
| 7 | public: |
| 8 | BlursGM() {} |
| 9 | |
| 10 | protected: |
| 11 | virtual SkString onShortName() { |
| 12 | return SkString("blurs"); |
| 13 | } |
| 14 | |
| 15 | virtual SkISize onISize() { |
| 16 | return make_isize(700, 500); |
| 17 | } |
| 18 | |
| 19 | void drawBG(SkCanvas* canvas) { |
| 20 | canvas->drawColor(0xFFDDDDDD); |
| 21 | } |
| 22 | |
| 23 | virtual void onDraw(SkCanvas* canvas) { |
| 24 | drawBG(canvas); |
| 25 | |
| 26 | SkBlurMaskFilter::BlurStyle NONE = SkBlurMaskFilter::BlurStyle(-999); |
| 27 | static const struct { |
| 28 | SkBlurMaskFilter::BlurStyle fStyle; |
| 29 | int fCx, fCy; |
| 30 | } gRecs[] = { |
| 31 | { NONE, 0, 0 }, |
| 32 | { SkBlurMaskFilter::kInner_BlurStyle, -1, 0 }, |
| 33 | { SkBlurMaskFilter::kNormal_BlurStyle, 0, 1 }, |
| 34 | { SkBlurMaskFilter::kSolid_BlurStyle, 0, -1 }, |
| 35 | { SkBlurMaskFilter::kOuter_BlurStyle, 1, 0 }, |
| 36 | }; |
| 37 | |
| 38 | SkPaint paint; |
| 39 | paint.setAntiAlias(true); |
| 40 | paint.setTextSize(25); |
| 41 | canvas->translate(-40, 0); |
| 42 | |
| 43 | SkBlurMaskFilter::BlurFlags flags = SkBlurMaskFilter::kNone_BlurFlag; |
| 44 | for (int j = 0; j < 2; j++) { |
| 45 | canvas->save(); |
| 46 | paint.setColor(SK_ColorBLUE); |
| 47 | for (size_t i = 0; i < SK_ARRAY_COUNT(gRecs); i++) { |
| 48 | if (gRecs[i].fStyle != NONE) { |
| 49 | SkMaskFilter* mf = SkBlurMaskFilter::Create(20, |
| 50 | gRecs[i].fStyle, |
| 51 | flags); |
| 52 | paint.setMaskFilter(mf)->unref(); |
| 53 | } else { |
| 54 | paint.setMaskFilter(NULL); |
| 55 | } |
| 56 | canvas->drawCircle(200 + gRecs[i].fCx*100, |
| 57 | 200 + gRecs[i].fCy*100, 50, paint); |
| 58 | } |
| 59 | // draw text |
| 60 | { |
| 61 | SkMaskFilter* mf = SkBlurMaskFilter::Create(4, |
| 62 | SkBlurMaskFilter::kNormal_BlurStyle, |
| 63 | flags); |
| 64 | paint.setMaskFilter(mf)->unref(); |
| 65 | SkScalar x = SkIntToScalar(70); |
| 66 | SkScalar y = SkIntToScalar(400); |
| 67 | paint.setColor(SK_ColorBLACK); |
| 68 | canvas->drawText("Hamburgefons Style", 18, x, y, paint); |
| 69 | canvas->drawText("Hamburgefons Style", 18, x, y + SkIntToScalar(50), paint); |
| 70 | paint.setMaskFilter(NULL); |
| 71 | paint.setColor(SK_ColorWHITE); |
| 72 | x -= SkIntToScalar(2); |
| 73 | y -= SkIntToScalar(2); |
| 74 | canvas->drawText("Hamburgefons Style", 18, x, y, paint); |
| 75 | } |
| 76 | canvas->restore(); |
reed@google.com | 11a5ff3 | 2011-02-18 20:20:51 +0000 | [diff] [blame] | 77 | flags = SkBlurMaskFilter::kHighQuality_BlurFlag; |
reed@google.com | c96e5c2 | 2011-02-16 21:50:04 +0000 | [diff] [blame] | 78 | canvas->translate(350, 0); |
| 79 | } |
| 80 | } |
| 81 | |
| 82 | private: |
| 83 | typedef GM INHERITED; |
| 84 | }; |
| 85 | |
| 86 | ////////////////////////////////////////////////////////////////////////////// |
| 87 | |
| 88 | static GM* MyFactory(void*) { return new BlursGM; } |
| 89 | static GMRegistry reg(MyFactory); |
| 90 | |
| 91 | } |
| 92 | |