epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 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 | */ |
reed@google.com | bf0001d | 2014-01-13 14:53:55 +0000 | [diff] [blame] | 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" |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 11 | #include "SkGradientShader.h" |
| 12 | #include "SkGraphics.h" |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 13 | #include "SkPath.h" |
| 14 | #include "SkRandom.h" |
| 15 | #include "SkRegion.h" |
| 16 | #include "SkShader.h" |
| 17 | #include "SkUtils.h" |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 18 | #include "SkColorPriv.h" |
| 19 | #include "SkColorFilter.h" |
| 20 | #include "SkTime.h" |
| 21 | #include "SkTypeface.h" |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 22 | #include "SkStream.h" |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 23 | |
reed@google.com | f218339 | 2011-04-22 14:10:48 +0000 | [diff] [blame] | 24 | class PointsView : public SampleView { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 25 | public: |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 26 | PointsView() {} |
reed@google.com | a965a15 | 2011-02-17 15:06:52 +0000 | [diff] [blame] | 27 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 28 | protected: |
| 29 | // overrides from SkEventSink |
reed@google.com | a965a15 | 2011-02-17 15:06:52 +0000 | [diff] [blame] | 30 | virtual bool onQuery(SkEvent* evt) { |
| 31 | if (SampleCode::TitleQ(*evt)) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 32 | SampleCode::TitleR(evt, "Points"); |
| 33 | return true; |
| 34 | } |
| 35 | return this->INHERITED::onQuery(evt); |
| 36 | } |
| 37 | |
commit-bot@chromium.org | e0e7cfe | 2013-09-09 20:09:12 +0000 | [diff] [blame] | 38 | static void fill_pts(SkPoint pts[], size_t n, SkRandom* rand) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 39 | for (size_t i = 0; i < n; i++) |
| 40 | pts[i].set(rand->nextUScalar1() * 640, rand->nextUScalar1() * 480); |
| 41 | } |
reed@google.com | a965a15 | 2011-02-17 15:06:52 +0000 | [diff] [blame] | 42 | |
reed@google.com | f218339 | 2011-04-22 14:10:48 +0000 | [diff] [blame] | 43 | virtual void onDrawContent(SkCanvas* canvas) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 44 | canvas->translate(SK_Scalar1, SK_Scalar1); |
reed@google.com | a965a15 | 2011-02-17 15:06:52 +0000 | [diff] [blame] | 45 | |
commit-bot@chromium.org | e0e7cfe | 2013-09-09 20:09:12 +0000 | [diff] [blame] | 46 | SkRandom rand; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 47 | SkPaint p0, p1, p2, p3; |
| 48 | const size_t n = 99; |
reed@google.com | a965a15 | 2011-02-17 15:06:52 +0000 | [diff] [blame] | 49 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 50 | p0.setColor(SK_ColorRED); |
| 51 | p1.setColor(SK_ColorGREEN); |
| 52 | p2.setColor(SK_ColorBLUE); |
| 53 | p3.setColor(SK_ColorWHITE); |
reed@google.com | a965a15 | 2011-02-17 15:06:52 +0000 | [diff] [blame] | 54 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 55 | p0.setStrokeWidth(SkIntToScalar(4)); |
reed@android.com | b4f404a | 2009-07-10 17:02:17 +0000 | [diff] [blame] | 56 | p2.setStrokeCap(SkPaint::kRound_Cap); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 57 | p2.setStrokeWidth(SkIntToScalar(6)); |
| 58 | |
| 59 | SkPoint* pts = new SkPoint[n]; |
| 60 | fill_pts(pts, n, &rand); |
| 61 | |
reed@google.com | a965a15 | 2011-02-17 15:06:52 +0000 | [diff] [blame] | 62 | 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.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 67 | delete[] pts; |
| 68 | } |
reed@google.com | a965a15 | 2011-02-17 15:06:52 +0000 | [diff] [blame] | 69 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 70 | private: |
| 71 | |
reed@google.com | f218339 | 2011-04-22 14:10:48 +0000 | [diff] [blame] | 72 | typedef SampleView INHERITED; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 73 | }; |
| 74 | |
| 75 | ////////////////////////////////////////////////////////////////////////////// |
| 76 | |
| 77 | static SkView* MyFactory() { return new PointsView; } |
| 78 | static SkViewRegister reg(MyFactory); |