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 "SkImageDecoder.h"
14 #include "SkPath.h"
15 #include "SkRandom.h"
16 #include "SkRegion.h"
17 #include "SkShader.h"
18 #include "SkUtils.h"
19 #include "SkColorPriv.h"
20 #include "SkColorFilter.h"
21 #include "SkTime.h"
22 #include "SkTypeface.h"
23 #include "SkXfermode.h"
24 
25 #include "SkStream.h"
26 #include "SkXMLParser.h"
27 
28 class PointsView : public SampleView {
29 public:
PointsView()30     PointsView() {}
31 
32 protected:
33     // overrides from SkEventSink
onQuery(SkEvent * evt)34     virtual bool onQuery(SkEvent* evt) {
35         if (SampleCode::TitleQ(*evt)) {
36             SampleCode::TitleR(evt, "Points");
37             return true;
38         }
39         return this->INHERITED::onQuery(evt);
40     }
41 
fill_pts(SkPoint pts[],size_t n,SkRandom * rand)42     static void fill_pts(SkPoint pts[], size_t n, SkRandom* rand) {
43         for (size_t i = 0; i < n; i++)
44             pts[i].set(rand->nextUScalar1() * 640, rand->nextUScalar1() * 480);
45     }
46 
onDrawContent(SkCanvas * canvas)47     virtual void onDrawContent(SkCanvas* canvas) {
48         canvas->translate(SK_Scalar1, SK_Scalar1);
49 
50         SkRandom rand;
51         SkPaint  p0, p1, p2, p3;
52         const size_t n = 99;
53 
54         p0.setColor(SK_ColorRED);
55         p1.setColor(SK_ColorGREEN);
56         p2.setColor(SK_ColorBLUE);
57         p3.setColor(SK_ColorWHITE);
58 
59         p0.setStrokeWidth(SkIntToScalar(4));
60         p2.setStrokeCap(SkPaint::kRound_Cap);
61         p2.setStrokeWidth(SkIntToScalar(6));
62 
63         SkPoint* pts = new SkPoint[n];
64         fill_pts(pts, n, &rand);
65 
66         canvas->drawPoints(SkCanvas::kPolygon_PointMode, n, pts, p0);
67         canvas->drawPoints(SkCanvas::kLines_PointMode, n, pts, p1);
68         canvas->drawPoints(SkCanvas::kPoints_PointMode, n, pts, p2);
69         canvas->drawPoints(SkCanvas::kPoints_PointMode, n, pts, p3);
70 
71         delete[] pts;
72     }
73 
74 private:
75 
76     typedef SampleView INHERITED;
77 };
78 
79 //////////////////////////////////////////////////////////////////////////////
80 
MyFactory()81 static SkView* MyFactory() { return new PointsView; }
82 static SkViewRegister reg(MyFactory);
83