blob: 47a8b177107db9f14f877f1ff35fa135a0305157 [file] [log] [blame]
epoger@google.comec3ed6a2011-07-28 14:26:00 +00001/*
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 */
reed@google.combf0001d2014-01-13 14:53:55 +00007
reed@android.com8a1c16f2008-12-17 15:59:43 +00008#include "SampleCode.h"
9#include "SkView.h"
10#include "SkCanvas.h"
reed@android.com8a1c16f2008-12-17 15:59:43 +000011#include "SkGradientShader.h"
12#include "SkGraphics.h"
13#include "SkImageDecoder.h"
reed@android.com8a1c16f2008-12-17 15:59:43 +000014#include "SkPath.h"
15#include "SkRandom.h"
16#include "SkRegion.h"
17#include "SkShader.h"
18#include "SkUtils.h"
reed@android.com8a1c16f2008-12-17 15:59:43 +000019#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
reed@google.comf2183392011-04-22 14:10:48 +000028class PointsView : public SampleView {
reed@android.com8a1c16f2008-12-17 15:59:43 +000029public:
rmistry@google.comae933ce2012-08-23 18:19:56 +000030 PointsView() {}
reed@google.coma965a152011-02-17 15:06:52 +000031
reed@android.com8a1c16f2008-12-17 15:59:43 +000032protected:
33 // overrides from SkEventSink
reed@google.coma965a152011-02-17 15:06:52 +000034 virtual bool onQuery(SkEvent* evt) {
35 if (SampleCode::TitleQ(*evt)) {
reed@android.com8a1c16f2008-12-17 15:59:43 +000036 SampleCode::TitleR(evt, "Points");
37 return true;
38 }
39 return this->INHERITED::onQuery(evt);
40 }
41
commit-bot@chromium.orge0e7cfe2013-09-09 20:09:12 +000042 static void fill_pts(SkPoint pts[], size_t n, SkRandom* rand) {
reed@android.com8a1c16f2008-12-17 15:59:43 +000043 for (size_t i = 0; i < n; i++)
44 pts[i].set(rand->nextUScalar1() * 640, rand->nextUScalar1() * 480);
45 }
reed@google.coma965a152011-02-17 15:06:52 +000046
reed@google.comf2183392011-04-22 14:10:48 +000047 virtual void onDrawContent(SkCanvas* canvas) {
reed@android.com8a1c16f2008-12-17 15:59:43 +000048 canvas->translate(SK_Scalar1, SK_Scalar1);
reed@google.coma965a152011-02-17 15:06:52 +000049
commit-bot@chromium.orge0e7cfe2013-09-09 20:09:12 +000050 SkRandom rand;
reed@android.com8a1c16f2008-12-17 15:59:43 +000051 SkPaint p0, p1, p2, p3;
52 const size_t n = 99;
reed@google.coma965a152011-02-17 15:06:52 +000053
reed@android.com8a1c16f2008-12-17 15:59:43 +000054 p0.setColor(SK_ColorRED);
55 p1.setColor(SK_ColorGREEN);
56 p2.setColor(SK_ColorBLUE);
57 p3.setColor(SK_ColorWHITE);
reed@google.coma965a152011-02-17 15:06:52 +000058
reed@android.com8a1c16f2008-12-17 15:59:43 +000059 p0.setStrokeWidth(SkIntToScalar(4));
reed@android.comb4f404a2009-07-10 17:02:17 +000060 p2.setStrokeCap(SkPaint::kRound_Cap);
reed@android.com8a1c16f2008-12-17 15:59:43 +000061 p2.setStrokeWidth(SkIntToScalar(6));
62
63 SkPoint* pts = new SkPoint[n];
64 fill_pts(pts, n, &rand);
65
reed@google.coma965a152011-02-17 15:06:52 +000066 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
reed@android.com8a1c16f2008-12-17 15:59:43 +000071 delete[] pts;
72 }
reed@google.coma965a152011-02-17 15:06:52 +000073
reed@android.com8a1c16f2008-12-17 15:59:43 +000074private:
75
reed@google.comf2183392011-04-22 14:10:48 +000076 typedef SampleView INHERITED;
reed@android.com8a1c16f2008-12-17 15:59:43 +000077};
78
79//////////////////////////////////////////////////////////////////////////////
80
81static SkView* MyFactory() { return new PointsView; }
82static SkViewRegister reg(MyFactory);