2 * Copyright 2012 Google Inc.
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
8 #include "SampleCode.h"
9 #include "SkAnimTimer.h"
10 #include "SkBlurMaskFilter.h"
11 #include "SkColorPriv.h"
15 SkScalar get_anim_sin(double secs, SkScalar amplitude, SkScalar periodInSec, SkScalar phaseInSec) {
19 double t = secs + phaseInSec;
20 t *= SkScalarToFloat(2 * SK_ScalarPI) / periodInSec;
21 amplitude = SK_ScalarHalf * amplitude;
22 return amplitude * SkDoubleToScalar(sin(t)) + amplitude;
25 class AnimBlurView : public SampleView {
27 AnimBlurView() : fBlurSigma(0), fCircleRadius(100) {}
30 // overrides from SkEventSink
31 bool onQuery(SkEvent* evt) SK_OVERRIDE {
32 if (SampleCode::TitleQ(*evt)) {
33 SampleCode::TitleR(evt, "AnimBlur");
36 return this->INHERITED::onQuery(evt);
39 void onDrawContent(SkCanvas* canvas) SK_OVERRIDE {
40 static const SkBlurStyle gStyles[] = {
48 for (size_t i = 0; i < SK_ARRAY_COUNT(gStyles); ++i) {
49 SkMaskFilter* mf = SkBlurMaskFilter::Create(
52 SkBlurMaskFilter::kHighQuality_BlurFlag);
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 fCircleRadius, paint);
62 bool onAnimate(const SkAnimTimer& timer) SK_OVERRIDE {
63 fBlurSigma = get_anim_sin(timer.secs(), 100, 4, 5);
64 fCircleRadius = 3 + get_anim_sin(timer.secs(), 150, 25, 3);
69 SkScalar fBlurSigma, fCircleRadius;
71 typedef SampleView INHERITED;
74 //////////////////////////////////////////////////////////////////////////////
76 static SkView* MyFactory() { return new AnimBlurView; }
77 static SkViewRegister reg(MyFactory);