From: reed@android.com Date: Wed, 21 Oct 2009 19:41:10 +0000 (+0000) Subject: first cut at a checkbox X-Git-Tag: accepted/tizen/5.0/unified/20181102.025319~19355 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=80b4ebe5d598039f1f8b75053053f0853e02fdb8;p=platform%2Fupstream%2FlibSkiaSharp.git first cut at a checkbox git-svn-id: http://skia.googlecode.com/svn/trunk@402 2bbb7eff-a529-9590-31e7-b0007b416f81 --- diff --git a/animations/checkbox.xml b/animations/checkbox.xml new file mode 100644 index 0000000..7750c36 --- /dev/null +++ b/animations/checkbox.xml @@ -0,0 +1,67 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/samplecode/SampleAnimator.cpp b/samplecode/SampleAnimator.cpp index 14c9745..2909ebc 100644 --- a/samplecode/SampleAnimator.cpp +++ b/samplecode/SampleAnimator.cpp @@ -69,7 +69,20 @@ bool SkAnimatorView::decodeStream(SkStream* stream) { void SkAnimatorView::onDraw(SkCanvas* canvas) { if (fAnimator) { canvas->drawColor(SK_ColorWHITE); - fAnimator->draw(canvas, SkTime::GetMSecs()); + fAnimator->draw(canvas, 0); + + canvas->save(); + canvas->translate(120, 30); + canvas->scale(0.5, 0.5); + fAnimator->draw(canvas, 0); + canvas->restore(); + + canvas->save(); + canvas->translate(190, 40); + canvas->scale(0.25, 0.25); + fAnimator->draw(canvas, 0); + canvas->restore(); + this->inval(NULL); } } @@ -80,7 +93,7 @@ static SkView* MyFactory() { SkAnimatorView* av = new SkAnimatorView; // av->decodeFile("/skimages/test.xml"); av->setURIBase("/skia/trunk/animations/"); - av->decodeFile("/skia/trunk/animations/paths#1.xml"); + av->decodeFile("/skia/trunk/animations/checkbox.xml"); return av; } diff --git a/samplecode/SampleWarp.cpp b/samplecode/SampleWarp.cpp index 5e18909..92955f8 100644 --- a/samplecode/SampleWarp.cpp +++ b/samplecode/SampleWarp.cpp @@ -8,6 +8,9 @@ #include "SkUtils.h" #include "SkImageDecoder.h" + +/////////////////////////////////////////////////////////////////////////////// + class Mesh { public: Mesh(); @@ -18,6 +21,8 @@ public: 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) { @@ -28,6 +33,7 @@ public: void drawWireframe(SkCanvas* canvas, const SkPaint& paint); private: + SkRect fBounds; int fRows, fCols; SkPoint* fPts; SkPoint* fTex; // just points into fPts, not separately allocated @@ -47,6 +53,7 @@ Mesh& Mesh::operator=(const Mesh& src) { delete[] fPts; delete[] fIndices; + fBounds = src.fBounds; fRows = src.fRows; fCols = src.fCols; @@ -67,6 +74,7 @@ void Mesh::init(const SkRect& bounds, int rows, int cols, const SkRect& texture) { SkASSERT(rows > 0 && cols > 0); + fBounds = bounds; fRows = rows; fCols = cols; @@ -140,7 +148,7 @@ public: bounds = texture; // fMesh.init(bounds, fBitmap.width() / 40, fBitmap.height() / 40, texture); - fMesh.init(bounds, 10, 10, texture); + fMesh.init(bounds, 30, 30, texture); fOrig = fMesh; } @@ -154,21 +162,54 @@ protected: return this->INHERITED::onQuery(evt); } + static SkPoint make_pt(SkScalar x, SkScalar y) { + SkPoint pt; + pt.set(x, y); + return pt; + } + + static SkScalar mapx0(SkScalar min, SkScalar max, SkScalar x0, SkScalar x1, + SkScalar x) { + if (x < x0) { + SkASSERT(x0 > min); + return x1 - SkScalarMulDiv(x1 - min, x0 - x, x0 - min); + } else { + SkASSERT(max > x0); + return x1 + SkScalarMulDiv(max - x1, x - x0, max - x0); + } + } + + static SkScalar mapx1(SkScalar min, SkScalar max, SkScalar x0, SkScalar x1, + SkScalar x) { + SkScalar newx; + if (x < x0) { + SkASSERT(x0 > min); + newx = x1 - SkScalarMulDiv(x1 - min, x0 - x, x0 - min); + } else { + SkASSERT(max > x0); + newx = x1 + SkScalarMulDiv(max - x1, x - x0, max - x0); + } + return x + (newx - x) * 0.5f; + } + + static SkPoint mappt(const SkRect& r, const SkPoint& p0, const SkPoint& p1, + const SkPoint& pt) { + return make_pt(mapx0(r.fLeft, r.fRight, p0.fX, p1.fX, pt.fX), + mapx0(r.fTop, r.fBottom, p0.fY, p1.fY, pt.fY)); + } + void warp(const SkPoint& p0, const SkPoint& p1) { + const SkRect& bounds = fOrig.bounds(); int rows = fMesh.rows(); int cols = fMesh.cols(); - const SkVector delta = p1 - p0; - for (int y = 1; y < cols; y++) { - for (int x = 1; x < rows; x++) { - const SkPoint& orig = fOrig.pt(x, y); - SkScalar dist = SkPoint::Distance(p0, orig); - dist += SkIntToScalar(1); - // dist = SkScalarSqrt(dist); - SkScalar dx = SkScalarDiv(delta.fX, dist); - SkScalar dy = SkScalarDiv(delta.fY, dist); - fMesh.pt(x, y).set(orig.fX + dx, orig.fY + dy); -// SkDebugf("[%g %g] -> [%d %d %g] <%g %g>\n", delta.fX, delta.fY, x, y, dist, dx, dy); + SkRect r = bounds; + r.inset(bounds.width() / 256, bounds.height() / 256); + if (r.contains(p0)) { + for (int y = 1; y < cols; y++) { + for (int x = 1; x < rows; x++) { + fMesh.pt(x, y) = mappt(bounds, p0, p1, fOrig.pt(x, y)); + } } } } @@ -185,7 +226,7 @@ protected: paint.setShader(NULL); paint.setColor(SK_ColorRED); - fMesh.draw(canvas, paint); + // fMesh.draw(canvas, paint); } virtual SkView::Click* onFindClickHandler(SkScalar x, SkScalar y) {