blob: 1810a09f767c48d66d20f97ea405d7f0f39de8d4 [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 "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.com8a1c16f2008-12-17 15:59:43 +000023#include "SkColorPriv.h"
24#include "SkColorFilter.h"
25#include "SkTime.h"
26#include "SkTypeface.h"
27#include "SkXfermode.h"
28
reed@google.com961ddb02011-05-05 14:03:48 +000029class EmbossView : public SampleView {
reed@android.com8a1c16f2008-12-17 15:59:43 +000030 SkEmbossMaskFilter::Light fLight;
31public:
rmistry@google.comae933ce2012-08-23 18:19:56 +000032 EmbossView() {
reed@android.com8a1c16f2008-12-17 15:59:43 +000033 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.comae933ce2012-08-23 18:19:56 +000039
reed@android.com8a1c16f2008-12-17 15:59:43 +000040protected:
41 // overrides from SkEventSink
reed@google.com961ddb02011-05-05 14:03:48 +000042 virtual bool onQuery(SkEvent* evt) {
43 if (SampleCode::TitleQ(*evt)) {
reed@android.com8a1c16f2008-12-17 15:59:43 +000044 SampleCode::TitleR(evt, "Emboss");
45 return true;
46 }
47 return this->INHERITED::onQuery(evt);
48 }
49
reed@google.com961ddb02011-05-05 14:03:48 +000050 virtual void onDrawContent(SkCanvas* canvas) {
reed@android.com8a1c16f2008-12-17 15:59:43 +000051 SkPaint paint;
rmistry@google.comae933ce2012-08-23 18:19:56 +000052
reed@android.com8a1c16f2008-12-17 15:59:43 +000053 paint.setAntiAlias(true);
54 paint.setStyle(SkPaint::kStroke_Style);
55 paint.setStrokeWidth(SkIntToScalar(10));
commit-bot@chromium.org7c9d0f32014-02-21 10:13:32 +000056 paint.setMaskFilter(SkEmbossMaskFilter::Create(
robertphillips@google.comb7061172013-09-06 14:16:12 +000057 SkBlurMask::ConvertRadiusToSigma(SkIntToScalar(4)), fLight))->unref();
reed@android.com8a1c16f2008-12-17 15:59:43 +000058 paint.setShader(new SkColorShader(SK_ColorBLUE))->unref();
59 paint.setDither(true);
rmistry@google.comae933ce2012-08-23 18:19:56 +000060
reed@android.com8a1c16f2008-12-17 15:59:43 +000061 canvas->drawCircle(SkIntToScalar(50), SkIntToScalar(50),
62 SkIntToScalar(30), paint);
63 }
rmistry@google.comae933ce2012-08-23 18:19:56 +000064
reed@android.com8a1c16f2008-12-17 15:59:43 +000065private:
66
reed@google.com961ddb02011-05-05 14:03:48 +000067 typedef SampleView INHERITED;
reed@android.com8a1c16f2008-12-17 15:59:43 +000068};
69
70//////////////////////////////////////////////////////////////////////////////
71
72static SkView* MyFactory() { return new EmbossView; }
73static SkViewRegister reg(MyFactory);