blob: 34edfaa91fa89929c75d417cc9a19319089136da [file] [log] [blame]
reed@android.com8a1c16f2008-12-17 15:59:43 +00001/*
epoger@google.comec3ed6a2011-07-28 14:26:00 +00002 * Copyright 2006 The Android Open Source Project
reed@android.com8a1c16f2008-12-17 15:59:43 +00003 *
epoger@google.comec3ed6a2011-07-28 14:26:00 +00004 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
reed@android.com8a1c16f2008-12-17 15:59:43 +00006 */
7
reed@android.com8a1c16f2008-12-17 15:59:43 +00008#ifndef Sk1DPathEffect_DEFINED
9#define Sk1DPathEffect_DEFINED
10
Mike Kleinc0bd9f92019-04-23 12:05:21 -050011#include "include/core/SkFlattenable.h"
12#include "include/core/SkPath.h"
13#include "include/core/SkPathEffect.h"
reed@android.com8a1c16f2008-12-17 15:59:43 +000014
15class SkPathMeasure;
16
tfarina@chromium.org6806fe82012-10-12 14:41:39 +000017// This class is not exported to java.
18class SK_API Sk1DPathEffect : public SkPathEffect {
reed@android.com8a1c16f2008-12-17 15:59:43 +000019public:
reed@android.com8a1c16f2008-12-17 15:59:43 +000020protected:
Mike Reed6d10f8b2018-08-16 13:22:16 -040021 bool onFilterPath(SkPath* dst, const SkPath& src, SkStrokeRec*, const SkRect*) const override;
22
reed@android.com8a1c16f2008-12-17 15:59:43 +000023 /** Called at the start of each contour, returns the initial offset
24 into that contour.
25 */
reed@google.com548a1f32012-12-18 16:12:09 +000026 virtual SkScalar begin(SkScalar contourLength) const = 0;
reed@android.com8a1c16f2008-12-17 15:59:43 +000027 /** Called with the current distance along the path, with the current matrix
28 for the point/tangent at the specified distance.
29 Return the distance to travel for the next call. If return <= 0, then that
30 contour is done.
31 */
reed@google.com548a1f32012-12-18 16:12:09 +000032 virtual SkScalar next(SkPath* dst, SkScalar dist, SkPathMeasure&) const = 0;
reed@android.com8a1c16f2008-12-17 15:59:43 +000033
34private:
35 typedef SkPathEffect INHERITED;
36};
37
tfarina@chromium.org6806fe82012-10-12 14:41:39 +000038class SK_API SkPath1DPathEffect : public Sk1DPathEffect {
reed@android.com8a1c16f2008-12-17 15:59:43 +000039public:
40 enum Style {
41 kTranslate_Style, // translate the shape to each position
42 kRotate_Style, // rotate the shape about its center
43 kMorph_Style, // transform each point, and turn lines into curves
ethannicholas23e7af02016-02-22 07:42:18 -080044
reedca726ab2016-02-22 12:50:25 -080045 kLastEnum_Style = kMorph_Style,
reed@android.com8a1c16f2008-12-17 15:59:43 +000046 };
rmistry@google.comfbfcd562012-08-23 18:09:54 +000047
reed@android.com8a1c16f2008-12-17 15:59:43 +000048 /** Dash by replicating the specified path.
49 @param path The path to replicate (dash)
50 @param advance The space between instances of path
51 @param phase distance (mod advance) along path for its initial position
52 @param style how to transform path at each point (based on the current
53 position and tangent)
54 */
reeda4393342016-03-18 11:22:57 -070055 static sk_sp<SkPathEffect> Make(const SkPath& path, SkScalar advance, SkScalar phase, Style);
56
reed@android.com8a1c16f2008-12-17 15:59:43 +000057protected:
commit-bot@chromium.orgbd0be252014-05-15 15:40:41 +000058 SkPath1DPathEffect(const SkPath& path, SkScalar advance, SkScalar phase, Style);
mtklein36352bf2015-03-25 18:17:31 -070059 void flatten(SkWriteBuffer&) const override;
Mike Reed6d10f8b2018-08-16 13:22:16 -040060 bool onFilterPath(SkPath*, const SkPath&, SkStrokeRec*, const SkRect*) const override;
reed@android.com8a1c16f2008-12-17 15:59:43 +000061
62 // overrides from Sk1DPathEffect
mtklein36352bf2015-03-25 18:17:31 -070063 SkScalar begin(SkScalar contourLength) const override;
64 SkScalar next(SkPath*, SkScalar, SkPathMeasure&) const override;
rmistry@google.comfbfcd562012-08-23 18:09:54 +000065
reed@android.com8a1c16f2008-12-17 15:59:43 +000066private:
Mike Klein4fee3232018-10-18 17:27:16 -040067 SK_FLATTENABLE_HOOKS(SkPath1DPathEffect)
Cary Clark4dc5a452018-05-21 11:56:57 -040068
reed@android.com8a1c16f2008-12-17 15:59:43 +000069 SkPath fPath; // copied from constructor
70 SkScalar fAdvance; // copied from constructor
71 SkScalar fInitialOffset; // computed from phase
72 Style fStyle; // copied from constructor
reed@android.com8a1c16f2008-12-17 15:59:43 +000073
74 typedef Sk1DPathEffect INHERITED;
75};
76
reed@android.com8a1c16f2008-12-17 15:59:43 +000077#endif