blob: 3ac15d878fadf6a1bff8f50e1dca57854c46aecb [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
Mike Kleinc0bd9f92019-04-23 12:05:21 -05008#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.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));
Mike Reedc8bea7d2019-04-09 13:55:36 -040051 paint.setShader(SkShaders::Color(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(); )