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 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 8 | #include "include/core/SkCanvas.h" |
| 9 | #include "include/core/SkColorFilter.h" |
| 10 | #include "include/core/SkColorPriv.h" |
| 11 | #include "include/core/SkGraphics.h" |
| 12 | #include "include/core/SkPath.h" |
| 13 | #include "include/core/SkRegion.h" |
| 14 | #include "include/core/SkShader.h" |
| 15 | #include "include/core/SkTime.h" |
| 16 | #include "include/core/SkTypeface.h" |
| 17 | #include "include/effects/SkGradientShader.h" |
| 18 | #include "include/utils/SkRandom.h" |
| 19 | #include "samplecode/Sample.h" |
| 20 | #include "src/core/SkBlurMask.h" |
| 21 | #include "src/effects/SkEmbossMaskFilter.h" |
| 22 | #include "src/utils/SkUTF.h" |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 23 | |
Ben Wagner | b2c4ea6 | 2018-08-08 11:36:17 -0400 | [diff] [blame] | 24 | class EmbossView : public Sample { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 25 | SkEmbossMaskFilter::Light fLight; |
| 26 | public: |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 27 | EmbossView() { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 28 | fLight.fDirection[0] = SK_Scalar1; |
| 29 | fLight.fDirection[1] = SK_Scalar1; |
| 30 | fLight.fDirection[2] = SK_Scalar1; |
| 31 | fLight.fAmbient = 128; |
| 32 | fLight.fSpecular = 16*2; |
| 33 | } |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 34 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 35 | protected: |
Hal Canary | 8a02731 | 2019-07-03 10:55:44 -0400 | [diff] [blame] | 36 | virtual SkString name() { return SkString("Emboss"); } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 37 | |
reed@google.com | 961ddb0 | 2011-05-05 14:03:48 +0000 | [diff] [blame] | 38 | virtual void onDrawContent(SkCanvas* canvas) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 39 | SkPaint paint; |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 40 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 41 | paint.setAntiAlias(true); |
| 42 | paint.setStyle(SkPaint::kStroke_Style); |
| 43 | paint.setStrokeWidth(SkIntToScalar(10)); |
reed | efdfd51 | 2016-04-04 10:02:58 -0700 | [diff] [blame] | 44 | paint.setMaskFilter(SkEmbossMaskFilter::Make(SkBlurMask::ConvertRadiusToSigma(4), fLight)); |
Mike Reed | c8bea7d | 2019-04-09 13:55:36 -0400 | [diff] [blame] | 45 | paint.setShader(SkShaders::Color(SK_ColorBLUE)); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 46 | paint.setDither(true); |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 47 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 48 | canvas->drawCircle(SkIntToScalar(50), SkIntToScalar(50), |
| 49 | SkIntToScalar(30), paint); |
| 50 | } |
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 | private: |
| 53 | |
Ben Wagner | b2c4ea6 | 2018-08-08 11:36:17 -0400 | [diff] [blame] | 54 | typedef Sample INHERITED; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 55 | }; |
| 56 | |
| 57 | ////////////////////////////////////////////////////////////////////////////// |
| 58 | |
Ben Wagner | b2c4ea6 | 2018-08-08 11:36:17 -0400 | [diff] [blame] | 59 | DEF_SAMPLE( return new EmbossView(); ) |