• Home
  • History
  • Annotate
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "SkEmbossMaskFilter.h"
13 #include "SkGradientShader.h"
14 #include "SkGraphics.h"
15 #include "SkPath.h"
16 #include "SkRandom.h"
17 #include "SkRegion.h"
18 #include "SkShader.h"
19 #include "SkUtils.h"
20 #include "SkColorPriv.h"
21 #include "SkColorFilter.h"
22 #include "SkTime.h"
23 #include "SkTypeface.h"
24 
25 class EmbossView : public SampleView {
26     SkEmbossMaskFilter::Light   fLight;
27 public:
EmbossView()28     EmbossView() {
29         fLight.fDirection[0] = SK_Scalar1;
30         fLight.fDirection[1] = SK_Scalar1;
31         fLight.fDirection[2] = SK_Scalar1;
32         fLight.fAmbient = 128;
33         fLight.fSpecular = 16*2;
34     }
35 
36 protected:
37     // overrides from SkEventSink
onQuery(SkEvent * evt)38     virtual bool onQuery(SkEvent* evt) {
39         if (SampleCode::TitleQ(*evt)) {
40             SampleCode::TitleR(evt, "Emboss");
41             return true;
42         }
43         return this->INHERITED::onQuery(evt);
44     }
45 
onDrawContent(SkCanvas * canvas)46     virtual void onDrawContent(SkCanvas* canvas) {
47         SkPaint paint;
48 
49         paint.setAntiAlias(true);
50         paint.setStyle(SkPaint::kStroke_Style);
51         paint.setStrokeWidth(SkIntToScalar(10));
52         paint.setMaskFilter(SkEmbossMaskFilter::Make(SkBlurMask::ConvertRadiusToSigma(4), fLight));
53         paint.setShader(SkShader::MakeColorShader(SK_ColorBLUE));
54         paint.setDither(true);
55 
56         canvas->drawCircle(SkIntToScalar(50), SkIntToScalar(50),
57                            SkIntToScalar(30), paint);
58     }
59 
60 private:
61 
62     typedef SampleView INHERITED;
63 };
64 
65 //////////////////////////////////////////////////////////////////////////////
66 
MyFactory()67 static SkView* MyFactory() { return new EmbossView; }
68 static SkViewRegister reg(MyFactory);
69