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
|
|
|
|
2018-08-08 15:36:17 +00:00
|
|
|
#include "Sample.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;
|
|
|
|
}
|
|
|
|
|
2018-08-08 15:36:17 +00:00
|
|
|
class AnimBlurView : public Sample {
|
2012-03-28 14:44:37 +00:00
|
|
|
public:
|
2015-02-02 03:01:04 +00:00
|
|
|
AnimBlurView() : fBlurSigma(0), fCircleRadius(100) {}
|
2012-03-28 14:44:37 +00:00
|
|
|
|
|
|
|
protected:
|
2018-08-08 15:36:17 +00:00
|
|
|
bool onQuery(Sample::Event* evt) override {
|
|
|
|
if (Sample::TitleQ(*evt)) {
|
|
|
|
Sample::TitleR(evt, "AnimBlur");
|
2012-03-28 14:44:37 +00:00
|
|
|
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;
|
|
|
|
|
2018-08-08 15:36:17 +00:00
|
|
|
typedef Sample INHERITED;
|
2012-03-28 14:44:37 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2018-08-08 15:36:17 +00:00
|
|
|
DEF_SAMPLE( return new AnimBlurView(); )
|