bsalomon@google.com | 8500322 | 2012-03-28 14:44:37 +0000 | [diff] [blame] | 1 | |
| 2 | /* |
| 3 | * Copyright 2012 Google Inc. |
| 4 | * |
| 5 | * Use of this source code is governed by a BSD-style license that can be |
| 6 | * found in the LICENSE file. |
| 7 | */ |
| 8 | #include "SampleCode.h" |
| 9 | #include "SkBlurMaskFilter.h" |
| 10 | #include "SkColorPriv.h" |
| 11 | #include "SkCanvas.h" |
| 12 | #include "SkRandom.h" |
| 13 | |
| 14 | class AnimBlurView : public SampleView { |
| 15 | public: |
| 16 | AnimBlurView() { |
| 17 | } |
| 18 | |
| 19 | protected: |
| 20 | // overrides from SkEventSink |
| 21 | virtual bool onQuery(SkEvent* evt) { |
| 22 | if (SampleCode::TitleQ(*evt)) { |
| 23 | SampleCode::TitleR(evt, "AnimBlur"); |
| 24 | return true; |
| 25 | } |
| 26 | return this->INHERITED::onQuery(evt); |
| 27 | } |
| 28 | |
| 29 | virtual void onDrawContent(SkCanvas* canvas) { |
| 30 | |
| 31 | SkScalar blurRadius = SampleCode::GetAnimSinScalar(100 * SK_Scalar1, |
| 32 | 4 * SK_Scalar1, |
| 33 | 5 * SK_Scalar1); |
| 34 | |
| 35 | SkScalar circleRadius = 3 * SK_Scalar1 + |
| 36 | SampleCode::GetAnimSinScalar(150 * SK_Scalar1, |
| 37 | 25 * SK_Scalar1, |
| 38 | 3 * SK_Scalar1); |
| 39 | |
| 40 | static const SkBlurMaskFilter::BlurStyle gStyles[] = { |
| 41 | SkBlurMaskFilter::kNormal_BlurStyle, |
| 42 | SkBlurMaskFilter::kInner_BlurStyle, |
| 43 | SkBlurMaskFilter::kSolid_BlurStyle, |
| 44 | SkBlurMaskFilter::kOuter_BlurStyle, |
| 45 | }; |
| 46 | SkRandom random; |
| 47 | |
robertphillips@google.com | 7460b37 | 2012-04-25 16:54:51 +0000 | [diff] [blame] | 48 | for (size_t i = 0; i < SK_ARRAY_COUNT(gStyles); ++i) { |
bsalomon@google.com | 8500322 | 2012-03-28 14:44:37 +0000 | [diff] [blame] | 49 | SkMaskFilter* mf = SkBlurMaskFilter::Create(blurRadius, |
| 50 | gStyles[i], |
| 51 | SkBlurMaskFilter::kHighQuality_BlurFlag); |
| 52 | SkPaint paint; |
reed@google.com | 59ed2c2 | 2012-04-09 17:12:30 +0000 | [diff] [blame] | 53 | SkSafeUnref(paint.setMaskFilter(mf)); |
bsalomon@google.com | 8500322 | 2012-03-28 14:44:37 +0000 | [diff] [blame] | 54 | paint.setColor(random.nextU() | 0xff000000); |
| 55 | canvas->drawCircle(200 * SK_Scalar1 + 400 * (i % 2) * SK_Scalar1, |
| 56 | 200 * SK_Scalar1 + i / 2 * 400 * SK_Scalar1, |
| 57 | circleRadius, paint); |
| 58 | } |
| 59 | this->inval(NULL); |
| 60 | } |
| 61 | |
| 62 | private: |
| 63 | typedef SkView INHERITED; |
| 64 | }; |
| 65 | |
| 66 | ////////////////////////////////////////////////////////////////////////////// |
| 67 | |
| 68 | static SkView* MyFactory() { return new AnimBlurView; } |
| 69 | static SkViewRegister reg(MyFactory); |
| 70 | |