Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1215)

Unified Diff: samplecode/SampleAnimBlur.cpp

Issue 888283002: allow GMs to animate (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: switch all existing animations to use animatePulse Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « samplecode/GMSampleView.h ('k') | samplecode/SampleAnimatedGradient.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: samplecode/SampleAnimBlur.cpp
diff --git a/samplecode/SampleAnimBlur.cpp b/samplecode/SampleAnimBlur.cpp
index e00c46ddd19a660a93600231a97028ed418ec3bf..527d4300e7acd616048673229cfa4f8448899fd0 100644
--- a/samplecode/SampleAnimBlur.cpp
+++ b/samplecode/SampleAnimBlur.cpp
@@ -11,14 +11,23 @@
#include "SkCanvas.h"
#include "SkRandom.h"
+SkScalar get_anim_sin(SkMSec time, SkScalar amplitude, SkScalar periodInSec, SkScalar phaseInSec) {
+ if (!periodInSec) {
+ return 0;
+ }
+ double t = (double)time / 1000.0 + phaseInSec;
+ t *= SkScalarToFloat(2 * SK_ScalarPI) / periodInSec;
+ amplitude = SK_ScalarHalf * amplitude;
+ return amplitude * SkDoubleToScalar(sin(t)) + amplitude;
+}
+
class AnimBlurView : public SampleView {
public:
- AnimBlurView() {
- }
+ AnimBlurView() : fBlurSigma(0), fCircleRadius(100) {}
protected:
// overrides from SkEventSink
- virtual bool onQuery(SkEvent* evt) {
+ bool onQuery(SkEvent* evt) SK_OVERRIDE {
if (SampleCode::TitleQ(*evt)) {
SampleCode::TitleR(evt, "AnimBlur");
return true;
@@ -26,17 +35,7 @@ protected:
return this->INHERITED::onQuery(evt);
}
- virtual void onDrawContent(SkCanvas* canvas) {
-
- SkScalar blurSigma = SampleCode::GetAnimSinScalar(100 * SK_Scalar1,
- 4 * SK_Scalar1,
- 5 * SK_Scalar1);
-
- SkScalar circleRadius = 3 * SK_Scalar1 +
- SampleCode::GetAnimSinScalar(150 * SK_Scalar1,
- 25 * SK_Scalar1,
- 3 * SK_Scalar1);
-
+ void onDrawContent(SkCanvas* canvas) SK_OVERRIDE {
static const SkBlurStyle gStyles[] = {
kNormal_SkBlurStyle,
kInner_SkBlurStyle,
@@ -48,20 +47,27 @@ protected:
for (size_t i = 0; i < SK_ARRAY_COUNT(gStyles); ++i) {
SkMaskFilter* mf = SkBlurMaskFilter::Create(
gStyles[i],
- blurSigma,
+ fBlurSigma,
SkBlurMaskFilter::kHighQuality_BlurFlag);
SkPaint paint;
SkSafeUnref(paint.setMaskFilter(mf));
paint.setColor(random.nextU() | 0xff000000);
canvas->drawCircle(200 * SK_Scalar1 + 400 * (i % 2) * SK_Scalar1,
200 * SK_Scalar1 + i / 2 * 400 * SK_Scalar1,
- circleRadius, paint);
+ fCircleRadius, paint);
}
- this->inval(NULL);
+ }
+
+ bool onAnimatePulse(SkMSec curr, SkMSec prev) SK_OVERRIDE {
+ fBlurSigma = get_anim_sin(curr, 100, 4, 5);
+ fCircleRadius = 3 + get_anim_sin(curr, 150, 25, 3);
+ return true;
}
private:
- typedef SkView INHERITED;
+ SkScalar fBlurSigma, fCircleRadius;
+
+ typedef SampleView INHERITED;
};
//////////////////////////////////////////////////////////////////////////////
« no previous file with comments | « samplecode/GMSampleView.h ('k') | samplecode/SampleAnimatedGradient.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698