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" |
robertphillips@google.com | b706117 | 2013-09-06 14:16:12 +0000 | [diff] [blame] | 9 | #include "SkBlurMask.h" |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 10 | #include "SkView.h" |
| 11 | #include "SkCanvas.h" |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 12 | #include "SkColorShader.h" |
| 13 | #include "SkEmbossMaskFilter.h" |
| 14 | #include "SkGradientShader.h" |
| 15 | #include "SkGraphics.h" |
| 16 | #include "SkImageDecoder.h" |
| 17 | #include "SkKernel33MaskFilter.h" |
| 18 | #include "SkPath.h" |
| 19 | #include "SkRandom.h" |
| 20 | #include "SkRegion.h" |
| 21 | #include "SkShader.h" |
| 22 | #include "SkUtils.h" |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 23 | #include "SkColorPriv.h" |
| 24 | #include "SkColorFilter.h" |
| 25 | #include "SkTime.h" |
| 26 | #include "SkTypeface.h" |
| 27 | #include "SkXfermode.h" |
| 28 | |
reed@google.com | 961ddb0 | 2011-05-05 14:03:48 +0000 | [diff] [blame] | 29 | class EmbossView : public SampleView { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 30 | SkEmbossMaskFilter::Light fLight; |
| 31 | public: |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 32 | EmbossView() { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 33 | fLight.fDirection[0] = SK_Scalar1; |
| 34 | fLight.fDirection[1] = SK_Scalar1; |
| 35 | fLight.fDirection[2] = SK_Scalar1; |
| 36 | fLight.fAmbient = 128; |
| 37 | fLight.fSpecular = 16*2; |
| 38 | } |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 39 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 40 | protected: |
| 41 | // overrides from SkEventSink |
reed@google.com | 961ddb0 | 2011-05-05 14:03:48 +0000 | [diff] [blame] | 42 | virtual bool onQuery(SkEvent* evt) { |
| 43 | if (SampleCode::TitleQ(*evt)) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 44 | SampleCode::TitleR(evt, "Emboss"); |
| 45 | return true; |
| 46 | } |
| 47 | return this->INHERITED::onQuery(evt); |
| 48 | } |
| 49 | |
reed@google.com | 961ddb0 | 2011-05-05 14:03:48 +0000 | [diff] [blame] | 50 | virtual void onDrawContent(SkCanvas* canvas) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 51 | SkPaint paint; |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 52 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 53 | paint.setAntiAlias(true); |
| 54 | paint.setStyle(SkPaint::kStroke_Style); |
| 55 | paint.setStrokeWidth(SkIntToScalar(10)); |
commit-bot@chromium.org | 7c9d0f3 | 2014-02-21 10:13:32 +0000 | [diff] [blame] | 56 | paint.setMaskFilter(SkEmbossMaskFilter::Create( |
robertphillips@google.com | b706117 | 2013-09-06 14:16:12 +0000 | [diff] [blame] | 57 | SkBlurMask::ConvertRadiusToSigma(SkIntToScalar(4)), fLight))->unref(); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 58 | paint.setShader(new SkColorShader(SK_ColorBLUE))->unref(); |
| 59 | paint.setDither(true); |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 60 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 61 | canvas->drawCircle(SkIntToScalar(50), SkIntToScalar(50), |
| 62 | SkIntToScalar(30), paint); |
| 63 | } |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 64 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 65 | private: |
| 66 | |
reed@google.com | 961ddb0 | 2011-05-05 14:03:48 +0000 | [diff] [blame] | 67 | typedef SampleView INHERITED; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 68 | }; |
| 69 | |
| 70 | ////////////////////////////////////////////////////////////////////////////// |
| 71 | |
| 72 | static SkView* MyFactory() { return new EmbossView; } |
| 73 | static SkViewRegister reg(MyFactory); |