1 #include "gm.h" 2 #include "SkRandom.h" 3 4 namespace skiagm { 5 6 class PointsGM : public GM { 7 public: 8 PointsGM() {} 9 10 protected: 11 virtual SkString onShortName() { 12 return SkString("points"); 13 } 14 15 virtual SkISize onISize() { 16 return make_isize(640, 490); 17 } 18 19 void drawBG(SkCanvas* canvas) { 20 canvas->drawColor(SK_ColorWHITE); 21 } 22 23 static void fill_pts(SkPoint pts[], size_t n, SkRandom* rand) { 24 for (size_t i = 0; i < n; i++) 25 pts[i].set(rand->nextUScalar1() * 640, rand->nextUScalar1() * 480); 26 } 27 28 virtual void onDraw(SkCanvas* canvas) { 29 this->drawBG(canvas); 30 31 canvas->translate(SK_Scalar1, SK_Scalar1); 32 33 SkRandom rand; 34 SkPaint p0, p1, p2, p3; 35 const size_t n = 99; 36 37 p0.setColor(SK_ColorRED); 38 p1.setColor(SK_ColorGREEN); 39 p2.setColor(SK_ColorBLUE); 40 p3.setColor(SK_ColorWHITE); 41 42 p0.setStrokeWidth(SkIntToScalar(4)); 43 p2.setStrokeCap(SkPaint::kRound_Cap); 44 p2.setStrokeWidth(SkIntToScalar(6)); 45 46 SkPoint* pts = new SkPoint[n]; 47 fill_pts(pts, n, &rand); 48 49 canvas->drawPoints(SkCanvas::kPolygon_PointMode, n, pts, p0); 50 canvas->drawPoints(SkCanvas::kLines_PointMode, n, pts, p1); 51 canvas->drawPoints(SkCanvas::kPoints_PointMode, n, pts, p2); 52 canvas->drawPoints(SkCanvas::kPoints_PointMode, n, pts, p3); 53 54 delete[] pts; 55 } 56 57 private: 58 typedef GM INHERITED; 59 }; 60 61 ////////////////////////////////////////////////////////////////////////////// 62 63 static GM* MyFactory(void*) { return new PointsGM; } 64 static GMRegistry reg(MyFactory); 65 66 } 67 68