SampleEmboss.cpp revision 7c9d0f3104408a64d52b84643f116179022d73bd
1/*
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 */
7
8#include "SampleCode.h"
9#include "SkBlurMask.h"
10#include "SkView.h"
11#include "SkCanvas.h"
12#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"
23#include "SkColorPriv.h"
24#include "SkColorFilter.h"
25#include "SkTime.h"
26#include "SkTypeface.h"
27#include "SkXfermode.h"
28
29class EmbossView : public SampleView {
30    SkEmbossMaskFilter::Light   fLight;
31public:
32    EmbossView() {
33        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    }
39
40protected:
41    // overrides from SkEventSink
42    virtual bool onQuery(SkEvent* evt) {
43        if (SampleCode::TitleQ(*evt)) {
44            SampleCode::TitleR(evt, "Emboss");
45            return true;
46        }
47        return this->INHERITED::onQuery(evt);
48    }
49
50    virtual void onDrawContent(SkCanvas* canvas) {
51        SkPaint paint;
52
53        paint.setAntiAlias(true);
54        paint.setStyle(SkPaint::kStroke_Style);
55        paint.setStrokeWidth(SkIntToScalar(10));
56        paint.setMaskFilter(SkEmbossMaskFilter::Create(
57            SkBlurMask::ConvertRadiusToSigma(SkIntToScalar(4)), fLight))->unref();
58        paint.setShader(new SkColorShader(SK_ColorBLUE))->unref();
59        paint.setDither(true);
60
61        canvas->drawCircle(SkIntToScalar(50), SkIntToScalar(50),
62                           SkIntToScalar(30), paint);
63    }
64
65private:
66
67    typedef SampleView INHERITED;
68};
69
70//////////////////////////////////////////////////////////////////////////////
71
72static SkView* MyFactory() { return new EmbossView; }
73static SkViewRegister reg(MyFactory);
74