blob: 793e2e8f4f0788b62f15b4f1520edc2d929ec101 [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:
rmistry@google.comae933ce2012-08-23 18:19:56 +000015 PointsGM() {}
reed@google.coma965a152011-02-17 15:06:52 +000016
17protected:
commit-bot@chromium.orga90c6802014-04-30 13:20:45 +000018 virtual uint32_t onGetFlags() const SK_OVERRIDE {
19 return kSkipTiled_Flag;
20 }
21
reed@google.coma965a152011-02-17 15:06:52 +000022 virtual SkString onShortName() {
23 return SkString("points");
24 }
25
rmistry@google.comae933ce2012-08-23 18:19:56 +000026 virtual SkISize onISize() {
tfarinaf5393182014-06-09 23:59:03 -070027 return SkISize::Make(640, 490);
reed@google.coma965a152011-02-17 15:06:52 +000028 }
29
commit-bot@chromium.orge0e7cfe2013-09-09 20:09:12 +000030 static void fill_pts(SkPoint pts[], size_t n, SkLCGRandom* rand) {
epoger@google.com17b78942011-08-26 14:40:38 +000031 for (size_t i = 0; i < n; i++) {
32 // Compute these independently and store in variables, rather
33 // than in the parameter-passing expression, to get consistent
34 // evaluation order across compilers.
bsalomon@google.com72e49b82011-10-27 21:47:03 +000035 SkScalar y = rand->nextUScalar1() * 480;
36 SkScalar x = rand->nextUScalar1() * 640;
epoger@google.com17b78942011-08-26 14:40:38 +000037 pts[i].set(x, y);
38 }
reed@google.coma965a152011-02-17 15:06:52 +000039 }
40
41 virtual void onDraw(SkCanvas* canvas) {
reed@google.coma965a152011-02-17 15:06:52 +000042 canvas->translate(SK_Scalar1, SK_Scalar1);
43
commit-bot@chromium.orge0e7cfe2013-09-09 20:09:12 +000044 SkLCGRandom rand;
reed@google.coma965a152011-02-17 15:06:52 +000045 SkPaint p0, p1, p2, p3;
46 const size_t n = 99;
47
48 p0.setColor(SK_ColorRED);
49 p1.setColor(SK_ColorGREEN);
50 p2.setColor(SK_ColorBLUE);
51 p3.setColor(SK_ColorWHITE);
52
53 p0.setStrokeWidth(SkIntToScalar(4));
54 p2.setStrokeCap(SkPaint::kRound_Cap);
55 p2.setStrokeWidth(SkIntToScalar(6));
56
57 SkPoint* pts = new SkPoint[n];
58 fill_pts(pts, n, &rand);
59
60 canvas->drawPoints(SkCanvas::kPolygon_PointMode, n, pts, p0);
61 canvas->drawPoints(SkCanvas::kLines_PointMode, n, pts, p1);
62 canvas->drawPoints(SkCanvas::kPoints_PointMode, n, pts, p2);
63 canvas->drawPoints(SkCanvas::kPoints_PointMode, n, pts, p3);
64
65 delete[] pts;
66 }
67
68private:
69 typedef GM INHERITED;
70};
71
72//////////////////////////////////////////////////////////////////////////////
73
74static GM* MyFactory(void*) { return new PointsGM; }
75static GMRegistry reg(MyFactory);
76
77}