blob: 0217d9e75eaae184d0e22f37555d1f98d24e7d0e [file] [log] [blame]
epoger@google.comec3ed6a2011-07-28 14:26:00 +00001/*
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.combf0001d2014-01-13 14:53:55 +00007
Ben Wagnerb2c4ea62018-08-08 11:36:17 -04008#include "Sample.h"
robertphillips@google.comb7061172013-09-06 14:16:12 +00009#include "SkBlurMask.h"
reed@android.com8a1c16f2008-12-17 15:59:43 +000010#include "SkCanvas.h"
reed@android.com8a1c16f2008-12-17 15:59:43 +000011#include "SkEmbossMaskFilter.h"
12#include "SkGradientShader.h"
13#include "SkGraphics.h"
reed@android.com8a1c16f2008-12-17 15:59:43 +000014#include "SkPath.h"
15#include "SkRandom.h"
16#include "SkRegion.h"
17#include "SkShader.h"
Hal Canaryea60b952018-08-21 11:45:46 -040018#include "SkUTF.h"
reed@android.com8a1c16f2008-12-17 15:59:43 +000019#include "SkColorPriv.h"
20#include "SkColorFilter.h"
21#include "SkTime.h"
22#include "SkTypeface.h"
reed@android.com8a1c16f2008-12-17 15:59:43 +000023
Ben Wagnerb2c4ea62018-08-08 11:36:17 -040024class EmbossView : public Sample {
reed@android.com8a1c16f2008-12-17 15:59:43 +000025 SkEmbossMaskFilter::Light fLight;
26public:
rmistry@google.comae933ce2012-08-23 18:19:56 +000027 EmbossView() {
reed@android.com8a1c16f2008-12-17 15:59:43 +000028 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.comae933ce2012-08-23 18:19:56 +000034
reed@android.com8a1c16f2008-12-17 15:59:43 +000035protected:
Ben Wagnerb2c4ea62018-08-08 11:36:17 -040036 virtual bool onQuery(Sample::Event* evt) {
37 if (Sample::TitleQ(*evt)) {
38 Sample::TitleR(evt, "Emboss");
reed@android.com8a1c16f2008-12-17 15:59:43 +000039 return true;
40 }
41 return this->INHERITED::onQuery(evt);
42 }
43
reed@google.com961ddb02011-05-05 14:03:48 +000044 virtual void onDrawContent(SkCanvas* canvas) {
reed@android.com8a1c16f2008-12-17 15:59:43 +000045 SkPaint paint;
rmistry@google.comae933ce2012-08-23 18:19:56 +000046
reed@android.com8a1c16f2008-12-17 15:59:43 +000047 paint.setAntiAlias(true);
48 paint.setStyle(SkPaint::kStroke_Style);
49 paint.setStrokeWidth(SkIntToScalar(10));
reedefdfd512016-04-04 10:02:58 -070050 paint.setMaskFilter(SkEmbossMaskFilter::Make(SkBlurMask::ConvertRadiusToSigma(4), fLight));
reedfe630452016-03-25 09:08:00 -070051 paint.setShader(SkShader::MakeColorShader(SK_ColorBLUE));
reed@android.com8a1c16f2008-12-17 15:59:43 +000052 paint.setDither(true);
rmistry@google.comae933ce2012-08-23 18:19:56 +000053
reed@android.com8a1c16f2008-12-17 15:59:43 +000054 canvas->drawCircle(SkIntToScalar(50), SkIntToScalar(50),
55 SkIntToScalar(30), paint);
56 }
rmistry@google.comae933ce2012-08-23 18:19:56 +000057
reed@android.com8a1c16f2008-12-17 15:59:43 +000058private:
59
Ben Wagnerb2c4ea62018-08-08 11:36:17 -040060 typedef Sample INHERITED;
reed@android.com8a1c16f2008-12-17 15:59:43 +000061};
62
63//////////////////////////////////////////////////////////////////////////////
64
Ben Wagnerb2c4ea62018-08-08 11:36:17 -040065DEF_SAMPLE( return new EmbossView(); )