blob: 4aba6fd15751d0b51baa6e08e09f786145e00b09 [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
reed@android.com8a1c16f2008-12-17 15:59:43 +00008#include "SampleCode.h"
robertphillips@google.comb7061172013-09-06 14:16:12 +00009#include "SkBlurMask.h"
reed@android.com8a1c16f2008-12-17 15:59:43 +000010#include "SkView.h"
11#include "SkCanvas.h"
reed@android.com8a1c16f2008-12-17 15:59:43 +000012#include "SkEmbossMaskFilter.h"
13#include "SkGradientShader.h"
14#include "SkGraphics.h"
reed@android.com8a1c16f2008-12-17 15:59:43 +000015#include "SkPath.h"
16#include "SkRandom.h"
17#include "SkRegion.h"
18#include "SkShader.h"
19#include "SkUtils.h"
reed@android.com8a1c16f2008-12-17 15:59:43 +000020#include "SkColorPriv.h"
21#include "SkColorFilter.h"
22#include "SkTime.h"
23#include "SkTypeface.h"
reed@android.com8a1c16f2008-12-17 15:59:43 +000024
reed@google.com961ddb02011-05-05 14:03:48 +000025class EmbossView : public SampleView {
reed@android.com8a1c16f2008-12-17 15:59:43 +000026 SkEmbossMaskFilter::Light fLight;
27public:
rmistry@google.comae933ce2012-08-23 18:19:56 +000028 EmbossView() {
reed@android.com8a1c16f2008-12-17 15:59:43 +000029 fLight.fDirection[0] = SK_Scalar1;
30 fLight.fDirection[1] = SK_Scalar1;
31 fLight.fDirection[2] = SK_Scalar1;
32 fLight.fAmbient = 128;
33 fLight.fSpecular = 16*2;
34 }
rmistry@google.comae933ce2012-08-23 18:19:56 +000035
reed@android.com8a1c16f2008-12-17 15:59:43 +000036protected:
37 // overrides from SkEventSink
reed@google.com961ddb02011-05-05 14:03:48 +000038 virtual bool onQuery(SkEvent* evt) {
39 if (SampleCode::TitleQ(*evt)) {
reed@android.com8a1c16f2008-12-17 15:59:43 +000040 SampleCode::TitleR(evt, "Emboss");
41 return true;
42 }
43 return this->INHERITED::onQuery(evt);
44 }
45
reed@google.com961ddb02011-05-05 14:03:48 +000046 virtual void onDrawContent(SkCanvas* canvas) {
reed@android.com8a1c16f2008-12-17 15:59:43 +000047 SkPaint paint;
rmistry@google.comae933ce2012-08-23 18:19:56 +000048
reed@android.com8a1c16f2008-12-17 15:59:43 +000049 paint.setAntiAlias(true);
50 paint.setStyle(SkPaint::kStroke_Style);
51 paint.setStrokeWidth(SkIntToScalar(10));
reedefdfd512016-04-04 10:02:58 -070052 paint.setMaskFilter(SkEmbossMaskFilter::Make(SkBlurMask::ConvertRadiusToSigma(4), fLight));
reedfe630452016-03-25 09:08:00 -070053 paint.setShader(SkShader::MakeColorShader(SK_ColorBLUE));
reed@android.com8a1c16f2008-12-17 15:59:43 +000054 paint.setDither(true);
rmistry@google.comae933ce2012-08-23 18:19:56 +000055
reed@android.com8a1c16f2008-12-17 15:59:43 +000056 canvas->drawCircle(SkIntToScalar(50), SkIntToScalar(50),
57 SkIntToScalar(30), paint);
58 }
rmistry@google.comae933ce2012-08-23 18:19:56 +000059
reed@android.com8a1c16f2008-12-17 15:59:43 +000060private:
61
reed@google.com961ddb02011-05-05 14:03:48 +000062 typedef SampleView INHERITED;
reed@android.com8a1c16f2008-12-17 15:59:43 +000063};
64
65//////////////////////////////////////////////////////////////////////////////
66
67static SkView* MyFactory() { return new EmbossView; }
68static SkViewRegister reg(MyFactory);