more gms for conics
authorreed <reed@google.com>
Mon, 9 Feb 2015 21:01:05 +0000 (13:01 -0800)
committerCommit bot <commit-bot@chromium.org>
Mon, 9 Feb 2015 21:01:05 +0000 (13:01 -0800)
BUG=skia:
TBR=

Review URL: https://codereview.chromium.org/869843006

gm/addarc.cpp
samplecode/SampleArc.cpp

index e6fad25..aef7916 100644 (file)
@@ -8,6 +8,7 @@
 #include "gm.h"
 #include "SkAnimTimer.h"
 #include "SkCanvas.h"
+#include "SkPathMeasure.h"
 #include "SkRandom.h"
 
 class AddArcGM : public skiagm::GM {
@@ -60,3 +61,53 @@ private:
     typedef skiagm::GM INHERITED;
 };
 DEF_GM( return new AddArcGM; )
+
+///////////////////////////////////////////////////
+
+#define R   400
+
+class AddArcMeasGM : public skiagm::GM {
+public:
+    AddArcMeasGM() {}
+
+protected:
+    SkString onShortName() SK_OVERRIDE { return SkString("addarc_meas"); }
+
+    SkISize onISize() SK_OVERRIDE { return SkISize::Make(2*R + 40, 2*R + 40); }
+
+    void onDraw(SkCanvas* canvas) SK_OVERRIDE {
+        canvas->translate(R + 20, R + 20);
+
+        SkPaint paint;
+        paint.setAntiAlias(true);
+        paint.setStyle(SkPaint::kStroke_Style);
+
+        SkPaint measPaint;
+        measPaint.setAntiAlias(true);
+        measPaint.setColor(SK_ColorRED);
+
+        const SkRect oval = SkRect::MakeLTRB(-R, -R, R, R);
+        canvas->drawOval(oval, paint);
+
+        for (SkScalar deg = 0; deg < 360; deg += 10) {
+            const SkScalar rad = SkDegreesToRadians(deg);
+            SkScalar rx = SkScalarCos(rad) * R;
+            SkScalar ry = SkScalarSin(rad) * R;
+
+            canvas->drawLine(0, 0, rx, ry, paint);
+
+            SkPath path;
+            path.addArc(oval, 0, deg);
+            SkPathMeasure meas(path, false);
+            SkScalar arcLen = rad * R;
+            SkPoint pos;
+            if (meas.getPosTan(arcLen, &pos, NULL)) {
+                canvas->drawLine(0, 0, pos.x(), pos.y(), measPaint);
+            }
+        }
+    }
+
+private:
+    typedef skiagm::GM INHERITED;
+};
+DEF_GM( return new AddArcMeasGM; )
index bc20e92..710901b 100644 (file)
@@ -122,8 +122,7 @@ protected:
         canvas->drawLine(r.centerX(), r.fTop, r.centerX(), r.fBottom, p);
     }
 
-    static void DrawLabel(SkCanvas* canvas, const SkRect& rect,
-                            int start, int sweep) {
+    static void DrawLabel(SkCanvas* canvas, const SkRect& rect, SkScalar start, SkScalar sweep) {
         SkPaint paint;
 
         paint.setAntiAlias(true);
@@ -131,9 +130,9 @@ protected:
 
         SkString    str;
 
-        str.appendS32(start);
+        str.appendScalar(start);
         str.append(", ");
-        str.appendS32(sweep);
+        str.appendScalar(sweep);
         canvas->drawText(str.c_str(), str.size(), rect.centerX(),
                          rect.fBottom + paint.getTextSize() * 5/4, paint);
     }
@@ -141,8 +140,8 @@ protected:
     static void DrawArcs(SkCanvas* canvas) {
         SkPaint paint;
         SkRect  r;
-        SkScalar w = SkIntToScalar(75);
-        SkScalar h = SkIntToScalar(50);
+        SkScalar w = 75;
+        SkScalar h = 50;
 
         r.set(0, 0, w, h);
         paint.setAntiAlias(true);
@@ -153,7 +152,7 @@ protected:
 
         paint.setStrokeWidth(SkIntToScalar(1));
 
-        static const int gAngles[] = {
+        static const SkScalar gAngles[] = {
             0, 360,
             0, 45,
             0, -45,
@@ -170,8 +169,7 @@ protected:
             DrawRectWithLines(canvas, r, paint);
 
             paint.setColor(SK_ColorRED);
-            canvas->drawArc(r, SkIntToScalar(gAngles[i]),
-                            SkIntToScalar(gAngles[i+1]), false, paint);
+            canvas->drawArc(r, gAngles[i], gAngles[i+1], false, paint);
 
             DrawLabel(canvas, r, gAngles[i], gAngles[i+1]);