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 | c07d23a | 2009-02-06 13:30:58 +0000 | [diff] [blame] | 8 | #include "SampleCode.h" |
| 9 | #include "SkView.h" |
| 10 | #include "SkCanvas.h" |
| 11 | #include "SkGradientShader.h" |
| 12 | #include "SkGraphics.h" |
| 13 | #include "SkImageDecoder.h" |
| 14 | #include "SkPath.h" |
reed@android.com | c07d23a | 2009-02-06 13:30:58 +0000 | [diff] [blame] | 15 | #include "SkRegion.h" |
| 16 | #include "SkShader.h" |
| 17 | #include "SkUtils.h" |
| 18 | #include "SkXfermode.h" |
| 19 | #include "SkColorPriv.h" |
| 20 | #include "SkColorFilter.h" |
| 21 | #include "SkTime.h" |
| 22 | #include "SkTypeface.h" |
| 23 | |
reed@google.com | 81e3d7f | 2011-06-01 12:42:36 +0000 | [diff] [blame] | 24 | class PathClipView : public SampleView { |
reed@android.com | c07d23a | 2009-02-06 13:30:58 +0000 | [diff] [blame] | 25 | public: |
| 26 | SkRect fOval; |
| 27 | SkPoint fCenter; |
| 28 | |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 29 | PathClipView() { |
reed@android.com | c07d23a | 2009-02-06 13:30:58 +0000 | [diff] [blame] | 30 | fOval.set(0, 0, SkIntToScalar(200), SkIntToScalar(50)); |
| 31 | fCenter.set(SkIntToScalar(250), SkIntToScalar(250)); |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 32 | |
reed@android.com | 54043a3 | 2009-03-05 14:14:49 +0000 | [diff] [blame] | 33 | // test_ats(); |
reed@android.com | c07d23a | 2009-02-06 13:30:58 +0000 | [diff] [blame] | 34 | } |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 35 | |
reed@android.com | c07d23a | 2009-02-06 13:30:58 +0000 | [diff] [blame] | 36 | virtual ~PathClipView() {} |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 37 | |
reed@android.com | c07d23a | 2009-02-06 13:30:58 +0000 | [diff] [blame] | 38 | protected: |
| 39 | // overrides from SkEventSink |
| 40 | virtual bool onQuery(SkEvent* evt) { |
| 41 | if (SampleCode::TitleQ(*evt)) { |
| 42 | SampleCode::TitleR(evt, "PathClip"); |
| 43 | return true; |
| 44 | } |
| 45 | return this->INHERITED::onQuery(evt); |
| 46 | } |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 47 | |
reed@google.com | 81e3d7f | 2011-06-01 12:42:36 +0000 | [diff] [blame] | 48 | virtual void onDrawContent(SkCanvas* canvas) { |
reed@android.com | c07d23a | 2009-02-06 13:30:58 +0000 | [diff] [blame] | 49 | SkRect oval = fOval; |
| 50 | oval.offset(fCenter.fX - oval.centerX(), fCenter.fY - oval.centerY()); |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 51 | |
reed@android.com | c07d23a | 2009-02-06 13:30:58 +0000 | [diff] [blame] | 52 | SkPaint p; |
| 53 | p.setAntiAlias(true); |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 54 | |
reed@android.com | c07d23a | 2009-02-06 13:30:58 +0000 | [diff] [blame] | 55 | p.setStyle(SkPaint::kStroke_Style); |
| 56 | canvas->drawOval(oval, p); |
| 57 | |
| 58 | SkRect r; |
| 59 | r.set(SkIntToScalar(200), SkIntToScalar(200), |
| 60 | SkIntToScalar(300), SkIntToScalar(300)); |
| 61 | canvas->clipRect(r); |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 62 | |
reed@android.com | c07d23a | 2009-02-06 13:30:58 +0000 | [diff] [blame] | 63 | p.setStyle(SkPaint::kFill_Style); |
| 64 | p.setColor(SK_ColorRED); |
| 65 | canvas->drawRect(r, p); |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 66 | |
reed@android.com | c07d23a | 2009-02-06 13:30:58 +0000 | [diff] [blame] | 67 | p.setColor(0x800000FF); |
| 68 | r.set(SkIntToScalar(150), SkIntToScalar(10), |
| 69 | SkIntToScalar(250), SkIntToScalar(400)); |
| 70 | canvas->drawOval(oval, p); |
| 71 | } |
reed@android.com | e72fee5 | 2009-11-16 14:52:01 +0000 | [diff] [blame] | 72 | |
mtklein | 72c9faa | 2015-01-09 10:06:39 -0800 | [diff] [blame] | 73 | SkView::Click* onFindClickHandler(SkScalar x, SkScalar y, unsigned) SK_OVERRIDE { |
reed@android.com | e72fee5 | 2009-11-16 14:52:01 +0000 | [diff] [blame] | 74 | return new Click(this); |
| 75 | } |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 76 | |
reed@android.com | e72fee5 | 2009-11-16 14:52:01 +0000 | [diff] [blame] | 77 | virtual bool onClick(Click* click) { |
| 78 | fCenter.set(click->fCurr.fX, click->fCurr.fY); |
reed@android.com | c07d23a | 2009-02-06 13:30:58 +0000 | [diff] [blame] | 79 | this->inval(NULL); |
caryclark@google.com | 02939ce | 2012-06-06 12:09:51 +0000 | [diff] [blame] | 80 | return false; |
reed@android.com | c07d23a | 2009-02-06 13:30:58 +0000 | [diff] [blame] | 81 | } |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 82 | |
reed@android.com | c07d23a | 2009-02-06 13:30:58 +0000 | [diff] [blame] | 83 | private: |
reed@google.com | 81e3d7f | 2011-06-01 12:42:36 +0000 | [diff] [blame] | 84 | typedef SampleView INHERITED; |
reed@android.com | c07d23a | 2009-02-06 13:30:58 +0000 | [diff] [blame] | 85 | }; |
| 86 | |
| 87 | ////////////////////////////////////////////////////////////////////////////// |
| 88 | |
| 89 | static SkView* MyFactory() { return new PathClipView; } |
| 90 | static SkViewRegister reg(MyFactory); |