| 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 SkDashPathEffect_DEFINED |
| 9 |
#define SkDashPathEffect_DEFINED |
| 10 |
|
| 11 |
#include "include/core/SkPathEffect.h" // IWYU pragma: keep (for unspanned apis) |
| 12 |
#include "include/core/SkRefCnt.h" |
| 13 |
#include "include/core/SkScalar.h" |
| 14 |
#include "include/core/SkSpan.h" |
| 15 |
#include "include/core/SkTypes.h" |
| 16 |
|
| 17 |
class SK_API SkDashPathEffect { |
| 18 |
public: |
| 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. This array will be |
| 22 |
copied in Make, and can be disposed of freely after. |
| 23 |
count: number of elements in the intervals array |
| 24 |
phase: offset into the intervals array (mod the sum of all of the |
| 25 |
intervals). |
| 26 |
|
| 27 |
For example: if intervals[] = {10, 20}, count = 2, and phase = 25, |
| 28 |
this will set up a dashed path like so: |
| 29 |
5 pixels off |
| 30 |
10 pixels on |
| 31 |
20 pixels off |
| 32 |
10 pixels on |
| 33 |
20 pixels off |
| 34 |
... |
| 35 |
A phase of -5, 25, 55, 85, etc. would all result in the same path, |
| 36 |
because the sum of all the intervals is 30. |
| 37 |
|
| 38 |
Note: only affects stroked paths. |
| 39 |
*/ |
| 40 |
static sk_sp<SkPathEffect> Make(SkSpan<const SkScalar> intervals, SkScalar phase); |
| 41 |
|
| 42 |
#ifdef SK_SUPPORT_UNSPANNED_APIS |
| 43 |
static sk_sp<SkPathEffect> Make(const SkScalar intervals[], int count, SkScalar phase) { |
| 44 |
return intervals ? Make({intervals, count}, phase) : nullptr; |
| 45 |
} |
| 46 |
#endif |
| 47 |
}; |
| 48 |
|
| 49 |
#endif |