blob: 6e33e05e794e2bb65eb968035bf1b0c0f3862538 [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"
reed@android.com8a1c16f2008-12-17 15:59:43 +000016#include "SkPath.h"
17#include "SkRandom.h"
18#include "SkRegion.h"
19#include "SkShader.h"
20#include "SkUtils.h"
reed@android.com8a1c16f2008-12-17 15:59:43 +000021#include "SkColorPriv.h"
22#include "SkColorFilter.h"
23#include "SkTime.h"
24#include "SkTypeface.h"
25#include "SkXfermode.h"
26
reed@google.com961ddb02011-05-05 14:03:48 +000027class EmbossView : public SampleView {
reed@android.com8a1c16f2008-12-17 15:59:43 +000028 SkEmbossMaskFilter::Light fLight;
29public:
rmistry@google.comae933ce2012-08-23 18:19:56 +000030 EmbossView() {
reed@android.com8a1c16f2008-12-17 15:59:43 +000031 fLight.fDirection[0] = SK_Scalar1;
32 fLight.fDirection[1] = SK_Scalar1;
33 fLight.fDirection[2] = SK_Scalar1;
34 fLight.fAmbient = 128;
35 fLight.fSpecular = 16*2;
36 }
rmistry@google.comae933ce2012-08-23 18:19:56 +000037
reed@android.com8a1c16f2008-12-17 15:59:43 +000038protected:
39 // overrides from SkEventSink
reed@google.com961ddb02011-05-05 14:03:48 +000040 virtual bool onQuery(SkEvent* evt) {
41 if (SampleCode::TitleQ(*evt)) {
reed@android.com8a1c16f2008-12-17 15:59:43 +000042 SampleCode::TitleR(evt, "Emboss");
43 return true;
44 }
45 return this->INHERITED::onQuery(evt);
46 }
47
reed@google.com961ddb02011-05-05 14:03:48 +000048 virtual void onDrawContent(SkCanvas* canvas) {
reed@android.com8a1c16f2008-12-17 15:59:43 +000049 SkPaint paint;
rmistry@google.comae933ce2012-08-23 18:19:56 +000050
reed@android.com8a1c16f2008-12-17 15:59:43 +000051 paint.setAntiAlias(true);
52 paint.setStyle(SkPaint::kStroke_Style);
53 paint.setStrokeWidth(SkIntToScalar(10));
commit-bot@chromium.org7c9d0f32014-02-21 10:13:32 +000054 paint.setMaskFilter(SkEmbossMaskFilter::Create(
robertphillips@google.comb7061172013-09-06 14:16:12 +000055 SkBlurMask::ConvertRadiusToSigma(SkIntToScalar(4)), fLight))->unref();
reed@android.com8a1c16f2008-12-17 15:59:43 +000056 paint.setShader(new SkColorShader(SK_ColorBLUE))->unref();
57 paint.setDither(true);
rmistry@google.comae933ce2012-08-23 18:19:56 +000058
reed@android.com8a1c16f2008-12-17 15:59:43 +000059 canvas->drawCircle(SkIntToScalar(50), SkIntToScalar(50),
60 SkIntToScalar(30), paint);
61 }
rmistry@google.comae933ce2012-08-23 18:19:56 +000062
reed@android.com8a1c16f2008-12-17 15:59:43 +000063private:
64
reed@google.com961ddb02011-05-05 14:03:48 +000065 typedef SampleView INHERITED;
reed@android.com8a1c16f2008-12-17 15:59:43 +000066};
67
68//////////////////////////////////////////////////////////////////////////////
69
70static SkView* MyFactory() { return new EmbossView; }
71static SkViewRegister reg(MyFactory);