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