blob: f1ea1fe547c790e3cf4acc732250fa02b7e5506a [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"
24#include "SkXfermode.h"
25
reed@google.com961ddb02011-05-05 14:03:48 +000026class EmbossView : public SampleView {
reed@android.com8a1c16f2008-12-17 15:59:43 +000027 SkEmbossMaskFilter::Light fLight;
28public:
rmistry@google.comae933ce2012-08-23 18:19:56 +000029 EmbossView() {
reed@android.com8a1c16f2008-12-17 15:59:43 +000030 fLight.fDirection[0] = SK_Scalar1;
31 fLight.fDirection[1] = SK_Scalar1;
32 fLight.fDirection[2] = SK_Scalar1;
33 fLight.fAmbient = 128;
34 fLight.fSpecular = 16*2;
35 }
rmistry@google.comae933ce2012-08-23 18:19:56 +000036
reed@android.com8a1c16f2008-12-17 15:59:43 +000037protected:
38 // overrides from SkEventSink
reed@google.com961ddb02011-05-05 14:03:48 +000039 virtual bool onQuery(SkEvent* evt) {
40 if (SampleCode::TitleQ(*evt)) {
reed@android.com8a1c16f2008-12-17 15:59:43 +000041 SampleCode::TitleR(evt, "Emboss");
42 return true;
43 }
44 return this->INHERITED::onQuery(evt);
45 }
46
reed@google.com961ddb02011-05-05 14:03:48 +000047 virtual void onDrawContent(SkCanvas* canvas) {
reed@android.com8a1c16f2008-12-17 15:59:43 +000048 SkPaint paint;
rmistry@google.comae933ce2012-08-23 18:19:56 +000049
reed@android.com8a1c16f2008-12-17 15:59:43 +000050 paint.setAntiAlias(true);
51 paint.setStyle(SkPaint::kStroke_Style);
52 paint.setStrokeWidth(SkIntToScalar(10));
reedefdfd512016-04-04 10:02:58 -070053 paint.setMaskFilter(SkEmbossMaskFilter::Make(SkBlurMask::ConvertRadiusToSigma(4), fLight));
reedfe630452016-03-25 09:08:00 -070054 paint.setShader(SkShader::MakeColorShader(SK_ColorBLUE));
reed@android.com8a1c16f2008-12-17 15:59:43 +000055 paint.setDither(true);
rmistry@google.comae933ce2012-08-23 18:19:56 +000056
reed@android.com8a1c16f2008-12-17 15:59:43 +000057 canvas->drawCircle(SkIntToScalar(50), SkIntToScalar(50),
58 SkIntToScalar(30), paint);
59 }
rmistry@google.comae933ce2012-08-23 18:19:56 +000060
reed@android.com8a1c16f2008-12-17 15:59:43 +000061private:
62
reed@google.com961ddb02011-05-05 14:03:48 +000063 typedef SampleView INHERITED;
reed@android.com8a1c16f2008-12-17 15:59:43 +000064};
65
66//////////////////////////////////////////////////////////////////////////////
67
68static SkView* MyFactory() { return new EmbossView; }
69static SkViewRegister reg(MyFactory);