epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 1 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 2 | /* |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 3 | * Copyright 2006 The Android Open Source Project |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 4 | * |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 5 | * Use of this source code is governed by a BSD-style license that can be |
| 6 | * found in the LICENSE file. |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 7 | */ |
| 8 | |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 9 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 10 | #ifndef Sk1DPathEffect_DEFINED |
| 11 | #define Sk1DPathEffect_DEFINED |
| 12 | |
| 13 | #include "SkPathEffect.h" |
| 14 | #include "SkPath.h" |
| 15 | |
| 16 | class SkPathMeasure; |
| 17 | |
| 18 | // This class is not exported to java. |
| 19 | class Sk1DPathEffect : public SkPathEffect { |
| 20 | public: |
| 21 | // override from SkPathEffect |
| 22 | virtual bool filterPath(SkPath* dst, const SkPath& src, SkScalar* width); |
| 23 | |
| 24 | protected: |
| 25 | /** Called at the start of each contour, returns the initial offset |
| 26 | into that contour. |
| 27 | */ |
| 28 | virtual SkScalar begin(SkScalar contourLength) = 0; |
| 29 | /** Called with the current distance along the path, with the current matrix |
| 30 | for the point/tangent at the specified distance. |
| 31 | Return the distance to travel for the next call. If return <= 0, then that |
| 32 | contour is done. |
| 33 | */ |
| 34 | virtual SkScalar next(SkPath* dst, SkScalar distance, SkPathMeasure&) = 0; |
| 35 | |
| 36 | private: |
| 37 | typedef SkPathEffect INHERITED; |
| 38 | }; |
| 39 | |
| 40 | class SkPath1DPathEffect : public Sk1DPathEffect { |
| 41 | public: |
| 42 | enum Style { |
| 43 | kTranslate_Style, // translate the shape to each position |
| 44 | kRotate_Style, // rotate the shape about its center |
| 45 | kMorph_Style, // transform each point, and turn lines into curves |
| 46 | |
| 47 | kStyleCount |
| 48 | }; |
| 49 | |
| 50 | /** Dash by replicating the specified path. |
| 51 | @param path The path to replicate (dash) |
| 52 | @param advance The space between instances of path |
| 53 | @param phase distance (mod advance) along path for its initial position |
| 54 | @param style how to transform path at each point (based on the current |
| 55 | position and tangent) |
| 56 | */ |
| 57 | SkPath1DPathEffect(const SkPath& path, SkScalar advance, SkScalar phase, Style); |
| 58 | |
| 59 | // override from SkPathEffect |
mike@reedtribe.org | 259210c | 2011-11-23 02:08:50 +0000 | [diff] [blame] | 60 | virtual bool filterPath(SkPath*, const SkPath&, SkScalar* width) SK_OVERRIDE; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 61 | |
djsollen@google.com | ba28d03 | 2012-03-26 17:57:35 +0000 | [diff] [blame] | 62 | SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkPath1DPathEffect) |
reed@google.com | e28b917 | 2011-08-09 18:14:31 +0000 | [diff] [blame] | 63 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 64 | protected: |
| 65 | SkPath1DPathEffect(SkFlattenableReadBuffer& buffer); |
| 66 | |
| 67 | // overrides from Sk1DPathEffect |
mike@reedtribe.org | 259210c | 2011-11-23 02:08:50 +0000 | [diff] [blame] | 68 | virtual SkScalar begin(SkScalar contourLength) SK_OVERRIDE; |
| 69 | virtual SkScalar next(SkPath*, SkScalar distance, SkPathMeasure&) SK_OVERRIDE; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 70 | // overrides from SkFlattenable |
mike@reedtribe.org | 259210c | 2011-11-23 02:08:50 +0000 | [diff] [blame] | 71 | virtual void flatten(SkFlattenableWriteBuffer&) SK_OVERRIDE; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 72 | |
| 73 | private: |
| 74 | SkPath fPath; // copied from constructor |
| 75 | SkScalar fAdvance; // copied from constructor |
| 76 | SkScalar fInitialOffset; // computed from phase |
| 77 | Style fStyle; // copied from constructor |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 78 | |
| 79 | typedef Sk1DPathEffect INHERITED; |
| 80 | }; |
| 81 | |
| 82 | |
| 83 | #endif |