reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1 | #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.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 16 | #include "SkColorPriv.h" |
| 17 | #include "SkColorFilter.h" |
| 18 | #include "SkTime.h" |
| 19 | #include "SkTypeface.h" |
| 20 | #include "SkXfermode.h" |
| 21 | |
| 22 | class EmbossView : public SkView { |
| 23 | SkEmbossMaskFilter::Light fLight; |
| 24 | public: |
| 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 | |
| 34 | protected: |
| 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 | |
| 68 | private: |
| 69 | |
| 70 | typedef SkView INHERITED; |
| 71 | }; |
| 72 | |
| 73 | ////////////////////////////////////////////////////////////////////////////// |
| 74 | |
| 75 | static SkView* MyFactory() { return new EmbossView; } |
| 76 | static SkViewRegister reg(MyFactory); |
| 77 | |