blob: b9bb691d329e9be8eaf98dc06b4e623419ef5d74 [file] [log] [blame]
epoger@google.comec3ed6a2011-07-28 14:26:00 +00001
2/*
3 * Copyright 2011 Google Inc.
4 *
5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
7 */
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"
12#include "Sk64.h"
13#include "SkColorShader.h"
14#include "SkEmbossMaskFilter.h"
15#include "SkGradientShader.h"
16#include "SkGraphics.h"
17#include "SkImageDecoder.h"
18#include "SkKernel33MaskFilter.h"
19#include "SkPath.h"
20#include "SkRandom.h"
21#include "SkRegion.h"
22#include "SkShader.h"
23#include "SkUtils.h"
reed@android.com8a1c16f2008-12-17 15:59:43 +000024#include "SkColorPriv.h"
25#include "SkColorFilter.h"
26#include "SkTime.h"
27#include "SkTypeface.h"
28#include "SkXfermode.h"
29
reed@google.com961ddb02011-05-05 14:03:48 +000030class EmbossView : public SampleView {
reed@android.com8a1c16f2008-12-17 15:59:43 +000031 SkEmbossMaskFilter::Light fLight;
32public:
rmistry@google.comae933ce2012-08-23 18:19:56 +000033 EmbossView() {
reed@android.com8a1c16f2008-12-17 15:59:43 +000034 fLight.fDirection[0] = SK_Scalar1;
35 fLight.fDirection[1] = SK_Scalar1;
36 fLight.fDirection[2] = SK_Scalar1;
37 fLight.fAmbient = 128;
38 fLight.fSpecular = 16*2;
39 }
rmistry@google.comae933ce2012-08-23 18:19:56 +000040
reed@android.com8a1c16f2008-12-17 15:59:43 +000041protected:
42 // overrides from SkEventSink
reed@google.com961ddb02011-05-05 14:03:48 +000043 virtual bool onQuery(SkEvent* evt) {
44 if (SampleCode::TitleQ(*evt)) {
reed@android.com8a1c16f2008-12-17 15:59:43 +000045 SampleCode::TitleR(evt, "Emboss");
46 return true;
47 }
48 return this->INHERITED::onQuery(evt);
49 }
50
reed@google.com961ddb02011-05-05 14:03:48 +000051 virtual void onDrawContent(SkCanvas* canvas) {
reed@android.com8a1c16f2008-12-17 15:59:43 +000052 SkPaint paint;
rmistry@google.comae933ce2012-08-23 18:19:56 +000053
reed@android.com8a1c16f2008-12-17 15:59:43 +000054 paint.setAntiAlias(true);
55 paint.setStyle(SkPaint::kStroke_Style);
56 paint.setStrokeWidth(SkIntToScalar(10));
robertphillips@google.comb7061172013-09-06 14:16:12 +000057 paint.setMaskFilter(new SkEmbossMaskFilter(
58 SkBlurMask::ConvertRadiusToSigma(SkIntToScalar(4)), fLight))->unref();
reed@android.com8a1c16f2008-12-17 15:59:43 +000059 paint.setShader(new SkColorShader(SK_ColorBLUE))->unref();
60 paint.setDither(true);
rmistry@google.comae933ce2012-08-23 18:19:56 +000061
reed@android.com8a1c16f2008-12-17 15:59:43 +000062 canvas->drawCircle(SkIntToScalar(50), SkIntToScalar(50),
63 SkIntToScalar(30), paint);
64 }
rmistry@google.comae933ce2012-08-23 18:19:56 +000065
reed@android.com8a1c16f2008-12-17 15:59:43 +000066private:
67
reed@google.com961ddb02011-05-05 14:03:48 +000068 typedef SampleView INHERITED;
reed@android.com8a1c16f2008-12-17 15:59:43 +000069};
70
71//////////////////////////////////////////////////////////////////////////////
72
73static SkView* MyFactory() { return new EmbossView; }
74static SkViewRegister reg(MyFactory);