blob: e4f3c2e0273499e3d9688991b50e0c9a1b7e0a4d [file] [log] [blame]
epoger@google.comec3ed6a2011-07-28 14:26:00 +00001
2/*
3 * Copyright 2011 Google Inc.
4 *
5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
7 */
reed@google.coma965a152011-02-17 15:06:52 +00008#include "gm.h"
9#include "SkRandom.h"
10
11namespace skiagm {
12
13class PointsGM : public GM {
14public:
15 PointsGM() {}
16
17protected:
18 virtual SkString onShortName() {
19 return SkString("points");
20 }
21
22 virtual SkISize onISize() {
23 return make_isize(640, 490);
24 }
25
reed@google.coma965a152011-02-17 15:06:52 +000026 static void fill_pts(SkPoint pts[], size_t n, SkRandom* rand) {
epoger@google.com17b78942011-08-26 14:40:38 +000027 for (size_t i = 0; i < n; i++) {
28 // Compute these independently and store in variables, rather
29 // than in the parameter-passing expression, to get consistent
30 // evaluation order across compilers.
bsalomon@google.com72e49b82011-10-27 21:47:03 +000031 SkScalar y = rand->nextUScalar1() * 480;
32 SkScalar x = rand->nextUScalar1() * 640;
epoger@google.com17b78942011-08-26 14:40:38 +000033 pts[i].set(x, y);
34 }
reed@google.coma965a152011-02-17 15:06:52 +000035 }
36
37 virtual void onDraw(SkCanvas* canvas) {
reed@google.coma965a152011-02-17 15:06:52 +000038 canvas->translate(SK_Scalar1, SK_Scalar1);
39
40 SkRandom rand;
41 SkPaint p0, p1, p2, p3;
42 const size_t n = 99;
43
44 p0.setColor(SK_ColorRED);
45 p1.setColor(SK_ColorGREEN);
46 p2.setColor(SK_ColorBLUE);
47 p3.setColor(SK_ColorWHITE);
48
49 p0.setStrokeWidth(SkIntToScalar(4));
50 p2.setStrokeCap(SkPaint::kRound_Cap);
51 p2.setStrokeWidth(SkIntToScalar(6));
52
53 SkPoint* pts = new SkPoint[n];
54 fill_pts(pts, n, &rand);
55
56 canvas->drawPoints(SkCanvas::kPolygon_PointMode, n, pts, p0);
57 canvas->drawPoints(SkCanvas::kLines_PointMode, n, pts, p1);
58 canvas->drawPoints(SkCanvas::kPoints_PointMode, n, pts, p2);
59 canvas->drawPoints(SkCanvas::kPoints_PointMode, n, pts, p3);
60
61 delete[] pts;
62 }
63
64private:
65 typedef GM INHERITED;
66};
67
68//////////////////////////////////////////////////////////////////////////////
69
70static GM* MyFactory(void*) { return new PointsGM; }
71static GMRegistry reg(MyFactory);
72
73}
74