Home | History | Annotate | Download | only in samplecode
      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 blurSigma = 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 SkBlurStyle gStyles[] = {
     41             kNormal_SkBlurStyle,
     42             kInner_SkBlurStyle,
     43             kSolid_SkBlurStyle,
     44             kOuter_SkBlurStyle,
     45         };
     46         SkRandom random;
     47 
     48         for (size_t i = 0; i < SK_ARRAY_COUNT(gStyles); ++i) {
     49             SkMaskFilter* mf = SkBlurMaskFilter::Create(
     50                                        gStyles[i],
     51                                        blurSigma,
     52                                        SkBlurMaskFilter::kHighQuality_BlurFlag);
     53             SkPaint paint;
     54             SkSafeUnref(paint.setMaskFilter(mf));
     55             paint.setColor(random.nextU() | 0xff000000);
     56             canvas->drawCircle(200 * SK_Scalar1 + 400 * (i % 2) * SK_Scalar1,
     57                                200 * SK_Scalar1 + i / 2 * 400 * SK_Scalar1,
     58                                circleRadius, paint);
     59         }
     60         this->inval(NULL);
     61     }
     62 
     63 private:
     64     typedef SkView INHERITED;
     65 };
     66 
     67 //////////////////////////////////////////////////////////////////////////////
     68 
     69 static SkView* MyFactory() { return new AnimBlurView; }
     70 static SkViewRegister reg(MyFactory);
     71