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