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