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 | |
msarett | d15750c | 2016-03-18 15:48:49 -0700 | [diff] [blame] | 8 | #include "DecodeFile.h" |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 9 | #include "SampleCode.h" |
| 10 | #include "SkView.h" |
| 11 | #include "SkCanvas.h" |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 12 | #include "SkCornerPathEffect.h" |
| 13 | #include "SkGradientShader.h" |
| 14 | #include "SkGraphics.h" |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 15 | #include "SkPath.h" |
| 16 | #include "SkRandom.h" |
| 17 | #include "SkRegion.h" |
| 18 | #include "SkShader.h" |
| 19 | #include "SkUtils.h" |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 20 | #include "SkColorPriv.h" |
| 21 | #include "SkColorFilter.h" |
| 22 | #include "SkTime.h" |
| 23 | #include "SkTypeface.h" |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 24 | #include "SkStream.h" |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 25 | #include "SkColorPriv.h" |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 26 | |
reed@google.com | 961ddb0 | 2011-05-05 14:03:48 +0000 | [diff] [blame] | 27 | class LinesView : public SampleView { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 28 | public: |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 29 | LinesView() {} |
| 30 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 31 | protected: |
| 32 | // overrides from SkEventSink |
mtklein | f059900 | 2015-07-13 06:18:39 -0700 | [diff] [blame] | 33 | bool onQuery(SkEvent* evt) override { |
reed@google.com | 961ddb0 | 2011-05-05 14:03:48 +0000 | [diff] [blame] | 34 | if (SampleCode::TitleQ(*evt)) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 35 | SampleCode::TitleR(evt, "Lines"); |
| 36 | return true; |
| 37 | } |
| 38 | return this->INHERITED::onQuery(evt); |
| 39 | } |
| 40 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 41 | /* |
| 42 | 0x1F * x + 0x1F * (32 - x) |
| 43 | */ |
reed@google.com | 961ddb0 | 2011-05-05 14:03:48 +0000 | [diff] [blame] | 44 | void drawRings(SkCanvas* canvas) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 45 | canvas->scale(SkIntToScalar(1)/2, SkIntToScalar(1)/2); |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 46 | |
| 47 | SkRect r; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 48 | SkScalar x = SkIntToScalar(10); |
| 49 | SkScalar y = SkIntToScalar(10); |
| 50 | r.set(x, y, x + SkIntToScalar(100), y + SkIntToScalar(100)); |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 51 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 52 | SkPaint paint; |
reed@android.com | f2b98d6 | 2010-12-20 18:26:13 +0000 | [diff] [blame] | 53 | // paint.setAntiAlias(true); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 54 | paint.setStyle(SkPaint::kStroke_Style); |
| 55 | paint.setStrokeWidth(SkScalarHalf(SkIntToScalar(3))); |
| 56 | paint.setColor(0xFFFF8800); |
reed@android.com | f2b98d6 | 2010-12-20 18:26:13 +0000 | [diff] [blame] | 57 | // paint.setColor(0xFFFFFFFF); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 58 | canvas->drawRect(r, paint); |
| 59 | } |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 60 | |
mtklein | f059900 | 2015-07-13 06:18:39 -0700 | [diff] [blame] | 61 | void onDrawContent(SkCanvas* canvas) override { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 62 | SkBitmap bm; |
msarett | d15750c | 2016-03-18 15:48:49 -0700 | [diff] [blame] | 63 | decode_file("/kill.gif", &bm); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 64 | canvas->drawBitmap(bm, 0, 0, nullptr); |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 65 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 66 | this->drawRings(canvas); |
| 67 | return; |
| 68 | |
| 69 | SkPaint paint; |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 70 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 71 | // fAlpha = 0x80; |
| 72 | paint.setColor(SK_ColorWHITE); |
| 73 | paint.setAlpha(fAlpha & 0xFF); |
| 74 | SkRect r; |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 75 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 76 | SkScalar x = SkIntToScalar(10); |
| 77 | SkScalar y = SkIntToScalar(10); |
| 78 | r.set(x, y, x + SkIntToScalar(100), y + SkIntToScalar(100)); |
| 79 | canvas->drawRect(r, paint); |
| 80 | return; |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 81 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 82 | paint.setColor(0xffffff00); // yellow |
| 83 | paint.setStyle(SkPaint::kStroke_Style); |
| 84 | paint.setStrokeWidth(SkIntToScalar(2)); |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 85 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 86 | // y += SK_Scalar1/2; |
| 87 | |
| 88 | canvas->drawLine(x, y, x + SkIntToScalar(90), y + SkIntToScalar(90), paint); |
| 89 | |
| 90 | paint.setAntiAlias(true); // with anti-aliasing |
| 91 | y += SkIntToScalar(10); |
| 92 | canvas->drawLine(x, y, x + SkIntToScalar(90), y + SkIntToScalar(90), paint); |
| 93 | } |
| 94 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 95 | SkView::Click* onFindClickHandler(SkScalar x, SkScalar y, unsigned) override { |
reed@google.com | e1ca705 | 2013-12-17 19:22:07 +0000 | [diff] [blame] | 96 | fAlpha = SkScalarRoundToInt(y); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 97 | this->inval(nullptr); |
| 98 | return nullptr; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 99 | } |
| 100 | private: |
| 101 | |
| 102 | int fAlpha; |
reed@google.com | 961ddb0 | 2011-05-05 14:03:48 +0000 | [diff] [blame] | 103 | typedef SampleView INHERITED; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 104 | }; |
| 105 | |
| 106 | ////////////////////////////////////////////////////////////////////////////// |
| 107 | |
| 108 | static SkView* MyFactory() { return new LinesView; } |
| 109 | static SkViewRegister reg(MyFactory); |