blob: ac2f625f998005c58238b8af7038a776d2e7d08e [file] [log] [blame]
epoger@google.comec3ed6a2011-07-28 14:26:00 +00001
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 */
reed@android.com8a1c16f2008-12-17 15:59:43 +00008#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"
reed@android.com8a1c16f2008-12-17 15:59:43 +000021#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
reed@google.comf2183392011-04-22 14:10:48 +000030class PointsView : public SampleView {
reed@android.com8a1c16f2008-12-17 15:59:43 +000031public:
rmistry@google.comae933ce2012-08-23 18:19:56 +000032 PointsView() {}
reed@google.coma965a152011-02-17 15:06:52 +000033
reed@android.com8a1c16f2008-12-17 15:59:43 +000034protected:
35 // overrides from SkEventSink
reed@google.coma965a152011-02-17 15:06:52 +000036 virtual bool onQuery(SkEvent* evt) {
37 if (SampleCode::TitleQ(*evt)) {
reed@android.com8a1c16f2008-12-17 15:59:43 +000038 SampleCode::TitleR(evt, "Points");
39 return true;
40 }
41 return this->INHERITED::onQuery(evt);
42 }
43
reed@google.coma965a152011-02-17 15:06:52 +000044 static void fill_pts(SkPoint pts[], size_t n, SkRandom* rand) {
reed@android.com8a1c16f2008-12-17 15:59:43 +000045 for (size_t i = 0; i < n; i++)
46 pts[i].set(rand->nextUScalar1() * 640, rand->nextUScalar1() * 480);
47 }
reed@google.coma965a152011-02-17 15:06:52 +000048
reed@google.comf2183392011-04-22 14:10:48 +000049 virtual void onDrawContent(SkCanvas* canvas) {
reed@android.com8a1c16f2008-12-17 15:59:43 +000050 canvas->translate(SK_Scalar1, SK_Scalar1);
reed@google.coma965a152011-02-17 15:06:52 +000051
reed@android.com8a1c16f2008-12-17 15:59:43 +000052 SkRandom rand;
53 SkPaint p0, p1, p2, p3;
54 const size_t n = 99;
reed@google.coma965a152011-02-17 15:06:52 +000055
reed@android.com8a1c16f2008-12-17 15:59:43 +000056 p0.setColor(SK_ColorRED);
57 p1.setColor(SK_ColorGREEN);
58 p2.setColor(SK_ColorBLUE);
59 p3.setColor(SK_ColorWHITE);
reed@google.coma965a152011-02-17 15:06:52 +000060
reed@android.com8a1c16f2008-12-17 15:59:43 +000061 p0.setStrokeWidth(SkIntToScalar(4));
reed@android.comb4f404a2009-07-10 17:02:17 +000062 p2.setStrokeCap(SkPaint::kRound_Cap);
reed@android.com8a1c16f2008-12-17 15:59:43 +000063 p2.setStrokeWidth(SkIntToScalar(6));
64
65 SkPoint* pts = new SkPoint[n];
66 fill_pts(pts, n, &rand);
67
reed@google.coma965a152011-02-17 15:06:52 +000068 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
reed@android.com8a1c16f2008-12-17 15:59:43 +000073 delete[] pts;
74 }
reed@google.coma965a152011-02-17 15:06:52 +000075
reed@android.com8a1c16f2008-12-17 15:59:43 +000076private:
77
reed@google.comf2183392011-04-22 14:10:48 +000078 typedef SampleView INHERITED;
reed@android.com8a1c16f2008-12-17 15:59:43 +000079};
80
81//////////////////////////////////////////////////////////////////////////////
82
83static SkView* MyFactory() { return new PointsView; }
84static SkViewRegister reg(MyFactory);