blob: 48d8fec2b455de6a9ff436208b85f92fbc4f35c8 [file] [log] [blame]
reed@google.coma965a152011-02-17 15:06:52 +00001#include "gm.h"
2#include "SkRandom.h"
3
4namespace skiagm {
5
6class PointsGM : public GM {
7public:
8 PointsGM() {}
9
10protected:
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
57private:
58 typedef GM INHERITED;
59};
60
61//////////////////////////////////////////////////////////////////////////////
62
63static GM* MyFactory(void*) { return new PointsGM; }
64static GMRegistry reg(MyFactory);
65
66}
67