blob: f219cdda245b2fc20659c3d247c9fd9dee5081d5 [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"
reed@android.com8a1c16f2008-12-17 15:59:43 +000017#include "SkPath.h"
18#include "SkRandom.h"
19#include "SkRegion.h"
20#include "SkShader.h"
21#include "SkUtils.h"
reed@android.com8a1c16f2008-12-17 15:59:43 +000022#include "SkColorPriv.h"
23#include "SkColorFilter.h"
24#include "SkTime.h"
25#include "SkTypeface.h"
26#include "SkXfermode.h"
27
reed@google.com961ddb02011-05-05 14:03:48 +000028class EmbossView : public SampleView {
reed@android.com8a1c16f2008-12-17 15:59:43 +000029 SkEmbossMaskFilter::Light fLight;
30public:
rmistry@google.comae933ce2012-08-23 18:19:56 +000031 EmbossView() {
reed@android.com8a1c16f2008-12-17 15:59:43 +000032 fLight.fDirection[0] = SK_Scalar1;
33 fLight.fDirection[1] = SK_Scalar1;
34 fLight.fDirection[2] = SK_Scalar1;
35 fLight.fAmbient = 128;
36 fLight.fSpecular = 16*2;
37 }
rmistry@google.comae933ce2012-08-23 18:19:56 +000038
reed@android.com8a1c16f2008-12-17 15:59:43 +000039protected:
40 // overrides from SkEventSink
reed@google.com961ddb02011-05-05 14:03:48 +000041 virtual bool onQuery(SkEvent* evt) {
42 if (SampleCode::TitleQ(*evt)) {
reed@android.com8a1c16f2008-12-17 15:59:43 +000043 SampleCode::TitleR(evt, "Emboss");
44 return true;
45 }
46 return this->INHERITED::onQuery(evt);
47 }
48
reed@google.com961ddb02011-05-05 14:03:48 +000049 virtual void onDrawContent(SkCanvas* canvas) {
reed@android.com8a1c16f2008-12-17 15:59:43 +000050 SkPaint paint;
rmistry@google.comae933ce2012-08-23 18:19:56 +000051
reed@android.com8a1c16f2008-12-17 15:59:43 +000052 paint.setAntiAlias(true);
53 paint.setStyle(SkPaint::kStroke_Style);
54 paint.setStrokeWidth(SkIntToScalar(10));
commit-bot@chromium.org7c9d0f32014-02-21 10:13:32 +000055 paint.setMaskFilter(SkEmbossMaskFilter::Create(
robertphillips@google.comb7061172013-09-06 14:16:12 +000056 SkBlurMask::ConvertRadiusToSigma(SkIntToScalar(4)), fLight))->unref();
reed@android.com8a1c16f2008-12-17 15:59:43 +000057 paint.setShader(new SkColorShader(SK_ColorBLUE))->unref();
58 paint.setDither(true);
rmistry@google.comae933ce2012-08-23 18:19:56 +000059
reed@android.com8a1c16f2008-12-17 15:59:43 +000060 canvas->drawCircle(SkIntToScalar(50), SkIntToScalar(50),
61 SkIntToScalar(30), paint);
62 }
rmistry@google.comae933ce2012-08-23 18:19:56 +000063
reed@android.com8a1c16f2008-12-17 15:59:43 +000064private:
65
reed@google.com961ddb02011-05-05 14:03:48 +000066 typedef SampleView INHERITED;
reed@android.com8a1c16f2008-12-17 15:59:43 +000067};
68
69//////////////////////////////////////////////////////////////////////////////
70
71static SkView* MyFactory() { return new EmbossView; }
72static SkViewRegister reg(MyFactory);