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