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