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 "Sample.h" 9 #include "SkBlurMask.h" 10 #include "SkCanvas.h" 11 #include "SkEmbossMaskFilter.h" 12 #include "SkGradientShader.h" 13 #include "SkGraphics.h" 14 #include "SkPath.h" 15 #include "SkRandom.h" 16 #include "SkRegion.h" 17 #include "SkShader.h" 18 #include "SkUTF.h" 19 #include "SkColorPriv.h" 20 #include "SkColorFilter.h" 21 #include "SkTime.h" 22 #include "SkTypeface.h" 23 24 class EmbossView : public Sample { 25 SkEmbossMaskFilter::Light fLight; 26 public: 27 EmbossView() { 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 35 protected: 36 virtual bool onQuery(Sample::Event* evt) { 37 if (Sample::TitleQ(*evt)) { 38 Sample::TitleR(evt, "Emboss"); 39 return true; 40 } 41 return this->INHERITED::onQuery(evt); 42 } 43 44 virtual void onDrawContent(SkCanvas* canvas) { 45 SkPaint paint; 46 47 paint.setAntiAlias(true); 48 paint.setStyle(SkPaint::kStroke_Style); 49 paint.setStrokeWidth(SkIntToScalar(10)); 50 paint.setMaskFilter(SkEmbossMaskFilter::Make(SkBlurMask::ConvertRadiusToSigma(4), fLight)); 51 paint.setShader(SkShader::MakeColorShader(SK_ColorBLUE)); 52 paint.setDither(true); 53 54 canvas->drawCircle(SkIntToScalar(50), SkIntToScalar(50), 55 SkIntToScalar(30), paint); 56 } 57 58 private: 59 60 typedef Sample INHERITED; 61 }; 62 63 ////////////////////////////////////////////////////////////////////////////// 64 65 DEF_SAMPLE( return new EmbossView(); ) 66