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 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<screenplay xmlns="urn:screenplay">
+
+	<path id="check">
+		<moveTo x="20" y="50" />
+        <quadTo x1="40" y1="70" x2="40" y2="77" />
+		<quadTo x1="45" y1="55" x2="75" y2="30" />
+	</path>
+
+    <roundRect id="frame"
+               left="3" top="3" right="97" bottom="97"
+               rx="17" ry="17" />
+
+	<event kind="onLoad">
+		<paint antiAlias="true" />
+
+        <!-- draw the background -->
+
+        <paint stroke="true" strokeWidth="4">
+            <color color="0x66000000"/>
+        </paint>
+        <matrix translate="[0,2]"/>
+        <add use="frame" />
+        <paint>
+            <color color="black"/>
+        </paint>
+        <matrix translate="[0,-2]"/>
+        <add use="frame" />
+
+        <paint stroke="false">
+			<linearGradient points="[0,frame.top,0,frame.bottom]" tileMode="clamp"
+                    offsets="[0,0.65,1]">
+				<color color="#F2F2F2" />
+				<color color="#AFAFAF" />
+				<color color="#C7C7C7" />
+			</linearGradient>
+        </paint>
+        <add use="frame" />
+
+        <!-- draw the checkmark background -->
+
+		<paint stroke="true" strokeWidth="9">
+            <shader/>
+            <blur radius="1" blurStyle="normal"/>
+            <color color="0x88777777"/>
+        </paint>
+        <matrix translate="[0,-2]" />
+        <add use="check" />
+
+		<paint>
+            <color color="0x88BBBBBB"/>
+        </paint>
+        <matrix translate="[0,4]" />
+        <add use="check" />
+
+        <!-- draw the checkmark -->
+
+		<paint>
+            <maskFilter/>
+            <color color="#66CC00"/>
+        </paint>
+        <matrix translate="[0,-2]" />
+        <add use="check" />
+
+	</event>
+
+</screenplay>
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 @@
 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 @@
     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 @@
     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 @@
     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 @@
     delete[] fPts;
     delete[] fIndices;
 
+    fBounds = src.fBounds;
     fRows = src.fRows;
     fCols = src.fCols;
 
@@ -67,6 +74,7 @@
                 const SkRect& texture) {
     SkASSERT(rows > 0 && cols > 0);
 
+    fBounds = bounds;
     fRows = rows;
     fCols = cols;
 
@@ -140,7 +148,7 @@
         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 @@
         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 @@
         
         paint.setShader(NULL);
         paint.setColor(SK_ColorRED);
-        fMesh.draw(canvas, paint);
+    //    fMesh.draw(canvas, paint);
     }
     
     virtual SkView::Click* onFindClickHandler(SkScalar x, SkScalar y) {