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#include "SampleCode.h" 8#include "SkBlurMask.h" 9#include "SkBlurMaskFilter.h" 10#include "SkCanvas.h" 11#include "SkColorMatrixFilter.h" 12#include "SkDiscretePathEffect.h" 13#include "SkGradientShader.h" 14#include "SkPaint.h" 15#include "SkView.h" 16 17 18//#define COLOR 0xFFFF8844 19#define COLOR 0xFF888888 20 21static void paint_proc0(SkPaint*) { 22} 23 24static void paint_proc1(SkPaint* paint) { 25 paint->setMaskFilter(SkBlurMaskFilter::Make( 26 kNormal_SkBlurStyle, 27 SkBlurMask::ConvertRadiusToSigma(2))); 28} 29 30static void paint_proc2(SkPaint* paint) { 31#ifdef SK_SUPPORT_LEGACY_EMBOSSMASKFILTER 32 SkScalar dir[3] = { 1, 1, 1}; 33 paint->setMaskFilter( 34 SkBlurMaskFilter::MakeEmboss(SkBlurMask::ConvertRadiusToSigma(1), dir, 0.1f, 0.05f)); 35#endif 36} 37 38static void paint_proc3(SkPaint* paint) { 39 SkColor colors[] = { SK_ColorRED, COLOR, SK_ColorBLUE }; 40 SkPoint pts[] = { { 3, 0 }, { 7, 5 } }; 41 paint->setShader(SkGradientShader::MakeLinear(pts, colors, nullptr, SK_ARRAY_COUNT(colors), 42 SkShader::kMirror_TileMode)); 43} 44 45static void paint_proc5(SkPaint* paint) { 46 paint_proc3(paint); 47 paint_proc2(paint); 48} 49 50typedef void (*PaintProc)(SkPaint*); 51const PaintProc gPaintProcs[] = { 52 paint_proc0, 53 paint_proc1, 54 paint_proc2, 55 paint_proc3, 56 paint_proc5, 57}; 58 59/////////////////////////////////////////////////////////////////////////////// 60 61class EffectsView : public SampleView { 62public: 63 SkPath fPath; 64 SkPaint fPaint[SK_ARRAY_COUNT(gPaintProcs)]; 65 66 EffectsView() { 67 size_t i; 68 const float pts[] = { 69 0, 0, 70 10, 0, 71 10, 5, 72 20, -5, 73 10, -15, 74 10, -10, 75 0, -10 76 }; 77 fPath.moveTo(pts[0], pts[1]); 78 for (i = 2; i < SK_ARRAY_COUNT(pts); i += 2) { 79 fPath.lineTo(pts[i], pts[i+1]); 80 } 81 82 for (i = 0; i < SK_ARRAY_COUNT(gPaintProcs); i++) { 83 fPaint[i].setAntiAlias(true); 84 fPaint[i].setColor(COLOR); 85 gPaintProcs[i](&fPaint[i]); 86 } 87 88 SkColorMatrix cm; 89 cm.setRotate(SkColorMatrix::kG_Axis, 180); 90 cm.setIdentity(); 91 92 this->setBGColor(0xFFDDDDDD); 93 } 94 95protected: 96 // overrides from SkEventSink 97 virtual bool onQuery(SkEvent* evt) { 98 if (SampleCode::TitleQ(*evt)) { 99 SampleCode::TitleR(evt, "Effects"); 100 return true; 101 } 102 return this->INHERITED::onQuery(evt); 103 } 104 105 virtual void onDrawContent(SkCanvas* canvas) { 106 canvas->scale(3, 3); 107 canvas->translate(10, 30); 108 for (size_t i = 0; i < SK_ARRAY_COUNT(fPaint); i++) { 109 canvas->drawPath(fPath, fPaint[i]); 110 canvas->translate(32, 0); 111 } 112 } 113 114private: 115 typedef SampleView INHERITED; 116}; 117 118/////////////////////////////////////////////////////////////////////////////// 119 120static SkView* MyFactory() { return new EffectsView; } 121static SkViewRegister reg(MyFactory); 122