2012-03-28 14:44:37 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2012 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
2015-02-02 20:55:02 +00:00
|
|
|
|
2012-03-28 14:44:37 +00:00
|
|
|
#include "SampleCode.h"
|
2015-02-02 20:55:02 +00:00
|
|
|
#include "SkAnimTimer.h"
|
2012-03-28 14:44:37 +00:00
|
|
|
#include "SkColorPriv.h"
|
|
|
|
#include "SkCanvas.h"
|
2018-03-14 17:01:17 +00:00
|
|
|
#include "SkMaskFilter.h"
|
2012-03-28 14:44:37 +00:00
|
|
|
#include "SkRandom.h"
|
|
|
|
|
2015-02-02 20:55:02 +00:00
|
|
|
SkScalar get_anim_sin(double secs, SkScalar amplitude, SkScalar periodInSec, SkScalar phaseInSec) {
|
2015-02-02 03:01:04 +00:00
|
|
|
if (!periodInSec) {
|
|
|
|
return 0;
|
|
|
|
}
|
2015-02-02 20:55:02 +00:00
|
|
|
double t = secs + phaseInSec;
|
2015-02-02 03:01:04 +00:00
|
|
|
t *= SkScalarToFloat(2 * SK_ScalarPI) / periodInSec;
|
|
|
|
amplitude = SK_ScalarHalf * amplitude;
|
|
|
|
return amplitude * SkDoubleToScalar(sin(t)) + amplitude;
|
|
|
|
}
|
|
|
|
|
2012-03-28 14:44:37 +00:00
|
|
|
class AnimBlurView : public SampleView {
|
|
|
|
public:
|
2015-02-02 03:01:04 +00:00
|
|
|
AnimBlurView() : fBlurSigma(0), fCircleRadius(100) {}
|
2012-03-28 14:44:37 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
// overrides from SkEventSink
|
2015-03-26 01:17:31 +00:00
|
|
|
bool onQuery(SkEvent* evt) override {
|
2012-03-28 14:44:37 +00:00
|
|
|
if (SampleCode::TitleQ(*evt)) {
|
|
|
|
SampleCode::TitleR(evt, "AnimBlur");
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return this->INHERITED::onQuery(evt);
|
|
|
|
}
|
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
void onDrawContent(SkCanvas* canvas) override {
|
2014-04-28 16:25:35 +00:00
|
|
|
static const SkBlurStyle gStyles[] = {
|
|
|
|
kNormal_SkBlurStyle,
|
|
|
|
kInner_SkBlurStyle,
|
|
|
|
kSolid_SkBlurStyle,
|
|
|
|
kOuter_SkBlurStyle,
|
2012-03-28 14:44:37 +00:00
|
|
|
};
|
2013-09-09 20:09:12 +00:00
|
|
|
SkRandom random;
|
2012-03-28 14:44:37 +00:00
|
|
|
|
2012-04-25 16:54:51 +00:00
|
|
|
for (size_t i = 0; i < SK_ARRAY_COUNT(gStyles); ++i) {
|
2012-03-28 14:44:37 +00:00
|
|
|
SkPaint paint;
|
2018-03-14 17:01:17 +00:00
|
|
|
paint.setMaskFilter(SkMaskFilter::MakeBlur(gStyles[i],
|
|
|
|
fBlurSigma));
|
2012-03-28 14:44:37 +00:00
|
|
|
paint.setColor(random.nextU() | 0xff000000);
|
|
|
|
canvas->drawCircle(200 * SK_Scalar1 + 400 * (i % 2) * SK_Scalar1,
|
|
|
|
200 * SK_Scalar1 + i / 2 * 400 * SK_Scalar1,
|
2015-02-02 03:01:04 +00:00
|
|
|
fCircleRadius, paint);
|
2012-03-28 14:44:37 +00:00
|
|
|
}
|
2015-02-02 03:01:04 +00:00
|
|
|
}
|
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
bool onAnimate(const SkAnimTimer& timer) override {
|
2015-02-02 20:55:02 +00:00
|
|
|
fBlurSigma = get_anim_sin(timer.secs(), 100, 4, 5);
|
|
|
|
fCircleRadius = 3 + get_anim_sin(timer.secs(), 150, 25, 3);
|
2015-02-02 03:01:04 +00:00
|
|
|
return true;
|
2012-03-28 14:44:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2015-02-02 03:01:04 +00:00
|
|
|
SkScalar fBlurSigma, fCircleRadius;
|
|
|
|
|
|
|
|
typedef SampleView INHERITED;
|
2012-03-28 14:44:37 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
static SkView* MyFactory() { return new AnimBlurView; }
|
|
|
|
static SkViewRegister reg(MyFactory);
|