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.
|
|
|
|
*/
|
2014-01-13 14:53:55 +00:00
|
|
|
|
2018-08-08 15:36:17 +00:00
|
|
|
#include "Sample.h"
|
2008-12-17 15:59:43 +00:00
|
|
|
#include "SkCanvas.h"
|
|
|
|
#include "SkGradientShader.h"
|
|
|
|
#include "SkGraphics.h"
|
|
|
|
#include "SkPath.h"
|
|
|
|
#include "SkRandom.h"
|
|
|
|
#include "SkRegion.h"
|
|
|
|
#include "SkShader.h"
|
2018-08-21 15:45:46 +00:00
|
|
|
#include "SkUTF.h"
|
2008-12-17 15:59:43 +00:00
|
|
|
#include "SkColorPriv.h"
|
|
|
|
#include "SkColorFilter.h"
|
|
|
|
#include "SkTime.h"
|
|
|
|
#include "SkTypeface.h"
|
|
|
|
#include "SkStream.h"
|
|
|
|
|
2018-08-08 15:36:17 +00:00
|
|
|
class PointsView : public Sample {
|
2008-12-17 15:59:43 +00:00
|
|
|
public:
|
2012-08-23 18:19:56 +00:00
|
|
|
PointsView() {}
|
2011-02-17 15:06:52 +00:00
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
protected:
|
2018-08-08 15:36:17 +00:00
|
|
|
virtual bool onQuery(Sample::Event* evt) {
|
|
|
|
if (Sample::TitleQ(*evt)) {
|
|
|
|
Sample::TitleR(evt, "Points");
|
2008-12-17 15:59:43 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return this->INHERITED::onQuery(evt);
|
|
|
|
}
|
|
|
|
|
2013-09-09 20:09:12 +00:00
|
|
|
static void fill_pts(SkPoint pts[], size_t n, SkRandom* rand) {
|
2008-12-17 15:59:43 +00:00
|
|
|
for (size_t i = 0; i < n; i++)
|
|
|
|
pts[i].set(rand->nextUScalar1() * 640, rand->nextUScalar1() * 480);
|
|
|
|
}
|
2011-02-17 15:06:52 +00:00
|
|
|
|
2011-04-22 14:10:48 +00:00
|
|
|
virtual void onDrawContent(SkCanvas* canvas) {
|
2008-12-17 15:59:43 +00:00
|
|
|
canvas->translate(SK_Scalar1, SK_Scalar1);
|
2011-02-17 15:06:52 +00:00
|
|
|
|
2013-09-09 20:09:12 +00:00
|
|
|
SkRandom rand;
|
2008-12-17 15:59:43 +00:00
|
|
|
SkPaint p0, p1, p2, p3;
|
|
|
|
const size_t n = 99;
|
2011-02-17 15:06:52 +00:00
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
p0.setColor(SK_ColorRED);
|
|
|
|
p1.setColor(SK_ColorGREEN);
|
|
|
|
p2.setColor(SK_ColorBLUE);
|
|
|
|
p3.setColor(SK_ColorWHITE);
|
2011-02-17 15:06:52 +00:00
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
p0.setStrokeWidth(SkIntToScalar(4));
|
2009-07-10 17:02:17 +00:00
|
|
|
p2.setStrokeCap(SkPaint::kRound_Cap);
|
2008-12-17 15:59:43 +00:00
|
|
|
p2.setStrokeWidth(SkIntToScalar(6));
|
|
|
|
|
|
|
|
SkPoint* pts = new SkPoint[n];
|
|
|
|
fill_pts(pts, n, &rand);
|
|
|
|
|
2011-02-17 15:06:52 +00:00
|
|
|
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);
|
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
delete[] pts;
|
|
|
|
}
|
2011-02-17 15:06:52 +00:00
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
private:
|
|
|
|
|
2018-08-08 15:36:17 +00:00
|
|
|
typedef Sample INHERITED;
|
2008-12-17 15:59:43 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2018-08-08 15:36:17 +00:00
|
|
|
DEF_SAMPLE( return new PointsView(); )
|