diff options
author | reed@android.com <reed@android.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2009-11-23 21:07:51 +0000 |
---|---|---|
committer | reed@android.com <reed@android.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2009-11-23 21:07:51 +0000 |
commit | 4417740a480786ca65379ba5b398c500ba34ee18 (patch) | |
tree | 1a261f93f6270078dbf165c73616aaf9bdb1570f /samplecode | |
parent | e522ca5d5f249bd51a00cb68bb051f811d0a9e85 (diff) |
add SampleCode::GetAnimTime() so slides go through a central location for
animation timing. This allows us to "freeze" time in order to do things like
draw multiple times to test clipping.
git-svn-id: http://skia.googlecode.com/svn/trunk@444 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'samplecode')
-rw-r--r-- | samplecode/SampleApp.cpp | 20 | ||||
-rw-r--r-- | samplecode/SampleArc.cpp | 7 | ||||
-rw-r--r-- | samplecode/SampleCode.h | 3 | ||||
-rw-r--r-- | samplecode/SampleLineClipper.cpp | 15 | ||||
-rw-r--r-- | samplecode/SampleMipMap.cpp | 17 | ||||
-rw-r--r-- | samplecode/SamplePicture.cpp | 4 | ||||
-rw-r--r-- | samplecode/SampleShapes.cpp | 10 |
7 files changed, 46 insertions, 30 deletions
diff --git a/samplecode/SampleApp.cpp b/samplecode/SampleApp.cpp index 2d0da1f71b..8fcdfa8715 100644 --- a/samplecode/SampleApp.cpp +++ b/samplecode/SampleApp.cpp @@ -6,6 +6,7 @@ #include "SkPaint.h" #include "SkPicture.h" #include "SkStream.h" +#include "SkTime.h" #include "SkWindow.h" #include "SampleCode.h" @@ -121,6 +122,18 @@ void SampleCode::PrefSizeR(SkEvent* evt, SkScalar width, SkScalar height) { evt->setScalars(gPrefSizeEvtName, 2, size); } +static SkMSec gAnimTime; +SkMSec SampleCode::GetAnimTime() { return gAnimTime; } + +SkScalar SampleCode::GetAnimScalar(SkScalar speed, SkScalar period) { + SkScalar seconds = SkFloatToScalar(gAnimTime / 1000.0f); + SkScalar value = SkScalarMul(speed, seconds); + if (period) { + value = SkScalarMod(value, period); + } + return value; +} + ////////////////////////////////////////////////////////////////////////////// class SampleWindow : public SkOSWindow { @@ -241,10 +254,13 @@ SampleWindow::~SampleWindow() { delete fGLCanvas; } -#define XCLIP_N 4 -#define YCLIP_N 1 +#define XCLIP_N 8 +#define YCLIP_N 8 void SampleWindow::draw(SkCanvas* canvas) { + // update the animation time + gAnimTime = SkTime::GetMSecs(); + if (fNClip) { // this->INHERITED::draw(canvas); // SkBitmap orig = capture_bitmap(canvas); diff --git a/samplecode/SampleArc.cpp b/samplecode/SampleArc.cpp index 19bf5f8533..ed62537e9e 100644 --- a/samplecode/SampleArc.cpp +++ b/samplecode/SampleArc.cpp @@ -127,6 +127,9 @@ protected: virtual void onDraw(SkCanvas* canvas) { this->drawBG(canvas); + + fSweep = SampleCode::GetAnimScalar(SkIntToScalar(360)/24, + SkIntToScalar(360)); SkRect r; SkPaint paint; @@ -167,10 +170,6 @@ protected: paint.setColor(SK_ColorBLUE); canvas->drawArc(r, 0, fSweep, false, paint); - fSweep += SK_Scalar1/4; - if (fSweep > SkIntToScalar(360)) - fSweep = 0; - drawArcs(canvas); this->inval(NULL); } diff --git a/samplecode/SampleCode.h b/samplecode/SampleCode.h index fd3ed2adc9..c901af3c39 100644 --- a/samplecode/SampleCode.h +++ b/samplecode/SampleCode.h @@ -10,6 +10,9 @@ public: static bool PrefSizeQ(const SkEvent&); static void PrefSizeR(SkEvent*, SkScalar width, SkScalar height); + + static SkMSec GetAnimTime(); + static SkScalar GetAnimScalar(SkScalar speedPerSec, SkScalar period = 0); }; ////////////////////////////////////////////////////////////////////////////// diff --git a/samplecode/SampleLineClipper.cpp b/samplecode/SampleLineClipper.cpp index 09606f6b89..8e2d620584 100644 --- a/samplecode/SampleLineClipper.cpp +++ b/samplecode/SampleLineClipper.cpp @@ -147,6 +147,7 @@ enum { }; class LineClipperView : public SkView { + SkMSec fNow; int fCounter; int fProcIndex; SkRect fClip; @@ -196,7 +197,14 @@ protected: virtual void onDraw(SkCanvas* canvas) { this->drawBG(canvas); - + + SkMSec now = SampleCode::GetAnimTime(); + if (fNow != now) { + fNow = now; + this->randPts(); + this->inval(NULL); + } + // fProcIndex = test0(fPts, &fClip); SkPaint paint, paint1; @@ -219,11 +227,6 @@ protected: paint1.setColor(SK_ColorRED); paint1.setStyle(SkPaint::kStroke_Style); gProcs[fProcIndex](fPts, fClip, canvas, paint, paint1); - - if (AUTO_ANIMATE) { - this->randPts(); - this->inval(NULL); - } } virtual SkView::Click* onFindClickHandler(SkScalar x, SkScalar y) { diff --git a/samplecode/SampleMipMap.cpp b/samplecode/SampleMipMap.cpp index 5885591637..07227e5ee0 100644 --- a/samplecode/SampleMipMap.cpp +++ b/samplecode/SampleMipMap.cpp @@ -38,7 +38,6 @@ public: fBitmap = createBitmap(N); fWidth = N; - fDW = -1; } protected: @@ -97,15 +96,13 @@ protected: SkBitmap bitmap(fBitmap); bitmap.buildMipMap(); drawN2(canvas, bitmap); - - fWidth += fDW; - if (fDW > 0 && fWidth > N) { - fDW = -fDW; - fWidth = N; - } else if (fDW < 0 && fWidth < 8) { - fDW = -fDW; - fWidth = 8; + + SkScalar time = SampleCode::GetAnimScalar(SkIntToScalar(1)/4, + SkIntToScalar(2)); + if (time >= SK_Scalar1) { + time = SkIntToScalar(2) - time; } + fWidth = 8 + SkScalarRound(N * time); SkRect dst; dst.set(0, 0, SkIntToScalar(fWidth), SkIntToScalar(fWidth)); @@ -140,7 +137,7 @@ protected: } private: - int fWidth, fDW; + int fWidth; typedef SkView INHERITED; }; diff --git a/samplecode/SamplePicture.cpp b/samplecode/SamplePicture.cpp index 4ca5b2a7d6..e1b05ad66b 100644 --- a/samplecode/SamplePicture.cpp +++ b/samplecode/SamplePicture.cpp @@ -148,9 +148,10 @@ protected: // test that we can re-record a subpicture, and see the results + SkRandom rand(SampleCode::GetAnimTime()); canvas->translate(SkIntToScalar(10), SkIntToScalar(250)); drawCircle(fSubPicture->beginRecording(50, 50), 25, - fRand.nextU() | 0xFF000000); + rand.nextU() | 0xFF000000); canvas->drawPicture(*fPicture); delayInval(500); } @@ -172,7 +173,6 @@ private: SkPicture* fPicture; SkPicture* fSubPicture; - SkRandom fRand; typedef SkView INHERITED; }; diff --git a/samplecode/SampleShapes.cpp b/samplecode/SampleShapes.cpp index 07f2d0037c..b92614b756 100644 --- a/samplecode/SampleShapes.cpp +++ b/samplecode/SampleShapes.cpp @@ -60,8 +60,6 @@ public: for (size_t i = 0; i < SK_ARRAY_COUNT(fMatrixRefs); i++) { SkSafeRef(fMatrixRefs[i] = fGroup.getShapeMatrixRef(i)); } - - fAngle = 0; } virtual ~ShapesView() { @@ -98,15 +96,15 @@ protected: #endif } - int fAngle; - virtual void onDraw(SkCanvas* canvas) { this->drawBG(canvas); + SkScalar angle = SampleCode::GetAnimScalar(SkIntToScalar(360)/2, + SkIntToScalar(360)); + SkMatrix saveM = *fMatrixRefs[3]; - fAngle = (fAngle + 5) % 360; SkScalar c = SkIntToScalar(50); - fMatrixRefs[3]->preRotate(SkIntToScalar(fAngle), c, c); + fMatrixRefs[3]->preRotate(angle, c, c); SkMatrix matrix; |