'../samplecode/SampleLua.cpp',
'../samplecode/SampleManyRects.cpp',
'../samplecode/SampleMeasure.cpp',
- '../samplecode/SampleMipMap.cpp',
- '../samplecode/SampleMovie.cpp',
- '../samplecode/SampleOvalTest.cpp',
'../samplecode/SamplePatch.cpp',
'../samplecode/SamplePath.cpp',
'../samplecode/SamplePathClip.cpp',
'../samplecode/SampleRectanizer.cpp',
'../samplecode/SampleRegion.cpp',
'../samplecode/SampleRepeatTile.cpp',
- '../samplecode/SampleRotateCircles.cpp',
'../samplecode/SampleShaders.cpp',
'../samplecode/SampleShaderText.cpp',
'../samplecode/SampleSkLayer.cpp',
],
'sources!': [
'../samplecode/SampleSkLayer.cpp', #relies on SkMatrix44 which doesn't compile
- '../samplecode/SampleWarp.cpp',
'../samplecode/SampleFontCache.cpp',
],
'dependencies': [
#include "Resources.h"
#include "SampleCode.h"
+#include "SkAnimTimer.h"
#include "SkCanvas.h"
#include "SkInterpolator.h"
#include "SkSurface.h"
AnimValue fScale, fAngle;
SkSize fCell;
SkInterpolator fTrans;
+ SkMSec fCurrTime;
bool fShowFatBits;
public:
fTrans.setMirror(true);
fTrans.setReset(true);
+ fCurrTime = 0;
+
fTrans.setRepeatCount(999);
values[0] = values[1] = 0;
- fTrans.setKeyFrame(0, SkTime::GetMSecs(), values);
+ fTrans.setKeyFrame(0, fCurrTime, values);
values[0] = values[1] = 1;
- fTrans.setKeyFrame(1, SkTime::GetMSecs() + 2000, values);
+ fTrans.setKeyFrame(1, fCurrTime + 2000, values);
}
protected:
fCell.set(this->height() / 2, this->height() / 2);
SkScalar trans[2];
- fTrans.timeToValues(SkTime::GetMSecs(), trans);
+ fTrans.timeToValues(fCurrTime, trans);
for (int y = 0; y < 2; ++y) {
for (int x = 0; x < 2; ++x) {
canvas->drawText(str.c_str(), str.size(), textX, 200, paint);
str.reset(); str.appendScalar(trans[1]);
canvas->drawText(str.c_str(), str.size(), textX, 250, paint);
+ }
- this->inval(NULL);
+ bool onAnimate(const SkAnimTimer& timer) SK_OVERRIDE {
+ fCurrTime = timer.msec();
+ return true;
}
virtual bool handleKey(SkKey key) {
+++ /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"
-#include "SkDevice.h"
-#include "SkPaint.h"
-#include "SkShader.h"
-
-static SkBitmap createBitmap(int n) {
- SkBitmap bitmap;
- bitmap.allocN32Pixels(n, n);
- bitmap.eraseColor(SK_ColorTRANSPARENT);
-
- SkCanvas canvas(bitmap);
- SkRect r;
- r.set(0, 0, SkIntToScalar(n), SkIntToScalar(n));
- SkPaint paint;
- paint.setAntiAlias(true);
-
- paint.setColor(SK_ColorRED);
- canvas.drawOval(r, paint);
- paint.setColor(SK_ColorBLUE);
- paint.setStrokeWidth(SkIntToScalar(n)/15);
- paint.setStyle(SkPaint::kStroke_Style);
- canvas.drawLine(0, 0, r.fRight, r.fBottom, paint);
- canvas.drawLine(0, r.fBottom, r.fRight, 0, paint);
-
- return bitmap;
-}
-
-class MipMapView : public SampleView {
- SkBitmap fBitmap;
- enum {
- N = 64
- };
- bool fOnce;
-public:
- MipMapView() {
- fOnce = false;
- }
-
- void init() {
- if (fOnce) {
- return;
- }
- fOnce = true;
-
- fBitmap = createBitmap(N);
-
- fWidth = N;
- }
-
-protected:
- // overrides from SkEventSink
- virtual bool onQuery(SkEvent* evt) {
- if (SampleCode::TitleQ(*evt)) {
- SampleCode::TitleR(evt, "MipMaps");
- return true;
- }
- return this->INHERITED::onQuery(evt);
- }
-
- virtual void onDrawContent(SkCanvas* canvas) {
- this->init();
-
- static const SkPaint::FilterLevel gLevel[] = {
- SkPaint::kNone_FilterLevel,
- SkPaint::kLow_FilterLevel,
- SkPaint::kMedium_FilterLevel,
- SkPaint::kHigh_FilterLevel,
- };
-
- SkPaint paint;
-
- for (size_t i = 0; i < SK_ARRAY_COUNT(gLevel); ++i) {
- SkScalar x = 10.0f + i * 100;
- SkScalar y = 10.0f;
-
- paint.setFilterLevel(gLevel[i]);
-
- canvas->drawBitmap(fBitmap, x, y, &paint);
- }
- this->inval(NULL);
- }
-
-private:
- int fWidth;
-
- typedef SampleView INHERITED;
-};
-
-//////////////////////////////////////////////////////////////////////////////
-
-static SkView* MyFactory() { return new MipMapView; }
-static SkViewRegister reg(MyFactory);
+++ /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"
-#include "SkMovie.h"
-#include "SkTime.h"
-#include <new>
-
-class AnimGifView : public SkView {
- SkMovie* fMovie;
-public:
- AnimGifView() {
- fMovie = SkMovie::DecodeFile("/skimages/dollarblk.gif");
- }
-
- virtual ~AnimGifView() {
- SkSafeUnref(fMovie);
- }
-
-protected:
- // overrides from SkEventSink
- virtual bool onQuery(SkEvent* evt) {
- if (SampleCode::TitleQ(*evt)) {
- SampleCode::TitleR(evt, "Animated Gif");
- return true;
- }
- return this->INHERITED::onQuery(evt);
- }
-
- void drawBG(SkCanvas* canvas) {
- canvas->drawColor(0xFFDDDDDD);
- }
-
- virtual void onDraw(SkCanvas* canvas) {
- this->drawBG(canvas);
-
- if (fMovie) {
- if (fMovie->duration()) {
- fMovie->setTime(SkTime::GetMSecs() % fMovie->duration());
- } else {
- fMovie->setTime(0);
- }
- canvas->drawBitmap(fMovie->bitmap(), SkIntToScalar(20),
- SkIntToScalar(20));
- this->inval(NULL);
- }
- }
-
-private:
- SkPath fPath;
-
- typedef SkView INHERITED;
-};
-
-//////////////////////////////////////////////////////////////////////////////
-
-static SkView* MyFactory() { return new AnimGifView; }
-static SkViewRegister reg(MyFactory);
+++ /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"
-
-static const int kILimit = 101;
-static const SkScalar kLimit = SK_Scalar1 * kILimit;
-
-class OvalTestView : public SampleView {
-public:
- SkSize fSize;
- SkPMColor fInsideColor; // signals an interior pixel that was not set
- SkPMColor fOutsideColor; // signals an exterior pixels that was set
- SkBitmap fBitmap;
-
- OvalTestView() {
- fSize.set(SK_Scalar1, SK_Scalar1);
-
- fBitmap.allocN32Pixels(kILimit, kILimit);
-
- fInsideColor = SkPreMultiplyColor(SK_ColorRED);
- fOutsideColor = SkPreMultiplyColor(SK_ColorGREEN);
-
- this->setBGColor(0xFFDDDDDD);
- }
-
-protected:
- // overrides from SkEventSink
- virtual bool onQuery(SkEvent* evt) {
- if (SampleCode::TitleQ(*evt)) {
- SampleCode::TitleR(evt, "OvalTest");
- return true;
- }
- return this->INHERITED::onQuery(evt);
- }
-
- void drawOval() {
- SkCanvas canvas(fBitmap);
- SkPaint p;
-
- fBitmap.eraseColor(SK_ColorTRANSPARENT);
- canvas.drawOval(SkRect::MakeSize(fSize), p);
- }
-
- int checkOval(int* flatCount, int* buldgeCount) {
- int flatc = 0;
- int buldgec = 0;
- const SkScalar rad = SkScalarHalf(fSize.width());
- SkScalar cx = SkScalarHalf(fSize.width());
- SkScalar cy = SkScalarHalf(fSize.height());
- for (int y = 0; y < kILimit; y++) {
- for (int x = 0; x < kILimit; x++) {
- // measure from pixel centers
- SkScalar px = SkIntToScalar(x) + SK_ScalarHalf;
- SkScalar py = SkIntToScalar(y) + SK_ScalarHalf;
-
- SkPMColor* ptr = fBitmap.getAddr32(x, y);
- SkScalar dist = SkPoint::Length(px - cx, py - cy);
- if (dist <= rad && !*ptr) {
- flatc++;
- *ptr = fInsideColor;
- } else if (dist > rad && *ptr) {
- buldgec++;
- *ptr = fOutsideColor;
- }
- }
- }
- if (flatCount) *flatCount = flatc;
- if (buldgeCount) *buldgeCount = buldgec;
- return flatc + buldgec;
- }
-
- virtual void onDrawContent(SkCanvas* canvas) {
- this->drawOval();
- int flatCount, buldgeCount;
- this->checkOval(&flatCount, &buldgeCount);
- this->inval(NULL);
-
- canvas->drawBitmap(fBitmap, SkIntToScalar(20), SkIntToScalar(20), NULL);
-
-
- static int gFlatCount;
- static int gBuldgeCount;
- gFlatCount += flatCount;
- gBuldgeCount += buldgeCount;
-
- if (fSize.fWidth < kLimit) {
- SkDebugf("--- width=%g, flat=%d buldge=%d total: flat=%d buldge=%d\n", fSize.fWidth,
- flatCount, buldgeCount, gFlatCount, gBuldgeCount);
- fSize.fWidth += SK_Scalar1;
- fSize.fHeight += SK_Scalar1;
- } else {
- // fSize.set(SK_Scalar1, SK_Scalar1);
- }
- }
-
- SkView::Click* onFindClickHandler(SkScalar x, SkScalar y, unsigned) SK_OVERRIDE {
- this->inval(NULL);
- return NULL;
- }
-
-private:
- typedef SampleView INHERITED;
-};
-
-///////////////////////////////////////////////////////////////////////////////
-
-static SkView* MyFactory() { return new OvalTestView; }
-static SkViewRegister reg(MyFactory);
-
/*
* 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 "SkAnimTimer.h"
#include "SkView.h"
#include "SkCanvas.h"
#include "SkGradientShader.h"
const SkScalar DY = 0;
class PatchView : public SampleView {
+ SkScalar fAngle;
SkShader* fShader0;
SkShader* fShader1;
SkIPoint fSize0, fSize1;
SkPoint fPts[12];
public:
- PatchView() {
+ PatchView() : fAngle(0) {
fShader0 = make_shader0(&fSize0);
fSize1 = fSize0;
if (fSize0.fX == 0 || fSize0.fY == 0) {
paint.setShader(s)->unref();
}
if (true) {
- static int gAngle;
SkMatrix m;
- m.setRotate(SkIntToScalar(gAngle++));
+ m.setRotate(fAngle);
SkShader* s = SkShader::CreateLocalMatrixShader(paint.getShader(), m);
paint.setShader(s)->unref();
}
patch.setBounds(fSize1.fX, fSize1.fY);
drawpatches(canvas, paint, nu, nv, &patch);
+ }
- this->inval(NULL);
+ bool onAnimate(const SkAnimTimer& timer) SK_OVERRIDE {
+ fAngle = timer.scaled(60, 360);
+ return true;
}
class PtClick : public Click {
*/
#include "SampleCode.h"
+#include "SkAnimTimer.h"
#include "SkView.h"
#include "SkCanvas.h"
#include "SkGradientShader.h"
}
class PathView : public SampleView {
+ SkScalar fPrevSecs;
public:
- int fDStroke, fStroke, fMinStroke, fMaxStroke;
+ SkScalar fDStroke, fStroke, fMinStroke, fMaxStroke;
SkPath fPath[6];
bool fShowHairline;
bool fOnce;
PathView() {
+ fPrevSecs = 0;
fOnce = false;
}
fMinStroke = 10;
fMaxStroke = 180;
- const int V = 85;
+ const SkScalar V = 85;
- fPath[0].moveTo(SkIntToScalar(40), SkIntToScalar(70));
- fPath[0].lineTo(SkIntToScalar(70), SkIntToScalar(70) + SK_Scalar1/1);
- fPath[0].lineTo(SkIntToScalar(110), SkIntToScalar(70));
+ fPath[0].moveTo(40, 70);
+ fPath[0].lineTo(70, 70 + SK_ScalarHalf);
+ fPath[0].lineTo(110, 70);
- fPath[1].moveTo(SkIntToScalar(40), SkIntToScalar(70));
- fPath[1].lineTo(SkIntToScalar(70), SkIntToScalar(70) - SK_Scalar1/1);
- fPath[1].lineTo(SkIntToScalar(110), SkIntToScalar(70));
+ fPath[1].moveTo(40, 70);
+ fPath[1].lineTo(70, 70 - SK_ScalarHalf);
+ fPath[1].lineTo(110, 70);
- fPath[2].moveTo(SkIntToScalar(V), SkIntToScalar(V));
- fPath[2].lineTo(SkIntToScalar(50), SkIntToScalar(V));
- fPath[2].lineTo(SkIntToScalar(50), SkIntToScalar(50));
+ fPath[2].moveTo(V, V);
+ fPath[2].lineTo(50, V);
+ fPath[2].lineTo(50, 50);
- fPath[3].moveTo(SkIntToScalar(50), SkIntToScalar(50));
- fPath[3].lineTo(SkIntToScalar(50), SkIntToScalar(V));
- fPath[3].lineTo(SkIntToScalar(V), SkIntToScalar(V));
+ fPath[3].moveTo(50, 50);
+ fPath[3].lineTo(50, V);
+ fPath[3].lineTo(V, V);
- fPath[4].moveTo(SkIntToScalar(50), SkIntToScalar(50));
- fPath[4].lineTo(SkIntToScalar(50), SkIntToScalar(V));
- fPath[4].lineTo(SkIntToScalar(52), SkIntToScalar(50));
+ fPath[4].moveTo(50, 50);
+ fPath[4].lineTo(50, V);
+ fPath[4].lineTo(52, 50);
- fPath[5].moveTo(SkIntToScalar(52), SkIntToScalar(50));
- fPath[5].lineTo(SkIntToScalar(50), SkIntToScalar(V));
- fPath[5].lineTo(SkIntToScalar(50), SkIntToScalar(50));
+ fPath[5].moveTo(52, 50);
+ fPath[5].lineTo(50, V);
+ fPath[5].lineTo(50, 50);
this->setBGColor(0xFFDDDDDD);
}
- void nextStroke() {
- fStroke += fDStroke;
- if (fStroke > fMaxStroke || fStroke < fMinStroke)
- fDStroke = -fDStroke;
- }
-
protected:
// overrides from SkEventSink
virtual bool onQuery(SkEvent* evt) {
paint.setAntiAlias(true);
paint.setStyle(SkPaint::kStroke_Style);
paint.setStrokeJoin(j);
- paint.setStrokeWidth(SkIntToScalar(fStroke));
+ paint.setStrokeWidth(fStroke);
if (fShowHairline) {
SkPath fill;
virtual void onDrawContent(SkCanvas* canvas) {
this->init();
- canvas->translate(SkIntToScalar(50), SkIntToScalar(50));
+ canvas->translate(50, 50);
static const SkPaint::Join gJoins[] = {
SkPaint::kBevel_Join,
canvas->save();
for (size_t j = 0; j < SK_ARRAY_COUNT(fPath); j++) {
this->drawPath(canvas, fPath[j], gJoins[i]);
- canvas->translate(SkIntToScalar(200), 0);
+ canvas->translate(200, 0);
}
canvas->restore();
- canvas->translate(0, SkIntToScalar(200));
+ canvas->translate(0, 200);
}
+ }
+
+ bool onAnimate(const SkAnimTimer& timer) SK_OVERRIDE {
+ SkScalar currSecs = timer.scaled(100);
+ SkScalar delta = currSecs - fPrevSecs;
+ fPrevSecs = currSecs;
- this->nextStroke();
- this->inval(NULL);
+ fStroke += fDStroke * delta;
+ if (fStroke > fMaxStroke || fStroke < fMinStroke) {
+ fDStroke = -fDStroke;
+ }
+ return true;
}
SkView::Click* onFindClickHandler(SkScalar x, SkScalar y, unsigned modi) SK_OVERRIDE {
+++ /dev/null
-/*
- * Copyright 2012 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"
-#include "SkRandom.h"
-#include "SkRRect.h"
-#include "SkColorPriv.h"
-#include "SkStrokerPriv.h"
-
-static void rotateAbout(SkCanvas* canvas, SkScalar degrees,
- SkScalar cx, SkScalar cy) {
- canvas->translate(cx, cy);
- canvas->rotate(degrees);
- canvas->translate(-cx, -cy);
-}
-
-class RotateCirclesView : public SampleView {
-public:
- RotateCirclesView() {
- this->setBGColor(SK_ColorLTGRAY);
-
- fAngle = 0;
- }
-
-protected:
- // overrides from SkEventSink
- virtual bool onQuery(SkEvent* evt) {
- if (SampleCode::TitleQ(*evt)) {
- SampleCode::TitleR(evt, "RotateCircles");
- return true;
- }
- return this->INHERITED::onQuery(evt);
- }
-
- virtual void onDrawContent(SkCanvas* canvas) {
- SkRandom rand;
- SkPaint paint;
- paint.setAntiAlias(true);
- paint.setStrokeWidth(20);
-
- SkScalar cx = 240;
- SkScalar cy = 240;
- SkScalar DX = 240 * 2;
- SkColor color = 0;
-
- float scale = 1;
- float sign = 0.3f;
- for (SkScalar rad = 200; rad >= 20; rad -= 15) {
- sign = -sign;
- scale += 0.2f;
-
- paint.setColor(rand.nextU());
- paint.setAlpha(0xFF);
- color = ~color;
-
- paint.setStyle(SkPaint::kFill_Style);
-
- canvas->save();
- rotateAbout(canvas, fAngle * scale * sign, cx, cy);
- canvas->drawCircle(cx, cy, rad, paint);
- canvas->restore();
-
- paint.setStyle(SkPaint::kStroke_Style);
- paint.setStrokeWidth(rad*2);
-
- canvas->save();
- rotateAbout(canvas, fAngle * scale * sign, cx + DX, cy);
- canvas->drawCircle(cx + DX, cy, 10, paint);
- canvas->restore();
-
- canvas->save();
- rotateAbout(canvas, fAngle * scale * sign, cx + DX, cy + DX);
- canvas->drawCircle(cx + DX, cy + DX, 10, paint);
- canvas->restore();
-
- }
-
- fAngle = (fAngle + 1) % 360;
- this->inval(NULL);
- }
-
-private:
- int fAngle;
- typedef SkView INHERITED;
-};
-
-class TestCirclesView : public SampleView {
-public:
- TestCirclesView() {
- }
-
-protected:
- bool onQuery(SkEvent* evt) SK_OVERRIDE {
- if (SampleCode::TitleQ(*evt)) {
- SampleCode::TitleR(evt, "RotateCircles2");
- return true;
- }
- return this->INHERITED::onQuery(evt);
- }
-
- void draw_real_circle(SkCanvas* canvas, SkScalar radius) {
- int w = SkScalarCeilToInt(radius * 2);
- int h = w;
-
- SkBitmap bm;
- bm.allocN32Pixels(w, h);
- bm.eraseColor(0);
-
- SkAutoLockPixels alp(bm);
-
- SkScalar cx = radius;
- SkScalar cy = radius;
- for (int y = 0; y < h; y += 1) {
- for (int x = 0; x < w; x += 1) {
- float d = sqrtf((x - cx)*(x - cx) + (y - cy)*(y - cy));
- if (d <= radius) {
- *bm.getAddr32(x, y) = SkPackARGB32(0xFF, 0, 0, 0);
- }
- }
- }
-
- canvas->drawBitmap(bm, 0, 0, NULL);
- }
-
- void onDrawContent(SkCanvas* canvas) SK_OVERRIDE {
- SkScalar radius = 256;
- canvas->translate(10, 10);
-
- draw_real_circle(canvas, radius);
-
- SkPaint paint;
- paint.setAntiAlias(true);
-
- paint.setColor(0x80FF0000);
- canvas->drawCircle(radius, radius, radius, paint);
-
- paint.setStyle(SkPaint::kStroke_Style);
- paint.setStrokeWidth(radius);
- paint.setColor(0x8000FF00);
- canvas->drawCircle(radius, radius, radius/2, paint);
- }
-
-private:
- typedef SkView INHERITED;
-};
-
-static bool hittest(const SkPoint& target, SkScalar x, SkScalar y) {
- const SkScalar TOL = 7;
- return SkPoint::Distance(target, SkPoint::Make(x, y)) <= TOL;
-}
-
-static int getOnCurvePoints(const SkPath& path, SkPoint storage[]) {
- SkPath::RawIter iter(path);
- SkPoint pts[4];
- SkPath::Verb verb;
-
- int count = 0;
- while ((verb = iter.next(pts)) != SkPath::kDone_Verb) {
- switch (verb) {
- case SkPath::kMove_Verb:
- case SkPath::kLine_Verb:
- case SkPath::kQuad_Verb:
- case SkPath::kCubic_Verb:
- storage[count++] = pts[0];
- break;
- default:
- break;
- }
- }
- return count;
-}
-
-#include "SkPathMeasure.h"
-
-struct StrokeTypeButton {
- SkRect fBounds;
- char fLabel;
- bool fEnabled;
-};
-
-class TestStrokeView : public SampleView {
- enum {
- SKELETON_COLOR = 0xFF0000FF,
- WIREFRAME_COLOR = 0x80FF0000
- };
-
- enum {
- kCount = 9
- };
- SkPoint fPts[kCount];
- SkRect fErrorControl;
- SkRect fWidthControl;
- StrokeTypeButton fCubicButton;
- StrokeTypeButton fQuadButton;
- StrokeTypeButton fRRectButton;
- SkScalar fWidth, fDWidth;
- bool fAnimate;
-#if QUAD_STROKE_APPROXIMATION && defined(SK_DEBUG)
- #define kStrokerErrorMin 0.001f
- #define kStrokerErrorMax 5
-#endif
- #define kWidthMin 1
- #define kWidthMax 100
-public:
- TestStrokeView() {
- this->setBGColor(SK_ColorLTGRAY);
-
- fPts[0].set(50, 200);
- fPts[1].set(50, 100);
- fPts[2].set(150, 50);
- fPts[3].set(300, 50);
-
- fPts[4].set(350, 200);
- fPts[5].set(350, 100);
- fPts[6].set(450, 50);
-
- fPts[7].set(200, 200);
- fPts[8].set(400, 400);
-
- fWidth = 50;
- fDWidth = 0.25f;
-
- fCubicButton.fLabel = 'C';
- fCubicButton.fEnabled = true;
- fQuadButton.fLabel = 'Q';
- fQuadButton.fEnabled = true;
- fRRectButton.fLabel = 'R';
- fRRectButton.fEnabled = true;
- fAnimate = true;
- }
-
-protected:
- bool onQuery(SkEvent* evt) SK_OVERRIDE {
- if (SampleCode::TitleQ(*evt)) {
- SampleCode::TitleR(evt, "RotateCircles3");
- return true;
- }
- return this->INHERITED::onQuery(evt);
- }
-
- void onSizeChange() SK_OVERRIDE {
- fErrorControl.setXYWH(this->width() - 100, 30, 30, 400);
- fWidthControl.setXYWH(this->width() - 50, 30, 30, 400);
- fCubicButton.fBounds.setXYWH(this->width() - 50, 450, 30, 30);
- fQuadButton.fBounds.setXYWH(this->width() - 50, 500, 30, 30);
- fRRectButton.fBounds.setXYWH(this->width() - 50, 550, 30, 30);
- this->INHERITED::onSizeChange();
- }
-
- void draw_points(SkCanvas* canvas, const SkPath& path, SkColor color,
- bool show_lines) {
- SkPaint paint;
- paint.setColor(color);
- paint.setAlpha(0x80);
- paint.setAntiAlias(true);
- int n = path.countPoints();
- SkAutoSTArray<32, SkPoint> pts(n);
- if (show_lines) {
- path.getPoints(pts.get(), n);
- canvas->drawPoints(SkCanvas::kPolygon_PointMode, n, pts.get(), paint);
- } else {
- n = getOnCurvePoints(path, pts.get());
- }
- paint.setStrokeWidth(5);
- canvas->drawPoints(SkCanvas::kPoints_PointMode, n, pts.get(), paint);
- }
-
- void draw_ribs(SkCanvas* canvas, const SkPath& path, SkScalar width,
- SkColor color) {
- const SkScalar radius = width / 2;
-
- SkPathMeasure meas(path, false);
- SkScalar total = meas.getLength();
-
- SkScalar delta = 8;
- SkPaint paint;
- paint.setColor(color);
-
- SkPoint pos, tan;
- for (SkScalar dist = 0; dist <= total; dist += delta) {
- if (meas.getPosTan(dist, &pos, &tan)) {
- tan.scale(radius);
- tan.rotateCCW();
- canvas->drawLine(pos.x() + tan.x(), pos.y() + tan.y(),
- pos.x() - tan.x(), pos.y() - tan.y(), paint);
- }
- }
- }
-
- void draw_stroke(SkCanvas* canvas, const SkPath& path, SkScalar width) {
- SkPaint paint;
- paint.setAntiAlias(true);
- paint.setStyle(SkPaint::kStroke_Style);
-
- paint.setColor(SKELETON_COLOR);
- canvas->drawPath(path, paint);
- draw_points(canvas, path, SKELETON_COLOR, true);
-
- draw_ribs(canvas, path, width, 0xFF00FF00);
-
- SkPath fill;
-
- SkPaint p;
- p.setStyle(SkPaint::kStroke_Style);
- p.setStrokeWidth(width);
- p.getFillPath(path, &fill);
-
- paint.setColor(WIREFRAME_COLOR);
- canvas->drawPath(fill, paint);
- draw_points(canvas, fill, WIREFRAME_COLOR, false);
- }
-
- void draw_button(SkCanvas* canvas, const StrokeTypeButton& button) {
- SkPaint paint;
- paint.setAntiAlias(true);
- paint.setStyle(SkPaint::kStroke_Style);
- paint.setColor(button.fEnabled ? 0xFF3F0000 : 0x6F3F0000);
- canvas->drawRect(button.fBounds, paint);
- paint.setTextSize(25.0f);
- paint.setColor(button.fEnabled ? 0xFF3F0000 : 0x6F3F0000);
- paint.setTextAlign(SkPaint::kCenter_Align);
- paint.setStyle(SkPaint::kFill_Style);
- canvas->drawText(&button.fLabel, 1, button.fBounds.centerX(), button.fBounds.fBottom - 5,
- paint);
- }
-
- void draw_control(SkCanvas* canvas, const SkRect& bounds, SkScalar value,
- SkScalar min, SkScalar max, const char* name) {
- SkPaint paint;
- paint.setAntiAlias(true);
- paint.setStyle(SkPaint::kStroke_Style);
- canvas->drawRect(bounds, paint);
- SkScalar scale = max - min;
- SkScalar yPos = bounds.fTop + (value - min) * bounds.height() / scale;
- paint.setColor(0xFFFF0000);
- canvas->drawLine(bounds.fLeft - 5, yPos, bounds.fRight + 5, yPos, paint);
- SkString label;
- label.printf("%0.3g", value);
- paint.setColor(0xFF000000);
- paint.setTextSize(11.0f);
- paint.setStyle(SkPaint::kFill_Style);
- canvas->drawText(label.c_str(), label.size(), bounds.fLeft + 5, yPos - 5, paint);
- paint.setTextSize(13.0f);
- canvas->drawText(name, strlen(name), bounds.fLeft, bounds.bottom() + 11, paint);
- }
-
- void onDrawContent(SkCanvas* canvas) SK_OVERRIDE {
- SkPath path;
- SkScalar width = fWidth;
-
- if (fCubicButton.fEnabled) {
- path.moveTo(fPts[0]);
- path.cubicTo(fPts[1], fPts[2], fPts[3]);
- draw_stroke(canvas, path, width);
- }
-
- if (fQuadButton.fEnabled) {
- path.reset();
- path.moveTo(fPts[4]);
- path.quadTo(fPts[5], fPts[6]);
- draw_stroke(canvas, path, width);
- }
-
- if (fRRectButton.fEnabled) {
- SkScalar rad = 32;
- SkRect r;
- r.set(&fPts[7], 2);
- path.reset();
- SkRRect rr;
- rr.setRectXY(r, rad, rad);
- path.addRRect(rr);
- draw_stroke(canvas, path, width);
-
- path.reset();
- SkRRect rr2;
- rr.inset(width/2, width/2, &rr2);
- path.addRRect(rr2, SkPath::kCCW_Direction);
- rr.inset(-width/2, -width/2, &rr2);
- path.addRRect(rr2, SkPath::kCW_Direction);
- SkPaint paint;
- paint.setAntiAlias(true);
- paint.setColor(0x40FF8844);
- canvas->drawPath(path, paint);
- }
-
- if (fAnimate) {
- fWidth += fDWidth;
- if (fDWidth > 0 && fWidth > kWidthMax) {
- fDWidth = -fDWidth;
- } else if (fDWidth < 0 && fWidth < kWidthMin) {
- fDWidth = -fDWidth;
- }
- }
-#if QUAD_STROKE_APPROXIMATION && defined(SK_DEBUG)
- draw_control(canvas, fErrorControl, gDebugStrokerError, kStrokerErrorMin, kStrokerErrorMax,
- "error");
-#endif
- draw_control(canvas, fWidthControl, fWidth, kWidthMin, kWidthMax, "width");
- draw_button(canvas, fQuadButton);
- draw_button(canvas, fCubicButton);
- draw_button(canvas, fRRectButton);
- this->inval(NULL);
- }
-
- class MyClick : public Click {
- public:
- int fIndex;
- MyClick(SkView* target, int index) : Click(target), fIndex(index) {}
- };
-
- virtual SkView::Click* onFindClickHandler(SkScalar x, SkScalar y,
- unsigned modi) SK_OVERRIDE {
- for (size_t i = 0; i < SK_ARRAY_COUNT(fPts); ++i) {
- if (hittest(fPts[i], x, y)) {
- return new MyClick(this, (int)i);
- }
- }
- const SkRect& rectPt = SkRect::MakeXYWH(x, y, 1, 1);
-#if QUAD_STROKE_APPROXIMATION && defined(SK_DEBUG)
- if (fErrorControl.contains(rectPt)) {
- return new MyClick(this, (int) SK_ARRAY_COUNT(fPts) + 1);
- }
-#endif
- if (fWidthControl.contains(rectPt)) {
- return new MyClick(this, (int) SK_ARRAY_COUNT(fPts) + 3);
- }
- if (fCubicButton.fBounds.contains(rectPt)) {
- fCubicButton.fEnabled ^= true;
- return new MyClick(this, (int) SK_ARRAY_COUNT(fPts) + 4);
- }
- if (fQuadButton.fBounds.contains(rectPt)) {
- fQuadButton.fEnabled ^= true;
- return new MyClick(this, (int) SK_ARRAY_COUNT(fPts) + 5);
- }
- if (fRRectButton.fBounds.contains(rectPt)) {
- fRRectButton.fEnabled ^= true;
- return new MyClick(this, (int) SK_ARRAY_COUNT(fPts) + 6);
- }
- return this->INHERITED::onFindClickHandler(x, y, modi);
- }
-
- static SkScalar MapScreenYtoValue(int y, const SkRect& control, SkScalar min,
- SkScalar max) {
- return (SkIntToScalar(y) - control.fTop) / control.height() * (max - min) + min;
- }
-
- bool onClick(Click* click) SK_OVERRIDE {
- int index = ((MyClick*)click)->fIndex;
- if (index < (int) SK_ARRAY_COUNT(fPts)) {
- fPts[index].offset(SkIntToScalar(click->fICurr.fX - click->fIPrev.fX),
- SkIntToScalar(click->fICurr.fY - click->fIPrev.fY));
- this->inval(NULL);
- }
-#if QUAD_STROKE_APPROXIMATION && defined(SK_DEBUG)
- else if (index == (int) SK_ARRAY_COUNT(fPts) + 1) {
- gDebugStrokerError = MapScreenYtoValue(click->fICurr.fY, fErrorControl,
- kStrokerErrorMin, kStrokerErrorMax);
- gDebugStrokerErrorSet = true;
- }
-#endif
- else if (index == (int) SK_ARRAY_COUNT(fPts) + 3) {
- fWidth = MapScreenYtoValue(click->fICurr.fY, fWidthControl, kWidthMin, kWidthMax);
- fAnimate = fWidth <= kWidthMin;
- }
- return true;
- }
-
-private:
- typedef SkView INHERITED;
-};
-
-///////////////////////////////////////////////////////////////////////////////
-
-static SkView* F0() { return new RotateCirclesView; }
-static SkViewRegister gR0(F0);
-static SkView* F1() { return new TestCirclesView; }
-static SkViewRegister gR1(F1);
-static SkView* F2() { return new TestStrokeView; }
-static SkViewRegister gR2(F2);
+++ /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"
-#include "SkGradientShader.h"
-#include "SkPath.h"
-#include "SkRegion.h"
-#include "SkShader.h"
-#include "SkUtils.h"
-#include "SkImageDecoder.h"
-
-#include "SkBlurMaskFilter.h"
-#include "SkTableMaskFilter.h"
-
-#define kNearlyZero (SK_Scalar1 / 8092)
-
-static void test_bigblur(SkCanvas* canvas) {
- canvas->drawColor(SK_ColorBLACK);
-
- SkBitmap orig, mask;
- SkImageDecoder::DecodeFile("/skimages/app_icon.png", &orig);
-
- SkMaskFilter* mf = SkBlurMaskFilter::Create(8, SkBlurMaskFilter::kNormal_BlurStyle);
- SkPaint paint;
- paint.setMaskFilter(mf)->unref();
- SkIPoint offset;
- orig.extractAlpha(&mask, &paint, &offset);
-
- paint.setColor(0xFFBB8800);
- paint.setColor(SK_ColorWHITE);
-
- int i;
- canvas->save();
- float gamma = 0.8;
- for (i = 0; i < 5; i++) {
- paint.setMaskFilter(SkTableMaskFilter::CreateGamma(gamma))->unref();
- canvas->drawBitmap(mask, 0, 0, &paint);
- paint.setMaskFilter(NULL);
- canvas->drawBitmap(orig, -offset.fX, -offset.fY, &paint);
- gamma -= 0.1;
- canvas->translate(120, 0);
- }
- canvas->restore();
- canvas->translate(0, 160);
-
- for (i = 0; i < 5; i++) {
- paint.setMaskFilter(SkTableMaskFilter::CreateClip(i*30, 255 - 20))->unref();
- canvas->drawBitmap(mask, 0, 0, &paint);
- paint.setMaskFilter(NULL);
- canvas->drawBitmap(orig, -offset.fX, -offset.fY, &paint);
- canvas->translate(120, 0);
- }
-
-#if 0
- paint.setColor(0xFFFFFFFF);
- canvas->drawBitmap(mask, 0, 0, &paint);
- paint.setMaskFilter(NULL);
- canvas->drawBitmap(orig, -offset.fX, -offset.fY, &paint);
-
- canvas->translate(120, 0);
-
- canvas->drawBitmap(mask, 0, 0, &paint);
- canvas->drawBitmap(mask, 0, 0, &paint);
- canvas->drawBitmap(orig, -offset.fX, -offset.fY, &paint);
-
- canvas->translate(120, 0);
-
- canvas->drawBitmap(mask, 0, 0, &paint);
- canvas->drawBitmap(mask, 0, 0, &paint);
- canvas->drawBitmap(mask, 0, 0, &paint);
- canvas->drawBitmap(orig, -offset.fX, -offset.fY, &paint);
-
- canvas->translate(120, 0);
-
- canvas->drawBitmap(mask, 0, 0, &paint);
- canvas->drawBitmap(mask, 0, 0, &paint);
- canvas->drawBitmap(mask, 0, 0, &paint);
- canvas->drawBitmap(mask, 0, 0, &paint);
- canvas->drawBitmap(orig, -offset.fX, -offset.fY, &paint);
-
- canvas->translate(120, 0);
-
- canvas->drawBitmap(mask, 0, 0, &paint);
- canvas->drawBitmap(mask, 0, 0, &paint);
- canvas->drawBitmap(mask, 0, 0, &paint);
- canvas->drawBitmap(mask, 0, 0, &paint);
- canvas->drawBitmap(mask, 0, 0, &paint);
- canvas->drawBitmap(orig, -offset.fX, -offset.fY, &paint);
-#endif
-}
-
-#include "SkMeshUtils.h"
-
-static SkPoint SkMakePoint(SkScalar x, SkScalar y) {
- SkPoint pt;
- pt.set(x, y);
- return pt;
-}
-
-static SkPoint SkPointInterp(const SkPoint& a, const SkPoint& b, SkScalar t) {
- return SkMakePoint(SkScalarInterp(a.fX, b.fX, t),
- SkScalarInterp(a.fY, b.fY, t));
-}
-
-#include "SkBoundaryPatch.h"
-
-static void set_cubic(SkPoint pts[4], SkScalar x0, SkScalar y0,
- SkScalar x3, SkScalar y3, SkScalar scale = 1) {
- SkPoint tmp, tmp2;
-
- pts[0].set(x0, y0);
- pts[3].set(x3, y3);
-
- tmp = SkPointInterp(pts[0], pts[3], SK_Scalar1/3);
- tmp2 = pts[0] - tmp;
- tmp2.rotateCW();
- tmp2.scale(scale);
- pts[1] = tmp + tmp2;
-
- tmp = SkPointInterp(pts[0], pts[3], 2*SK_Scalar1/3);
- tmp2 = pts[3] - tmp;
- tmp2.rotateCW();
- tmp2.scale(scale);
- pts[2] = tmp + tmp2;
-}
-
-static void test_patch(SkCanvas* canvas, const SkBitmap& bm, SkScalar scale) {
- SkCubicBoundary cubic;
- set_cubic(cubic.fPts + 0, 0, 0, 100, 0, scale);
- set_cubic(cubic.fPts + 3, 100, 0, 100, 100, scale);
- set_cubic(cubic.fPts + 6, 100, 100, 0, 100, -scale);
- set_cubic(cubic.fPts + 9, 0, 100, 0, 0, 0);
-
- SkBoundaryPatch patch;
- patch.setBoundary(&cubic);
-
- const int Rows = 16;
- const int Cols = 16;
- SkPoint pts[Rows * Cols];
- patch.evalPatch(pts, Rows, Cols);
-
- SkPaint paint;
- paint.setAntiAlias(true);
- paint.setFilterBitmap(true);
- paint.setStrokeWidth(1);
- paint.setStrokeCap(SkPaint::kRound_Cap);
-
- canvas->translate(50, 50);
- canvas->scale(3, 3);
-
- SkMeshUtils::Draw(canvas, bm, Rows, Cols, pts, NULL, paint);
-}
-
-static void test_drag(SkCanvas* canvas, const SkBitmap& bm,
- const SkPoint& p0, const SkPoint& p1) {
- SkCubicBoundary cubic;
- set_cubic(cubic.fPts + 0, 0, 0, 100, 0, 0);
- set_cubic(cubic.fPts + 3, 100, 0, 100, 100, 0);
- set_cubic(cubic.fPts + 6, 100, 100, 0, 100, 0);
- set_cubic(cubic.fPts + 9, 0, 100, 0, 0, 0);
-
-#if 0
- cubic.fPts[1] += p1 - p0;
- cubic.fPts[2] += p1 - p0;
-#else
- SkScalar dx = p1.fX - p0.fX;
- if (dx > 0) dx = 0;
- SkScalar dy = p1.fY - p0.fY;
- if (dy > 0) dy = 0;
-
- cubic.fPts[1].fY += dy;
- cubic.fPts[2].fY += dy;
- cubic.fPts[10].fX += dx;
- cubic.fPts[11].fX += dx;
-#endif
-
- SkBoundaryPatch patch;
- patch.setBoundary(&cubic);
-
- const int Rows = 16;
- const int Cols = 16;
- SkPoint pts[Rows * Cols];
- patch.evalPatch(pts, Rows, Cols);
-
- SkPaint paint;
- paint.setAntiAlias(true);
- paint.setFilterBitmap(true);
- paint.setStrokeWidth(1);
- paint.setStrokeCap(SkPaint::kRound_Cap);
-
- canvas->translate(50, 50);
- canvas->scale(3, 3);
-
- SkAutoCanvasRestore acr(canvas, true);
-
- SkRect r = { 0, 0, 100, 100 };
- canvas->clipRect(r);
- SkMeshUtils::Draw(canvas, bm, Rows, Cols, pts, NULL, paint);
-}
-
-///////////////////////////////////////////////////////////////////////////////
-
-class Mesh {
-public:
- Mesh();
- ~Mesh();
-
- Mesh& operator=(const Mesh& src);
-
- void init(const SkRect& bounds, int rows, int cols,
- const SkRect& texture);
-
- const SkRect& bounds() const { return fBounds; }
-
- int rows() const { return fRows; }
- int cols() const { return fCols; }
- SkPoint& pt(int row, int col) {
- return fPts[row * (fRows + 1) + col];
- }
-
- void draw(SkCanvas*, const SkPaint&);
- void drawWireframe(SkCanvas* canvas, const SkPaint& paint);
-
-private:
- SkRect fBounds;
- int fRows, fCols;
- SkPoint* fPts;
- SkPoint* fTex; // just points into fPts, not separately allocated
- int fCount;
- uint16_t* fIndices;
- int fIndexCount;
-};
-
-Mesh::Mesh() : fPts(NULL), fCount(0), fIndices(NULL), fIndexCount(0) {}
-
-Mesh::~Mesh() {
- delete[] fPts;
- delete[] fIndices;
-}
-
-Mesh& Mesh::operator=(const Mesh& src) {
- delete[] fPts;
- delete[] fIndices;
-
- fBounds = src.fBounds;
- fRows = src.fRows;
- fCols = src.fCols;
-
- fCount = src.fCount;
- fPts = new SkPoint[fCount * 2];
- fTex = fPts + fCount;
- memcpy(fPts, src.fPts, fCount * 2 * sizeof(SkPoint));
-
- delete[] fIndices;
- fIndexCount = src.fIndexCount;
- fIndices = new uint16_t[fIndexCount];
- memcpy(fIndices, src.fIndices, fIndexCount * sizeof(uint16_t));
-
- return *this;
-}
-
-void Mesh::init(const SkRect& bounds, int rows, int cols,
- const SkRect& texture) {
- SkASSERT(rows > 0 && cols > 0);
-
- fBounds = bounds;
- fRows = rows;
- fCols = cols;
-
- delete[] fPts;
- fCount = (rows + 1) * (cols + 1);
- fPts = new SkPoint[fCount * 2];
- fTex = fPts + fCount;
-
- delete[] fIndices;
- fIndexCount = rows * cols * 6;
- fIndices = new uint16_t[fIndexCount];
-
- SkPoint* pts = fPts;
- const SkScalar dx = bounds.width() / rows;
- const SkScalar dy = bounds.height() / cols;
- SkPoint* tex = fTex;
- const SkScalar dtx = texture.width() / rows;
- const SkScalar dty = texture.height() / cols;
- uint16_t* idx = fIndices;
- int index = 0;
- for (int y = 0; y <= cols; y++) {
- for (int x = 0; x <= rows; x++) {
- pts->set(bounds.fLeft + x*dx, bounds.fTop + y*dy);
- pts += 1;
- tex->set(texture.fLeft + x*dtx, texture.fTop + y*dty);
- tex += 1;
-
- if (y < cols && x < rows) {
- *idx++ = index;
- *idx++ = index + rows + 1;
- *idx++ = index + 1;
-
- *idx++ = index + 1;
- *idx++ = index + rows + 1;
- *idx++ = index + rows + 2;
-
- index += 1;
- }
- }
- index += 1;
- }
-}
-
-void Mesh::draw(SkCanvas* canvas, const SkPaint& paint) {
- canvas->drawVertices(SkCanvas::kTriangles_VertexMode, fCount,
- fPts, fTex, NULL, NULL, fIndices, fIndexCount,
- paint);
-}
-
-void Mesh::drawWireframe(SkCanvas* canvas, const SkPaint& paint) {
- canvas->drawVertices(SkCanvas::kTriangles_VertexMode, fCount,
- fPts, NULL, NULL, NULL, fIndices, fIndexCount,
- paint);
-}
-
-///////////////////////////////////////////////////////////////////////////////
-
-class WarpView : public SkView {
- Mesh fMesh, fOrig;
- SkBitmap fBitmap;
- SkMatrix fMatrix, fInverse;
-public:
- WarpView() {
- SkBitmap bm;
-// SkImageDecoder::DecodeFile("/skimages/marker.png", &bm);
- SkImageDecoder::DecodeFile("/skimages/logo.gif", &bm);
- // SkImageDecoder::DecodeFile("/beach_shot.JPG", &bm);
- fBitmap = bm;
-
- SkRect bounds, texture;
- texture.set(0, 0, SkIntToScalar(fBitmap.width()),
- SkIntToScalar(fBitmap.height()));
- bounds = texture;
-
-// fMesh.init(bounds, fBitmap.width() / 40, fBitmap.height() / 40, texture);
- fMesh.init(bounds, fBitmap.width()/16, fBitmap.height()/16, texture);
- fOrig = fMesh;
-
- fP0.set(0, 0);
- fP1 = fP0;
-
- fMatrix.setScale(2, 2);
- fMatrix.invert(&fInverse);
- }
-
-protected:
- // overrides from SkEventSink
- virtual bool onQuery(SkEvent* evt) {
- if (SampleCode::TitleQ(*evt)) {
- SampleCode::TitleR(evt, "Warp");
- return true;
- }
- return this->INHERITED::onQuery(evt);
- }
-
- static SkPoint apply_warp(const SkVector& drag, SkScalar dragLength,
- const SkPoint& dragStart, const SkPoint& dragCurr,
- const SkPoint& orig) {
- SkVector delta = orig - dragCurr;
- SkScalar length = SkPoint::Normalize(&delta);
- if (length <= kNearlyZero) {
- return orig;
- }
-
- const SkScalar period = 20;
- const SkScalar mag = dragLength / 3;
-
- SkScalar d = length / (period);
- d = mag * SkScalarSin(d) / d;
- SkScalar dx = delta.fX * d;
- SkScalar dy = delta.fY * d;
- SkScalar px = orig.fX + dx;
- SkScalar py = orig.fY + dy;
- return SkPoint::Make(px, py);
- }
-
- static SkPoint apply_warp2(const SkVector& drag, SkScalar dragLength,
- const SkPoint& dragStart, const SkPoint& dragCurr,
- const SkPoint& orig) {
- SkVector delta = orig - dragCurr;
- SkScalar length = SkPoint::Normalize(&delta);
- if (length <= kNearlyZero) {
- return orig;
- }
-
- const SkScalar period = 10 + dragLength/4;
- const SkScalar mag = dragLength / 3;
-
- SkScalar d = length / (period);
- if (d > SK_ScalarPI) {
- d = SK_ScalarPI;
- }
-
- d = -mag * SkScalarSin(d);
-
- SkScalar dx = delta.fX * d;
- SkScalar dy = delta.fY * d;
- SkScalar px = orig.fX + dx;
- SkScalar py = orig.fY + dy;
- return SkPoint::Make(px, py);
- }
-
- typedef SkPoint (*WarpProc)(const SkVector& drag, SkScalar dragLength,
- const SkPoint& dragStart, const SkPoint& dragCurr,
- const SkPoint& orig);
-
- void warp(const SkPoint& p0, const SkPoint& p1) {
- WarpProc proc = apply_warp2;
- SkPoint delta = p1 - p0;
- SkScalar length = SkPoint::Normalize(&delta);
- for (int y = 0; y < fMesh.rows(); y++) {
- for (int x = 0; x < fMesh.cols(); x++) {
- fMesh.pt(x, y) = proc(delta, length, p0, p1, fOrig.pt(x, y));
- }
- }
- fP0 = p0;
- fP1 = p1;
- }
-
- virtual void onDraw(SkCanvas* canvas) {
- canvas->drawColor(SK_ColorLTGRAY);
- // test_bigblur(canvas); return;
-
- canvas->concat(fMatrix);
-
- SkPaint paint;
- paint.setFilterBitmap(true);
- paint.setShader(SkShader::CreateBitmapShader(fBitmap,
- SkShader::kClamp_TileMode,
- SkShader::kClamp_TileMode))->unref();
- fMesh.draw(canvas, paint); //return;
-
- paint.setShader(NULL);
- paint.setColor(SK_ColorRED);
- fMesh.draw(canvas, paint);
-
- // test_drag(canvas, fBitmap, fP0, fP1);
- }
-
- virtual SkView::Click* onFindClickHandler(SkScalar x, SkScalar y) {
- return new Click(this);
- }
-
- virtual bool onClick(Click* click) {
- SkPoint pts[2] = { click->fOrig, click->fCurr };
- fInverse.mapPoints(pts, 2);
- this->warp(pts[0], pts[1]);
- this->inval(NULL);
- return true;
- }
-
-private:
- SkIRect fBase, fRect;
- SkPoint fP0, fP1;
- typedef SkView INHERITED;
-};
-
-//////////////////////////////////////////////////////////////////////////////
-
-static SkView* MyFactory() { return new WarpView; }
-static SkViewRegister reg(MyFactory);