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