epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 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 | */ |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 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" |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 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 | |
reed@google.com | f218339 | 2011-04-22 14:10:48 +0000 | [diff] [blame] | 30 | class PointsView : public SampleView { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 31 | public: |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 32 | PointsView() {} |
reed@google.com | a965a15 | 2011-02-17 15:06:52 +0000 | [diff] [blame] | 33 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 34 | protected: |
| 35 | // overrides from SkEventSink |
reed@google.com | a965a15 | 2011-02-17 15:06:52 +0000 | [diff] [blame] | 36 | virtual bool onQuery(SkEvent* evt) { |
| 37 | if (SampleCode::TitleQ(*evt)) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 38 | SampleCode::TitleR(evt, "Points"); |
| 39 | return true; |
| 40 | } |
| 41 | return this->INHERITED::onQuery(evt); |
| 42 | } |
| 43 | |
reed@google.com | a965a15 | 2011-02-17 15:06:52 +0000 | [diff] [blame] | 44 | static void fill_pts(SkPoint pts[], size_t n, SkRandom* rand) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 45 | for (size_t i = 0; i < n; i++) |
| 46 | pts[i].set(rand->nextUScalar1() * 640, rand->nextUScalar1() * 480); |
| 47 | } |
reed@google.com | a965a15 | 2011-02-17 15:06:52 +0000 | [diff] [blame] | 48 | |
reed@google.com | f218339 | 2011-04-22 14:10:48 +0000 | [diff] [blame] | 49 | virtual void onDrawContent(SkCanvas* canvas) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 50 | canvas->translate(SK_Scalar1, SK_Scalar1); |
reed@google.com | a965a15 | 2011-02-17 15:06:52 +0000 | [diff] [blame] | 51 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 52 | SkRandom rand; |
| 53 | SkPaint p0, p1, p2, p3; |
| 54 | const size_t n = 99; |
reed@google.com | a965a15 | 2011-02-17 15:06:52 +0000 | [diff] [blame] | 55 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 56 | p0.setColor(SK_ColorRED); |
| 57 | p1.setColor(SK_ColorGREEN); |
| 58 | p2.setColor(SK_ColorBLUE); |
| 59 | p3.setColor(SK_ColorWHITE); |
reed@google.com | a965a15 | 2011-02-17 15:06:52 +0000 | [diff] [blame] | 60 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 61 | p0.setStrokeWidth(SkIntToScalar(4)); |
reed@android.com | b4f404a | 2009-07-10 17:02:17 +0000 | [diff] [blame] | 62 | p2.setStrokeCap(SkPaint::kRound_Cap); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 63 | p2.setStrokeWidth(SkIntToScalar(6)); |
| 64 | |
| 65 | SkPoint* pts = new SkPoint[n]; |
| 66 | fill_pts(pts, n, &rand); |
| 67 | |
reed@google.com | a965a15 | 2011-02-17 15:06:52 +0000 | [diff] [blame] | 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 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 73 | delete[] pts; |
| 74 | } |
reed@google.com | a965a15 | 2011-02-17 15:06:52 +0000 | [diff] [blame] | 75 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 76 | private: |
| 77 | |
reed@google.com | f218339 | 2011-04-22 14:10:48 +0000 | [diff] [blame] | 78 | typedef SampleView INHERITED; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 79 | }; |
| 80 | |
| 81 | ////////////////////////////////////////////////////////////////////////////// |
| 82 | |
| 83 | static SkView* MyFactory() { return new PointsView; } |
| 84 | static SkViewRegister reg(MyFactory); |