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