#include "SkPaint.h"
#include "SkPicture.h"
#include "SkStream.h"
+#include "SkTime.h"
#include "SkWindow.h"
#include "SampleCode.h"
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 {
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);
virtual void onDraw(SkCanvas* canvas)
{
this->drawBG(canvas);
+
+ fSweep = SampleCode::GetAnimScalar(SkIntToScalar(360)/24,
+ SkIntToScalar(360));
SkRect r;
SkPaint paint;
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);
}
static bool PrefSizeQ(const SkEvent&);
static void PrefSizeR(SkEvent*, SkScalar width, SkScalar height);
+
+ static SkMSec GetAnimTime();
+ static SkScalar GetAnimScalar(SkScalar speedPerSec, SkScalar period = 0);
};
//////////////////////////////////////////////////////////////////////////////
};
class LineClipperView : public SkView {
+ SkMSec fNow;
int fCounter;
int fProcIndex;
SkRect fClip;
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;
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) {
fBitmap = createBitmap(N);
fWidth = N;
- fDW = -1;
}
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));
}
private:
- int fWidth, fDW;
+ int fWidth;
typedef SkView INHERITED;
};
// 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);
}
SkPicture* fPicture;
SkPicture* fSubPicture;
- SkRandom fRand;
typedef SkView INHERITED;
};
for (size_t i = 0; i < SK_ARRAY_COUNT(fMatrixRefs); i++) {
SkSafeRef(fMatrixRefs[i] = fGroup.getShapeMatrixRef(i));
}
-
- fAngle = 0;
}
virtual ~ShapesView() {
#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;