#include "SkRandom.h"
class AddArcGM : public skiagm::GM {
+public:
+ AddArcGM() : fRotate(0) {}
+
protected:
SkString onShortName() SK_OVERRIDE { return SkString("addarc"); }
const SkScalar sweepAngle = 345;
SkRandom rand;
+ SkScalar sign = 1;
while (r.width() > paint.getStrokeWidth() * 3) {
paint.setColor(rand.nextU() | (0xFF << 24));
SkScalar startAngle = rand.nextUScalar1() * 360;
+ SkScalar speed = SkScalarSqrt(16 / r.width()) * 0.5f;
+ startAngle += fRotate * 360 * speed * sign;
+
SkPath path;
path.addArc(r, startAngle, sweepAngle);
canvas->drawPath(path, paint);
r.inset(inset, inset);
-
+ sign = -sign;
}
}
+ bool onAnimatePulse(SkMSec curr, SkMSec prev) SK_OVERRIDE {
+ fRotate = SkDoubleToScalar(fmod(curr * 0.001, 360));
+ return true;
+ }
+
private:
+ SkScalar fRotate;
typedef skiagm::GM INHERITED;
};
DEF_GM( return new AddArcGM; )
fBGColor = color;
}
+bool GM::animatePulse(SkMSec curr, SkMSec prev) {
+ return this->onAnimatePulse(curr, prev);
+}
+
+/////////////////////////////////////////////////////////////////////////////////////////////
+
void GM::onDrawBackground(SkCanvas* canvas) {
canvas->drawColor(fBGColor, SkXfermode::kSrc_Mode);
}
SkString skiagm::SimpleGM::onShortName() {
return fName;
}
+
fStarterMatrix = matrix;
}
+ bool animatePulse(SkMSec curr, SkMSec prev);
+
protected:
/** draws a standard message that the GM is only intended to be used with the GPU.*/
void drawGpuOnlyMessage(SkCanvas*);
virtual SkISize onISize() = 0;
virtual SkString onShortName() = 0;
+ virtual bool onAnimatePulse(SkMSec curr, SkMSec prev) { return false; }
virtual SkMatrix onGetInitialTransform() const { return SkMatrix::I(); }
private:
fGM->drawBackground(canvas);
}
+ bool onAnimatePulse(SkMSec curr, SkMSec prev) SK_OVERRIDE {
+ return fGM->animatePulse(curr, prev);
+ }
+
private:
GM* fGM;
typedef SampleView INHERITED;
#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;
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,
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;
};
//////////////////////////////////////////////////////////////////////////////
+++ /dev/null
-
-/*
- * Copyright 2011 Google Inc.
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-#include "SampleCode.h"
-#include "SkCanvas.h"
-#include "SkGradientShader.h"
-
-class GradientView : public SampleView {
-public:
- GradientView() {
- this->setBGColor(0xFFDDDDDD);
- }
-
-protected:
- struct GradData {
- int fCount;
- const SkColor* fColors;
- const SkScalar* fPos;
- };
- // overrides from SkEventSink
- virtual bool onQuery(SkEvent* evt) {
- if (SampleCode::TitleQ(*evt)) {
- SampleCode::TitleR(evt, "Gradients");
- return true;
- }
- return this->INHERITED::onQuery(evt);
- }
- virtual void onDrawContent(SkCanvas* canvas) {
- SkPaint paint;
- paint.setAntiAlias(true);
- paint.setStyle(SkPaint::kStroke_Style);
- paint.setStrokeWidth(SkScalarHalf(SkIntToScalar(3)));
- paint.setStyle(SkPaint::kFill_Style);
-
- SkPoint p = SkPoint::Make(0,0);
- SkPoint q = SkPoint::Make(100,100);
- SkPoint pts[] = {p, q};
-
- SkScalar t, temp, x, y;
- SkColor gColors[] = {
- SK_ColorRED, SK_ColorGREEN, SK_ColorBLUE, SK_ColorWHITE, SK_ColorBLACK
- };
- t = SampleCode::GetAnimScalar(SkIntToScalar(2), SkIntToScalar(20));
- temp = SampleCode::GetAnimScalar(SkIntToScalar(1), SkIntToScalar(8));
- SkScalar step = SK_ScalarPI / (10);
- SkScalar angle = t * step;
- x = SkScalarSinCos(angle, &y);
- SkScalar colorPositions[] = { 0, 0.1 + x, 0.4 + y, 0.9 - x + y, 1.0};
- GradData data = { 5, gColors, colorPositions };
-
-
- SkRect r = { 0, 0, SkIntToScalar(200), SkIntToScalar(200) };
- SkShader* shader1 = SkGradientShader::CreateLinear(
- pts, data.fColors, data.fPos,data.fCount,
- SkShader::kMirror_TileMode);
- paint.setShader(shader1)->unref();
-
- canvas->drawRect(r, paint);
-
-
- SkPoint s = SkPoint::Make(100,100);
- SkShader* shader2 = SkGradientShader::CreateRadial(
- s, 100, data.fColors, data.fPos, data.fCount,
- SkShader::kMirror_TileMode);
- paint.setShader(shader2)->unref();
- canvas->translate(250, 0);
- canvas->drawRect(r, paint);
-
- SkShader* shader3 = SkGradientShader::CreateTwoPointRadial(
- p, 0, q, 100, data.fColors, data.fPos, data.fCount,
- SkShader::kMirror_TileMode);
- paint.setShader(shader3)->unref();
- canvas->translate(0, 250);
- canvas->drawRect(r, paint);
-
- SkShader* shader4 = SkGradientShader::CreateSweep(
- 100, 100, data.fColors, data.fPos, data.fCount);
-
- paint.setShader(shader4)->unref();
- canvas->translate(-250, 0);
- canvas->drawRect(r, paint);
-
- this->inval(NULL);
- }
-
-private:
- typedef SampleView INHERITED;
-};
-
-//////////////////////////////////////////////////////////////////////////////
-
-static SkView* MyFactory() { return new GradientView; }
-static SkViewRegister reg(MyFactory);
return false;
}
+bool SampleWindow::sendAnimatePulse() {
+ SkView* view = curr_view(this);
+ if (SampleView::IsSampleView(view)) {
+ if (fDoAnimate) {
+ return ((SampleView*)view)->animatePulse(gAnimTime, gAnimTimePrev);
+ } else {
+ // 0 signals the view that we are no longer animating
+ ((SampleView*)view)->animatePulse(0, 0);
+ }
+ }
+ return false;
+}
+
void SampleWindow::setZoomCenter(float x, float y)
{
fZoomCenterX = x;
fDeviceType = kANGLE_DeviceType;
#endif
+ fDoAnimate = true;
fUseClip = false;
fNClip = false;
fAnimating = false;
this->postInvalDelay();
}
+ if (this->sendAnimatePulse()) {
+ this->inval(NULL);
+ }
+
// do this last
fDevManager->publishCanvas(fDeviceType, canvas, this);
}
}
switch (uni) {
+ case ' ':
+ fDoAnimate = !fDoAnimate;
+ if (this->sendAnimatePulse()) {
+ this->inval(NULL);
+ }
+ break;
case 'B':
post_event_to_sink(SkNEW_ARGS(SkEvent, ("PictFileView::toggleBBox")), curr_view(this));
// Cannot call updateTitle() synchronously, because the toggleBBox event is still in
bool fSaveToPdf;
SkAutoTUnref<SkDocument> fPDFDocument;
+ bool fDoAnimate;
bool fUseClip;
bool fNClip;
bool fAnimating;
int findByTitle(const char*);
void listTitles();
SkSize tileSize() const;
+ bool sendAnimatePulse();
typedef SkOSWindow INHERITED;
};
}
void onDrawContent(SkCanvas* canvas) SK_OVERRIDE {
- fAnimatingDrawable->setSweep(SampleCode::GetAnimScalar(360/24, 360));
canvas->EXPERIMENTAL_drawDrawable(fRootDrawable);
- this->inval(NULL);
+ }
+
+ bool onAnimatePulse(SkMSec curr, SkMSec prev) SK_OVERRIDE {
+ SkScalar angle = SkDoubleToScalar(fmod(curr * 0.36 / 24, 360));
+ fAnimatingDrawable->setSweep(angle);
+ return true;
}
SkView::Click* onFindClickHandler(SkScalar x, SkScalar y, unsigned modi) SK_OVERRIDE {
SkRect r = { -150, -150, 150, 150 };
canvas->drawRoundRect(r, 30, 30, paint);
}
+ }
- fRY += SampleCode::GetAnimSecondsDelta() * 90;
- if (fRY >= SkIntToScalar(360)) {
+ bool onAnimatePulse(SkMSec curr, SkMSec prev) SK_OVERRIDE {
+ fRY += (curr - prev) * 0.09f;
+ if (fRY >= 360) {
fRY = 0;
}
- this->inval(NULL);
+ return true;
}
private:
static bool FastTextQ(const SkEvent&);
+private:
static SkMSec GetAnimTime();
static SkMSec GetAnimTimeDelta();
static SkScalar GetAnimSecondsDelta();
static SkScalar GetAnimSinScalar(SkScalar amplitude,
SkScalar periodInSec,
SkScalar phaseInSec = 0);
+
+ friend class SampleWindow;
};
//////////////////////////////////////////////////////////////////////////////
{}
void setBGColor(SkColor color) { fBGColor = color; }
+ bool animatePulse(SkMSec curr, SkMSec prev) { return this->onAnimatePulse(curr, prev); }
static bool IsSampleView(SkView*);
static bool SetRepeatDraw(SkView*, int count);
protected:
virtual void onDrawBackground(SkCanvas*);
virtual void onDrawContent(SkCanvas*) = 0;
+ virtual bool onAnimatePulse(SkMSec curr, SkMSec prev) { return false; }
// overrides
virtual bool onEvent(const SkEvent& evt);
class DegenerateTwoPtRadialsView : public SampleView {
-
public:
DegenerateTwoPtRadialsView() {
fTime = 0;
}
protected:
- // overrides from SkEventSink
- virtual bool onQuery(SkEvent* evt) {
+ bool onQuery(SkEvent* evt) SK_OVERRIDE {
if (SampleCode::TitleQ(*evt)) {
SampleCode::TitleR(evt, "DegenerateTwoPtRadials");
return true;
return this->INHERITED::onQuery(evt);
}
- virtual void onDrawContent(SkCanvas* canvas) {
- fTime += SampleCode::GetAnimSecondsDelta();
+ void onDrawContent(SkCanvas* canvas) SK_OVERRIDE {
SkScalar delta = fTime / 15.f;
int intPart = SkScalarFloorToInt(delta);
delta = delta - SK_Scalar1 * intPart;
paint.setAntiAlias(true);
paint.setColor(SK_ColorBLACK);
canvas->drawText(txt.c_str(), txt.size(), l + w/2 + w*DELTA_SCALE*delta, t + h + SK_Scalar1 * 10, paint);
- this->inval(NULL);
+ }
+
+ bool onAnimatePulse(SkMSec curr, SkMSec prev) SK_OVERRIDE {
+ fTime += (curr - prev) * 0.001f;
+ return true;
}
private:
SkRect fR;
SkColor fColor;
SkInterpolator* fInterp;
+ SkMSec fTime;
public:
HTDrawable(SkRandom& rand) {
rand.nextRangeF(20, 200), rand.nextRangeF(20, 200));
fColor = rand_opaque_color(rand.nextU());
fInterp = NULL;
+ fTime = 0;
}
- void spawnAnimation() {
+ void spawnAnimation(SkMSec now) {
+ this->setTime(now);
+
SkDELETE(fInterp);
fInterp = SkNEW_ARGS(SkInterpolator, (5, 3));
SkScalar values[5];
color_to_floats(fColor, values); values[4] = 0;
- fInterp->setKeyFrame(0, SampleCode::GetAnimTime(), values);
+ fInterp->setKeyFrame(0, now, values);
values[0] = 0; values[4] = 180;
- fInterp->setKeyFrame(1, SampleCode::GetAnimTime() + 1000, values);
+ fInterp->setKeyFrame(1, now + 1000, values);
color_to_floats(rand_opaque_color(fColor), values); values[4] = 360;
- fInterp->setKeyFrame(2, SampleCode::GetAnimTime() + 2000, values);
+ fInterp->setKeyFrame(2, now + 2000, values);
fInterp->setMirror(true);
fInterp->setRepeatCount(3);
return oval_contains(fR, x, y);
}
+ void setTime(SkMSec time) { fTime = time; }
+
void onDraw(SkCanvas* canvas) SK_OVERRIDE {
SkAutoCanvasRestore acr(canvas, false);
if (fInterp) {
SkScalar values[5];
- SkInterpolator::Result res = fInterp->timeToValues(SampleCode::GetAnimTime(), values);
+ SkInterpolator::Result res = fInterp->timeToValues(fTime, values);
fColor = floats_to_color(values);
canvas->save();
paint.setColor(fColor);
canvas->drawRect(fR, paint);
}
-
+
SkRect onGetBounds() SK_OVERRIDE { return fR; }
};
};
Rec fArray[N];
SkAutoTUnref<SkCanvasDrawable> fRoot;
+ SkMSec fTime;
HTView() {
SkRandom rand;
void onDrawContent(SkCanvas* canvas) SK_OVERRIDE {
canvas->EXPERIMENTAL_drawDrawable(fRoot);
- this->inval(NULL);
+ }
+
+ bool onAnimatePulse(SkMSec curr, SkMSec prev) SK_OVERRIDE {
+ fTime = curr;
+ for (int i = 0; i < N; ++i) {
+ fArray[i].fDrawable->setTime(fTime);
+ }
+ return true;
}
SkView::Click* onFindClickHandler(SkScalar x, SkScalar y, unsigned modi) SK_OVERRIDE {
// search backwards to find the top-most
for (int i = N - 1; i >= 0; --i) {
if (fArray[i].fDrawable->hitTest(x, y)) {
- fArray[i].fDrawable->spawnAnimation();
+ fArray[i].fDrawable->spawnAnimation(fTime);
break;
}
}
static SkRandom gRand;
-static void test_chromium_9005() {
- SkBitmap bm;
- bm.allocN32Pixels(800, 600);
-
- SkCanvas canvas(bm);
-
- SkPoint pt0 = { 799.33374f, 1.2360189f };
- SkPoint pt1 = { 808.49969f, -7.4338055f };
-
- SkPaint paint;
- paint.setAntiAlias(true);
- canvas.drawLine(pt0.fX, pt0.fY, pt1.fX, pt1.fY, paint);
-}
-
static void generate_pts(SkPoint pts[], int count, int w, int h) {
for (int i = 0; i < count; i++) {
pts[i].set(gRand.nextUScalar1() * 3 * w - SkIntToScalar(w),
bool fDoAA;
public:
HairlineView() {
- fCounter = 0;
fProcIndex = 0;
fDoAA = true;
fNow = 0;
protected:
// overrides from SkEventSink
- virtual bool onQuery(SkEvent* evt) {
+ bool onQuery(SkEvent* evt) SK_OVERRIDE {
if (SampleCode::TitleQ(*evt)) {
SkString str;
str.printf("Hair-%s", gProcs[fProcIndex].fName);
canvas->drawBitmap(b1, SkIntToScalar(b0.width()), 0, NULL);
}
- int fCounter;
-
- virtual void onDrawContent(SkCanvas* canvas) {
+ void onDrawContent(SkCanvas* canvas) SK_OVERRIDE {
gRand.setSeed(fNow);
- if (false) { // avoid bit rot, suppress warning
- test_chromium_9005();
- }
-
SkBitmap bm, bm2;
bm.allocN32Pixels(WIDTH + MARGIN*2, HEIGHT + MARGIN*2);
// this will erase our margin, which we want to always stay 0
bm2.eraseColor(SK_ColorTRANSPARENT);
gProcs[fProcIndex].fProc(&c2, paint, bm);
canvas->drawBitmap(bm2, SkIntToScalar(10), SkIntToScalar(10), NULL);
+ }
- SkMSec now = SampleCode::GetAnimTime();
- if (fNow != now) {
- fNow = now;
- fCounter += 1;
- fDoAA = !fDoAA;
- if (fCounter > 50) {
- fProcIndex = cycle_hairproc_index(fProcIndex);
- // todo: signal that we want to rebuild our TITLE
- fCounter = 0;
- }
- this->inval(NULL);
+ bool onAnimatePulse(SkMSec curr, SkMSec prev) SK_OVERRIDE {
+ if (fDoAA) {
+ fProcIndex = cycle_hairproc_index(fProcIndex);
+ // todo: signal that we want to rebuild our TITLE
}
+ fDoAA = !fDoAA;
+ return true;
}
- virtual SkView::Click* onFindClickHandler(SkScalar x, SkScalar y,
- unsigned modi) {
+ SkView::Click* onFindClickHandler(SkScalar x, SkScalar y, unsigned modi) SK_OVERRIDE {
fDoAA = !fDoAA;
this->inval(NULL);
return this->INHERITED::onFindClickHandler(x, y, modi);
#include "SkPixelXorXfermode.h"
#define CORNER_RADIUS 12
-static SkScalar gPhase;
static const int gXY[] = {
4, 0, 0, -4, 8, -4, 12, 0, 8, 4, 0, 4
};
-static SkPathEffect* make_pe(int flags) {
+static SkPathEffect* make_pe(int flags, SkScalar phase) {
if (flags == 1)
return SkCornerPathEffect::Create(SkIntToScalar(CORNER_RADIUS));
path.close();
path.offset(SkIntToScalar(-6), 0);
- SkPathEffect* outer = SkPath1DPathEffect::Create(path, SkIntToScalar(12), gPhase, SkPath1DPathEffect::kRotate_Style);
+ SkPathEffect* outer = SkPath1DPathEffect::Create(path, 12, phase,
+ SkPath1DPathEffect::kRotate_Style);
if (flags == 2)
return outer;
return pe;
}
-static SkPathEffect* make_warp_pe() {
+static SkPathEffect* make_warp_pe(SkScalar phase) {
SkPath path;
path.moveTo(SkIntToScalar(gXY[0]), SkIntToScalar(gXY[1]));
for (unsigned i = 2; i < SK_ARRAY_COUNT(gXY); i += 2)
path.offset(SkIntToScalar(-6), 0);
SkPathEffect* outer = SkPath1DPathEffect::Create(
- path, SkIntToScalar(12), gPhase, SkPath1DPathEffect::kMorph_Style);
+ path, 12, phase, SkPath1DPathEffect::kMorph_Style);
SkPathEffect* inner = SkCornerPathEffect::Create(SkIntToScalar(CORNER_RADIUS));
SkPathEffect* pe = SkComposePathEffect::Create(outer, inner);
SkPaint paint;
paint.setAntiAlias(true);
-#if 0
- paint.setStyle(SkPaint::kStroke_Style);
- paint.setStrokeWidth(SK_Scalar1*4);
- this->addLayer(paint);
-
- paint.setStrokeWidth(SK_Scalar1*1);
- paint.setXfermode(SkXfermode::kClear_Mode);
- this->addLayer(paint);
-#else
paint.setAlpha(0x66);
this->addLayer(paint, SkIntToScalar(4), SkIntToScalar(4));
paint.setAlpha(0xFF);
this->addLayer(paint);
-#endif
}
};
class PathEffectView : public SampleView {
SkPath fPath;
SkPoint fClickPt;
+ SkScalar fPhase;
+
public:
- PathEffectView() {
+ PathEffectView() : fPhase(0) {
SkRandom rand;
int steps = 20;
SkScalar dist = SkIntToScalar(400);
}
protected:
- // overrides from SkEventSink
- virtual bool onQuery(SkEvent* evt) {
+ bool onQuery(SkEvent* evt) SK_OVERRIDE {
if (SampleCode::TitleQ(*evt)) {
SampleCode::TitleR(evt, "PathEffects");
return true;
return this->INHERITED::onQuery(evt);
}
- virtual void onDrawContent(SkCanvas* canvas) {
- gPhase -= SampleCode::GetAnimSecondsDelta() * 40;
- this->inval(NULL);
-
+ void onDrawContent(SkCanvas* canvas) SK_OVERRIDE {
SkPaint paint;
-#if 0
- paint.setAntiAlias(true);
- paint.setStyle(SkPaint::kStroke_Style);
- paint.setStrokeWidth(SkIntToScalar(5));
- canvas->drawPath(fPath, paint);
- paint.setStrokeWidth(0);
-
- paint.setColor(SK_ColorWHITE);
- paint.setPathEffect(make_pe(1))->unref();
- canvas->drawPath(fPath, paint);
-#endif
-
- canvas->translate(0, SkIntToScalar(50));
+ canvas->translate(0, 50);
paint.setColor(SK_ColorBLUE);
- paint.setPathEffect(make_pe(2))->unref();
+ paint.setPathEffect(make_pe(2, fPhase))->unref();
canvas->drawPath(fPath, paint);
- canvas->translate(0, SkIntToScalar(50));
+ canvas->translate(0, 50);
paint.setARGB(0xFF, 0, 0xBB, 0);
- paint.setPathEffect(make_pe(3))->unref();
+ paint.setPathEffect(make_pe(3, fPhase))->unref();
canvas->drawPath(fPath, paint);
- canvas->translate(0, SkIntToScalar(50));
+ canvas->translate(0, 50);
paint.setARGB(0xFF, 0, 0, 0);
- paint.setPathEffect(make_warp_pe())->unref();
+ paint.setPathEffect(make_warp_pe(fPhase))->unref();
TestRastBuilder testRastBuilder;
paint.setRasterizer(testRastBuilder.detachRasterizer())->unref();
canvas->drawPath(fPath, paint);
}
+ bool onAnimatePulse(SkMSec curr, SkMSec prev) SK_OVERRIDE {
+ fPhase -= (curr - prev) * 0.04f;
+ return true;
+ }
+
private:
typedef SampleView INHERITED;
};
protected:
// overrides from SkEventSink
- virtual bool onQuery(SkEvent* evt) {
+ bool onQuery(SkEvent* evt) SK_OVERRIDE {
if (SampleCode::TitleQ(*evt)) {
SampleCode::TitleR(evt, "Picture");
return true;
}
- virtual void onDrawContent(SkCanvas* canvas) {
+ void onDrawContent(SkCanvas* canvas) SK_OVERRIDE {
this->drawSomething(canvas);
SkPictureRecorder recorder;
canvas->translate(-SkIntToScalar(100), 0);
canvas->drawPicture(pict);
canvas->restore();
-
-#ifdef SK_DEVELOPER
- if (false) {
- SkDebugfDumper dumper;
- SkDumpCanvas dumpCanvas(&dumper);
- dumpCanvas.drawPicture(pict);
- }
-#endif
-
- // This used to re-record the sub-picture and redraw the parent
- // A capability that is now forbidden!
-
- SkRandom rand(SampleCode::GetAnimTime());
- canvas->translate(SkIntToScalar(10), SkIntToScalar(250));
- canvas->drawPicture(fPicture);
- delayInval(500);
}
private:
(new SkEvent(INVAL_ALL_TYPE, this->getSinkID()))->postDelay(delay);
}
- virtual bool onEvent(const SkEvent& evt) {
+ bool onEvent(const SkEvent& evt) SK_OVERRIDE {
if (evt.isType(INVAL_ALL_TYPE)) {
this->inval(NULL);
return true;
+++ /dev/null
-
-/*
- * Copyright 2011 Google Inc.
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-#include "SampleCode.h"
-#include "SkView.h"
-#include "SkCanvas.h"
-
-class SpiralView : public SampleView {
-public:
- SpiralView() {
- this->setBGColor(0xFFDDDDDD);
- }
-
-protected:
- // overrides from SkEventSink
- virtual bool onQuery(SkEvent* evt) {
- if (SampleCode::TitleQ(*evt)) {
- SampleCode::TitleR(evt, "Spiral");
- return true;
- }
- return this->INHERITED::onQuery(evt);
- }
-
- virtual void onDrawContent(SkCanvas* canvas) {
- SkPaint paint;
- paint.setAntiAlias(true);
- paint.setStyle(SkPaint::kStroke_Style);
- paint.setStrokeWidth(SkScalarHalf(SkIntToScalar(3)));
- paint.setStyle(SkPaint::kFill_Style);
-
- SkRect r;
- SkScalar l,t,x,y;
- l = SampleCode::GetAnimScalar(SkIntToScalar(10),
- SkIntToScalar(400));
- t = SampleCode::GetAnimScalar(SkIntToScalar(5),
- SkIntToScalar(200));
-
- canvas->translate(320,240);
- for (int i = 0; i < 35; i++) {
- paint.setColor(0xFFF00FF0 - i * 0x04000000);
- SkScalar step = SK_ScalarPI / (55 - i);
- SkScalar angle = t * step;
- x = (20 + SkIntToScalar(i) * 5) * SkScalarSinCos(angle, &y);
- y *= (20 + SkIntToScalar(i) * 5);
- r.set(x, y, x + SkIntToScalar(10), y + SkIntToScalar(10));
- canvas->drawRect(r, paint);
- }
-
- this->inval(NULL);
- }
-
-private:
- typedef SampleView INHERITED;
-};
-
-//////////////////////////////////////////////////////////////////////////////
-
-static SkView* MyFactory() { return new SpiralView; }
-static SkViewRegister reg(MyFactory);