2011-07-28 14:26:00 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2011 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "gm/gm.h"
|
|
|
|
#include "include/utils/SkRandom.h"
|
2011-02-17 15:06:52 +00:00
|
|
|
|
|
|
|
namespace skiagm {
|
|
|
|
|
|
|
|
class PointsGM : public GM {
|
|
|
|
public:
|
2012-08-23 18:19:56 +00:00
|
|
|
PointsGM() {}
|
2011-02-17 15:06:52 +00:00
|
|
|
|
|
|
|
protected:
|
2014-04-30 13:20:45 +00:00
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
SkString onShortName() override {
|
2011-02-17 15:06:52 +00:00
|
|
|
return SkString("points");
|
|
|
|
}
|
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
SkISize onISize() override {
|
2014-06-10 06:59:03 +00:00
|
|
|
return SkISize::Make(640, 490);
|
2011-02-17 15:06:52 +00:00
|
|
|
}
|
|
|
|
|
2014-12-15 20:54:51 +00:00
|
|
|
static void fill_pts(SkPoint pts[], size_t n, SkRandom* rand) {
|
2011-08-26 14:40:38 +00:00
|
|
|
for (size_t i = 0; i < n; i++) {
|
|
|
|
// Compute these independently and store in variables, rather
|
|
|
|
// than in the parameter-passing expression, to get consistent
|
|
|
|
// evaluation order across compilers.
|
2011-10-27 21:47:03 +00:00
|
|
|
SkScalar y = rand->nextUScalar1() * 480;
|
|
|
|
SkScalar x = rand->nextUScalar1() * 640;
|
2011-08-26 14:40:38 +00:00
|
|
|
pts[i].set(x, y);
|
|
|
|
}
|
2011-02-17 15:06:52 +00:00
|
|
|
}
|
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
void onDraw(SkCanvas* canvas) override {
|
2011-02-17 15:06:52 +00:00
|
|
|
canvas->translate(SK_Scalar1, SK_Scalar1);
|
|
|
|
|
2014-12-15 20:54:51 +00:00
|
|
|
SkRandom rand;
|
2011-02-17 15:06:52 +00:00
|
|
|
SkPaint p0, p1, p2, p3;
|
|
|
|
const size_t n = 99;
|
|
|
|
|
|
|
|
p0.setColor(SK_ColorRED);
|
|
|
|
p1.setColor(SK_ColorGREEN);
|
|
|
|
p2.setColor(SK_ColorBLUE);
|
|
|
|
p3.setColor(SK_ColorWHITE);
|
|
|
|
|
|
|
|
p0.setStrokeWidth(SkIntToScalar(4));
|
|
|
|
p2.setStrokeCap(SkPaint::kRound_Cap);
|
|
|
|
p2.setStrokeWidth(SkIntToScalar(6));
|
|
|
|
|
|
|
|
SkPoint* pts = new SkPoint[n];
|
|
|
|
fill_pts(pts, n, &rand);
|
|
|
|
|
|
|
|
canvas->drawPoints(SkCanvas::kPolygon_PointMode, n, pts, p0);
|
|
|
|
canvas->drawPoints(SkCanvas::kLines_PointMode, n, pts, p1);
|
|
|
|
canvas->drawPoints(SkCanvas::kPoints_PointMode, n, pts, p2);
|
|
|
|
canvas->drawPoints(SkCanvas::kPoints_PointMode, n, pts, p3);
|
|
|
|
|
|
|
|
delete[] pts;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
typedef GM INHERITED;
|
|
|
|
};
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2019-01-23 15:22:01 +00:00
|
|
|
DEF_GM( return new PointsGM; )
|
2011-02-17 15:06:52 +00:00
|
|
|
|
|
|
|
}
|