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
This commit is contained in:
reed@android.com 2009-11-23 21:07:51 +00:00
Родитель e522ca5d5f
Коммит 4417740a48
7 изменённых файлов: 46 добавлений и 30 удалений

Просмотреть файл

@ -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);

Просмотреть файл

@ -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);
}

Просмотреть файл

@ -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);
};
//////////////////////////////////////////////////////////////////////////////

Просмотреть файл

@ -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) {

Просмотреть файл

@ -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;
};

Просмотреть файл

@ -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;
};

Просмотреть файл

@ -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;