blob: cdc8b4742267a4d5050bd3dae58ee624058b2855 [file] [log] [blame]
reed@android.com8a1c16f2008-12-17 15:59:43 +00001#include "SampleCode.h"
2#include "SkView.h"
3#include "SkCanvas.h"
4#include "Sk64.h"
5#include "SkColorShader.h"
6#include "SkEmbossMaskFilter.h"
7#include "SkGradientShader.h"
8#include "SkGraphics.h"
9#include "SkImageDecoder.h"
10#include "SkKernel33MaskFilter.h"
11#include "SkPath.h"
12#include "SkRandom.h"
13#include "SkRegion.h"
14#include "SkShader.h"
15#include "SkUtils.h"
16#include "SkShaderExtras.h"
17#include "SkColorPriv.h"
18#include "SkColorFilter.h"
19#include "SkTime.h"
20#include "SkTypeface.h"
21#include "SkXfermode.h"
22
23class EmbossView : public SkView {
24 SkEmbossMaskFilter::Light fLight;
25public:
26 EmbossView()
27 {
28 fLight.fDirection[0] = SK_Scalar1;
29 fLight.fDirection[1] = SK_Scalar1;
30 fLight.fDirection[2] = SK_Scalar1;
31 fLight.fAmbient = 128;
32 fLight.fSpecular = 16*2;
33 }
34
35protected:
36 // overrides from SkEventSink
37 virtual bool onQuery(SkEvent* evt)
38 {
39 if (SampleCode::TitleQ(*evt))
40 {
41 SampleCode::TitleR(evt, "Emboss");
42 return true;
43 }
44 return this->INHERITED::onQuery(evt);
45 }
46
47 void drawBG(SkCanvas* canvas)
48 {
49 canvas->drawColor(SK_ColorWHITE);
50 }
51
52 virtual void onDraw(SkCanvas* canvas)
53 {
54 this->drawBG(canvas);
55
56 SkPaint paint;
57
58 paint.setAntiAlias(true);
59 paint.setStyle(SkPaint::kStroke_Style);
60 paint.setStrokeWidth(SkIntToScalar(10));
61 paint.setMaskFilter(new SkEmbossMaskFilter(fLight, SkIntToScalar(4)))->unref();
62 paint.setShader(new SkColorShader(SK_ColorBLUE))->unref();
63 paint.setDither(true);
64
65 canvas->drawCircle(SkIntToScalar(50), SkIntToScalar(50),
66 SkIntToScalar(30), paint);
67 }
68
69private:
70
71 typedef SkView INHERITED;
72};
73
74//////////////////////////////////////////////////////////////////////////////
75
76static SkView* MyFactory() { return new EmbossView; }
77static SkViewRegister reg(MyFactory);
78