Mike Reed | 4123223 | 2018-03-07 17:02:47 -0500 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2018 Google Inc. |
| 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 SkTrimPathEffect_DEFINED |
| 9 | #define SkTrimPathEffect_DEFINED |
| 10 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame^] | 11 | #include "include/core/SkPathEffect.h" |
Mike Reed | 4123223 | 2018-03-07 17:02:47 -0500 | [diff] [blame] | 12 | |
| 13 | class SK_API SkTrimPathEffect { |
| 14 | public: |
Florin Malita | 827af66 | 2018-03-09 16:08:58 -0500 | [diff] [blame] | 15 | enum class Mode { |
| 16 | kNormal, // return the subset path [start,stop] |
| 17 | kInverted, // return the complement/subset paths [0,start] + [stop,1] |
| 18 | }; |
| 19 | |
Mike Reed | 4123223 | 2018-03-07 17:02:47 -0500 | [diff] [blame] | 20 | /** |
| 21 | * Take start and stop "t" values (values between 0...1), and return a path that is that |
| 22 | * subset of the original path. |
| 23 | * |
| 24 | * e.g. |
| 25 | * Make(0.5, 1.0) --> return the 2nd half of the path |
| 26 | * Make(0.33333, 0.66667) --> return the middle third of the path |
| 27 | * |
| 28 | * The trim values apply to the entire path, so if it contains several contours, all of them |
| 29 | * are including in the calculation. |
| 30 | * |
| 31 | * startT and stopT must be 0..1 inclusive. If they are outside of that interval, they will |
| 32 | * be pinned to the nearest legal value. If either is NaN, null will be returned. |
| 33 | * |
Florin Malita | 827af66 | 2018-03-09 16:08:58 -0500 | [diff] [blame] | 34 | * Note: for Mode::kNormal, this will return one (logical) segment (even if it is spread |
| 35 | * across multiple contours). For Mode::kInverted, this will return 2 logical |
Mike Reed | 4123223 | 2018-03-07 17:02:47 -0500 | [diff] [blame] | 36 | * segments: 0...stopT and startT...1 |
| 37 | */ |
Florin Malita | 827af66 | 2018-03-09 16:08:58 -0500 | [diff] [blame] | 38 | static sk_sp<SkPathEffect> Make(SkScalar startT, SkScalar stopT, Mode = Mode::kNormal); |
Mike Reed | 4123223 | 2018-03-07 17:02:47 -0500 | [diff] [blame] | 39 | }; |
| 40 | |
| 41 | #endif |