3 * Copyright 2011 Google Inc.
5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
13 class PointsGM : public GM {
19 SkString onShortName() SK_OVERRIDE {
20 return SkString("points");
23 SkISize onISize() SK_OVERRIDE {
24 return SkISize::Make(640, 490);
27 static void fill_pts(SkPoint pts[], size_t n, SkRandom* rand) {
28 for (size_t i = 0; i < n; i++) {
29 // Compute these independently and store in variables, rather
30 // than in the parameter-passing expression, to get consistent
31 // evaluation order across compilers.
32 SkScalar y = rand->nextUScalar1() * 480;
33 SkScalar x = rand->nextUScalar1() * 640;
38 void onDraw(SkCanvas* canvas) SK_OVERRIDE {
39 canvas->translate(SK_Scalar1, SK_Scalar1);
42 SkPaint p0, p1, p2, p3;
45 p0.setColor(SK_ColorRED);
46 p1.setColor(SK_ColorGREEN);
47 p2.setColor(SK_ColorBLUE);
48 p3.setColor(SK_ColorWHITE);
50 p0.setStrokeWidth(SkIntToScalar(4));
51 p2.setStrokeCap(SkPaint::kRound_Cap);
52 p2.setStrokeWidth(SkIntToScalar(6));
54 SkPoint* pts = new SkPoint[n];
55 fill_pts(pts, n, &rand);
57 canvas->drawPoints(SkCanvas::kPolygon_PointMode, n, pts, p0);
58 canvas->drawPoints(SkCanvas::kLines_PointMode, n, pts, p1);
59 canvas->drawPoints(SkCanvas::kPoints_PointMode, n, pts, p2);
60 canvas->drawPoints(SkCanvas::kPoints_PointMode, n, pts, p3);
69 //////////////////////////////////////////////////////////////////////////////
71 static GM* MyFactory(void*) { return new PointsGM; }
72 static GMRegistry reg(MyFactory);