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 SkDashPathEffect_DEFINED |
| 11 | #define SkDashPathEffect_DEFINED |
| 12 | |
| 13 | #include "SkPathEffect.h" |
| 14 | |
| 15 | /** \class SkDashPathEffect |
| 16 | |
| 17 | SkDashPathEffect is a subclass of SkPathEffect that implements dashing |
| 18 | */ |
ctguil@chromium.org | 7ffb1b2 | 2011-03-15 21:27:08 +0000 | [diff] [blame] | 19 | class SK_API SkDashPathEffect : public SkPathEffect { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 20 | public: |
epoger@google.com | 20bf4ca | 2012-04-27 13:34:52 +0000 | [diff] [blame] | 21 | /** intervals: array containing an even number of entries (>=2), with |
| 22 | the even indices specifying the length of "on" intervals, and the odd |
| 23 | indices specifying the length of "off" intervals. |
| 24 | count: number of elements in the intervals array |
| 25 | phase: offset into the intervals array (mod the sum of all of the |
| 26 | intervals). |
| 27 | |
| 28 | For example: if intervals[] = {10, 20}, count = 2, and phase = 25, |
| 29 | this will set up a dashed path like so: |
| 30 | 5 pixels off |
| 31 | 10 pixels on |
| 32 | 20 pixels off |
| 33 | 10 pixels on |
| 34 | 20 pixels off |
| 35 | ... |
| 36 | A phase of -5, 25, 55, 85, etc. would all result in the same path, |
| 37 | because the sum of all the intervals is 30. |
| 38 | |
| 39 | Note: only affects stroked paths. |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 40 | */ |
| 41 | SkDashPathEffect(const SkScalar intervals[], int count, SkScalar phase, bool scaleToFit = false); |
| 42 | virtual ~SkDashPathEffect(); |
| 43 | |
reed@google.com | 9797272 | 2012-05-24 20:13:57 +0000 | [diff] [blame^] | 44 | virtual bool filterPath(SkPath* dst, const SkPath& src, SkStrokeRec*) SK_OVERRIDE; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 45 | |
| 46 | // overrides for SkFlattenable |
| 47 | // This method is not exported to java. |
| 48 | virtual Factory getFactory(); |
reed@google.com | 6bac947 | 2011-06-21 19:24:00 +0000 | [diff] [blame] | 49 | static SkFlattenable* CreateProc(SkFlattenableReadBuffer&); |
| 50 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 51 | protected: |
| 52 | SkDashPathEffect(SkFlattenableReadBuffer&); |
djsollen@google.com | 5492424 | 2012-03-29 15:18:04 +0000 | [diff] [blame] | 53 | virtual void flatten(SkFlattenableWriteBuffer&) const SK_OVERRIDE; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 54 | |
| 55 | private: |
| 56 | SkScalar* fIntervals; |
| 57 | int32_t fCount; |
| 58 | // computed from phase |
| 59 | SkScalar fInitialDashLength; |
| 60 | int32_t fInitialDashIndex; |
| 61 | SkScalar fIntervalLength; |
| 62 | bool fScaleToFit; |
| 63 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 64 | typedef SkPathEffect INHERITED; |
| 65 | }; |
| 66 | |
| 67 | #endif |
| 68 | |