1 /*
2 * Copyright 2011 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8 #include "SampleCode.h"
9 #include "SkView.h"
10 #include "SkCanvas.h"
11 #include "SkGradientShader.h"
12 #include "SkGraphics.h"
13 #include "SkPath.h"
14 #include "SkRandom.h"
15 #include "SkRegion.h"
16 #include "SkShader.h"
17 #include "SkUtils.h"
18 #include "SkColorPriv.h"
19 #include "SkColorFilter.h"
20 #include "SkTime.h"
21 #include "SkTypeface.h"
22 #include "SkStream.h"
23
24 class PointsView : public SampleView {
25 public:
PointsView()26 PointsView() {}
27
28 protected:
29 // overrides from SkEventSink
onQuery(SkEvent * evt)30 virtual bool onQuery(SkEvent* evt) {
31 if (SampleCode::TitleQ(*evt)) {
32 SampleCode::TitleR(evt, "Points");
33 return true;
34 }
35 return this->INHERITED::onQuery(evt);
36 }
37
fill_pts(SkPoint pts[],size_t n,SkRandom * rand)38 static void fill_pts(SkPoint pts[], size_t n, SkRandom* rand) {
39 for (size_t i = 0; i < n; i++)
40 pts[i].set(rand->nextUScalar1() * 640, rand->nextUScalar1() * 480);
41 }
42
onDrawContent(SkCanvas * canvas)43 virtual void onDrawContent(SkCanvas* canvas) {
44 canvas->translate(SK_Scalar1, SK_Scalar1);
45
46 SkRandom rand;
47 SkPaint p0, p1, p2, p3;
48 const size_t n = 99;
49
50 p0.setColor(SK_ColorRED);
51 p1.setColor(SK_ColorGREEN);
52 p2.setColor(SK_ColorBLUE);
53 p3.setColor(SK_ColorWHITE);
54
55 p0.setStrokeWidth(SkIntToScalar(4));
56 p2.setStrokeCap(SkPaint::kRound_Cap);
57 p2.setStrokeWidth(SkIntToScalar(6));
58
59 SkPoint* pts = new SkPoint[n];
60 fill_pts(pts, n, &rand);
61
62 canvas->drawPoints(SkCanvas::kPolygon_PointMode, n, pts, p0);
63 canvas->drawPoints(SkCanvas::kLines_PointMode, n, pts, p1);
64 canvas->drawPoints(SkCanvas::kPoints_PointMode, n, pts, p2);
65 canvas->drawPoints(SkCanvas::kPoints_PointMode, n, pts, p3);
66
67 delete[] pts;
68 }
69
70 private:
71
72 typedef SampleView INHERITED;
73 };
74
75 //////////////////////////////////////////////////////////////////////////////
76
MyFactory()77 static SkView* MyFactory() { return new PointsView; }
78 static SkViewRegister reg(MyFactory);
79