Sk1DPathEffect.h revision 6806fe87e0b39e283291c1a1c7d1d864230aa2aa
1/* 2 * Copyright 2006 The Android Open Source Project 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#ifndef Sk1DPathEffect_DEFINED 9#define Sk1DPathEffect_DEFINED 10 11#include "SkPathEffect.h" 12#include "SkPath.h" 13 14class SkPathMeasure; 15 16// This class is not exported to java. 17class SK_API Sk1DPathEffect : public SkPathEffect { 18public: 19 virtual bool filterPath(SkPath* dst, const SkPath& src, SkStrokeRec*) SK_OVERRIDE; 20 21protected: 22 /** Called at the start of each contour, returns the initial offset 23 into that contour. 24 */ 25 virtual SkScalar begin(SkScalar contourLength) = 0; 26 /** Called with the current distance along the path, with the current matrix 27 for the point/tangent at the specified distance. 28 Return the distance to travel for the next call. If return <= 0, then that 29 contour is done. 30 */ 31 virtual SkScalar next(SkPath* dst, SkScalar distance, SkPathMeasure&) = 0; 32 33private: 34 typedef SkPathEffect INHERITED; 35}; 36 37class SK_API SkPath1DPathEffect : public Sk1DPathEffect { 38public: 39 enum Style { 40 kTranslate_Style, // translate the shape to each position 41 kRotate_Style, // rotate the shape about its center 42 kMorph_Style, // transform each point, and turn lines into curves 43 44 kStyleCount 45 }; 46 47 /** Dash by replicating the specified path. 48 @param path The path to replicate (dash) 49 @param advance The space between instances of path 50 @param phase distance (mod advance) along path for its initial position 51 @param style how to transform path at each point (based on the current 52 position and tangent) 53 */ 54 SkPath1DPathEffect(const SkPath& path, SkScalar advance, SkScalar phase, Style); 55 56 virtual bool filterPath(SkPath*, const SkPath&, SkStrokeRec*) SK_OVERRIDE; 57 58 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkPath1DPathEffect) 59 60protected: 61 SkPath1DPathEffect(SkFlattenableReadBuffer& buffer); 62 virtual void flatten(SkFlattenableWriteBuffer&) const SK_OVERRIDE; 63 64 // overrides from Sk1DPathEffect 65 virtual SkScalar begin(SkScalar contourLength) SK_OVERRIDE; 66 virtual SkScalar next(SkPath*, SkScalar distance, SkPathMeasure&) SK_OVERRIDE; 67 68private: 69 SkPath fPath; // copied from constructor 70 SkScalar fAdvance; // copied from constructor 71 SkScalar fInitialOffset; // computed from phase 72 Style fStyle; // copied from constructor 73 74 typedef Sk1DPathEffect INHERITED; 75}; 76 77#endif 78