blob: 13b98972d35b944bc345882c55784ab06b44f3b1 [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"
reed@android.com8a1c16f2008-12-17 15:59:43 +000013#include "SkPath.h"
14#include "SkRandom.h"
15#include "SkRegion.h"
16#include "SkShader.h"
17#include "SkUtils.h"
reed@android.com8a1c16f2008-12-17 15:59:43 +000018#include "SkColorPriv.h"
19#include "SkColorFilter.h"
20#include "SkTime.h"
21#include "SkTypeface.h"
reed@android.com8a1c16f2008-12-17 15:59:43 +000022#include "SkStream.h"
reed@android.com8a1c16f2008-12-17 15:59:43 +000023
reed@google.comf2183392011-04-22 14:10:48 +000024class PointsView : public SampleView {
reed@android.com8a1c16f2008-12-17 15:59:43 +000025public:
rmistry@google.comae933ce2012-08-23 18:19:56 +000026 PointsView() {}
reed@google.coma965a152011-02-17 15:06:52 +000027
reed@android.com8a1c16f2008-12-17 15:59:43 +000028protected:
29 // overrides from SkEventSink
reed@google.coma965a152011-02-17 15:06:52 +000030 virtual bool onQuery(SkEvent* evt) {
31 if (SampleCode::TitleQ(*evt)) {
reed@android.com8a1c16f2008-12-17 15:59:43 +000032 SampleCode::TitleR(evt, "Points");
33 return true;
34 }
35 return this->INHERITED::onQuery(evt);
36 }
37
commit-bot@chromium.orge0e7cfe2013-09-09 20:09:12 +000038 static void fill_pts(SkPoint pts[], size_t n, SkRandom* rand) {
reed@android.com8a1c16f2008-12-17 15:59:43 +000039 for (size_t i = 0; i < n; i++)
40 pts[i].set(rand->nextUScalar1() * 640, rand->nextUScalar1() * 480);
41 }
reed@google.coma965a152011-02-17 15:06:52 +000042
reed@google.comf2183392011-04-22 14:10:48 +000043 virtual void onDrawContent(SkCanvas* canvas) {
reed@android.com8a1c16f2008-12-17 15:59:43 +000044 canvas->translate(SK_Scalar1, SK_Scalar1);
reed@google.coma965a152011-02-17 15:06:52 +000045
commit-bot@chromium.orge0e7cfe2013-09-09 20:09:12 +000046 SkRandom rand;
reed@android.com8a1c16f2008-12-17 15:59:43 +000047 SkPaint p0, p1, p2, p3;
48 const size_t n = 99;
reed@google.coma965a152011-02-17 15:06:52 +000049
reed@android.com8a1c16f2008-12-17 15:59:43 +000050 p0.setColor(SK_ColorRED);
51 p1.setColor(SK_ColorGREEN);
52 p2.setColor(SK_ColorBLUE);
53 p3.setColor(SK_ColorWHITE);
reed@google.coma965a152011-02-17 15:06:52 +000054
reed@android.com8a1c16f2008-12-17 15:59:43 +000055 p0.setStrokeWidth(SkIntToScalar(4));
reed@android.comb4f404a2009-07-10 17:02:17 +000056 p2.setStrokeCap(SkPaint::kRound_Cap);
reed@android.com8a1c16f2008-12-17 15:59:43 +000057 p2.setStrokeWidth(SkIntToScalar(6));
58
59 SkPoint* pts = new SkPoint[n];
60 fill_pts(pts, n, &rand);
61
reed@google.coma965a152011-02-17 15:06:52 +000062 canvas->drawPoints(SkCanvas::kPolygon_PointMode, n, pts, p0);
63 canvas->drawPoints(SkCanvas::kLines_PointMode, n, pts, p1);
64 canvas->drawPoints(SkCanvas::kPoints_PointMode, n, pts, p2);
65 canvas->drawPoints(SkCanvas::kPoints_PointMode, n, pts, p3);
66
reed@android.com8a1c16f2008-12-17 15:59:43 +000067 delete[] pts;
68 }
reed@google.coma965a152011-02-17 15:06:52 +000069
reed@android.com8a1c16f2008-12-17 15:59:43 +000070private:
71
reed@google.comf2183392011-04-22 14:10:48 +000072 typedef SampleView INHERITED;
reed@android.com8a1c16f2008-12-17 15:59:43 +000073};
74
75//////////////////////////////////////////////////////////////////////////////
76
77static SkView* MyFactory() { return new PointsView; }
78static SkViewRegister reg(MyFactory);