reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1 | /* |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 2 | * Copyright 2006 The Android Open Source Project |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 3 | * |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | #ifndef SkDashPathEffect_DEFINED |
| 9 | #define SkDashPathEffect_DEFINED |
| 10 | |
| 11 | #include "SkPathEffect.h" |
| 12 | |
| 13 | /** \class SkDashPathEffect |
| 14 | |
| 15 | SkDashPathEffect is a subclass of SkPathEffect that implements dashing |
| 16 | */ |
ctguil@chromium.org | 7ffb1b2 | 2011-03-15 21:27:08 +0000 | [diff] [blame] | 17 | class SK_API SkDashPathEffect : public SkPathEffect { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 18 | public: |
epoger@google.com | 20bf4ca | 2012-04-27 13:34:52 +0000 | [diff] [blame] | 19 | /** intervals: array containing an even number of entries (>=2), with |
| 20 | the even indices specifying the length of "on" intervals, and the odd |
| 21 | indices specifying the length of "off" intervals. |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 22 | count: number of elements in the intervals array |
epoger@google.com | 20bf4ca | 2012-04-27 13:34:52 +0000 | [diff] [blame] | 23 | phase: offset into the intervals array (mod the sum of all of the |
| 24 | intervals). |
| 25 | |
| 26 | For example: if intervals[] = {10, 20}, count = 2, and phase = 25, |
| 27 | this will set up a dashed path like so: |
| 28 | 5 pixels off |
| 29 | 10 pixels on |
| 30 | 20 pixels off |
| 31 | 10 pixels on |
| 32 | 20 pixels off |
| 33 | ... |
| 34 | A phase of -5, 25, 55, 85, etc. would all result in the same path, |
| 35 | because the sum of all the intervals is 30. |
| 36 | |
| 37 | Note: only affects stroked paths. |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 38 | */ |
reed | a439334 | 2016-03-18 11:22:57 -0700 | [diff] [blame] | 39 | static sk_sp<SkPathEffect> Make(const SkScalar intervals[], int count, SkScalar phase); |
| 40 | |
reed@google.com | 548a1f3 | 2012-12-18 16:12:09 +0000 | [diff] [blame] | 41 | virtual bool filterPath(SkPath* dst, const SkPath& src, |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 42 | SkStrokeRec*, const SkRect*) const override; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 43 | |
skia.committer@gmail.com | 687c57c | 2012-11-29 02:01:19 +0000 | [diff] [blame] | 44 | virtual bool asPoints(PointData* results, const SkPath& src, |
reed@google.com | 4bbdeac | 2013-01-24 21:03:11 +0000 | [diff] [blame] | 45 | const SkStrokeRec&, const SkMatrix&, |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 46 | const SkRect*) const override; |
robertphillips@google.com | 629ab54 | 2012-11-28 17:18:11 +0000 | [diff] [blame] | 47 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 48 | DashType asADash(DashInfo* info) const override; |
commit-bot@chromium.org | aec1438 | 2014-04-22 15:21:18 +0000 | [diff] [blame] | 49 | |
robertphillips | 42dbfa8 | 2015-01-26 06:08:52 -0800 | [diff] [blame] | 50 | SK_TO_STRING_OVERRIDE() |
reed | 9fa60da | 2014-08-21 07:59:51 -0700 | [diff] [blame] | 51 | SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkDashPathEffect) |
reed@google.com | 6bac947 | 2011-06-21 19:24:00 +0000 | [diff] [blame] | 52 | |
tomhudson | 64de1e1 | 2015-03-05 08:01:07 -0800 | [diff] [blame] | 53 | #ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 54 | bool exposedInAndroidJavaAPI() const override { return true; } |
tomhudson | 64de1e1 | 2015-03-05 08:01:07 -0800 | [diff] [blame] | 55 | #endif |
| 56 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 57 | protected: |
reed | ca726ab | 2016-02-22 12:50:25 -0800 | [diff] [blame] | 58 | virtual ~SkDashPathEffect(); |
commit-bot@chromium.org | 35c03fb | 2014-03-31 18:52:51 +0000 | [diff] [blame] | 59 | SkDashPathEffect(const SkScalar intervals[], int count, SkScalar phase); |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 60 | void flatten(SkWriteBuffer&) const override; |
commit-bot@chromium.org | 0a2bf90 | 2014-02-20 20:40:19 +0000 | [diff] [blame] | 61 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 62 | private: |
| 63 | SkScalar* fIntervals; |
| 64 | int32_t fCount; |
commit-bot@chromium.org | aec1438 | 2014-04-22 15:21:18 +0000 | [diff] [blame] | 65 | SkScalar fPhase; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 66 | // computed from phase |
reed | ca726ab | 2016-02-22 12:50:25 -0800 | [diff] [blame] | 67 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 68 | SkScalar fInitialDashLength; |
| 69 | int32_t fInitialDashIndex; |
| 70 | SkScalar fIntervalLength; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 71 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 72 | typedef SkPathEffect INHERITED; |
| 73 | }; |
| 74 | |
| 75 | #endif |