blob: 3419dc23b7458fb084b83339e9a287a51d12ad52 [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
11#include "SkPathEffect.h"
12#include "SkPath.h"
13
14class SkPathMeasure;
15
tfarina@chromium.org6806fe82012-10-12 14:41:39 +000016// This class is not exported to java.
17class SK_API Sk1DPathEffect : public SkPathEffect {
reed@android.com8a1c16f2008-12-17 15:59:43 +000018public:
reed@google.com548a1f32012-12-18 16:12:09 +000019 virtual bool filterPath(SkPath* dst, const SkPath& src,
mtklein36352bf2015-03-25 18:17:31 -070020 SkStrokeRec*, const SkRect*) const override;
reed@android.com8a1c16f2008-12-17 15:59:43 +000021
22protected:
23 /** 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
tomhudson64de1e12015-03-05 08:01:07 -080034#ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK
mtklein36352bf2015-03-25 18:17:31 -070035 bool exposedInAndroidJavaAPI() const override { return true; }
tomhudson64de1e12015-03-05 08:01:07 -080036#endif
37
reed@android.com8a1c16f2008-12-17 15:59:43 +000038private:
39 typedef SkPathEffect INHERITED;
40};
41
tfarina@chromium.org6806fe82012-10-12 14:41:39 +000042class SK_API SkPath1DPathEffect : public Sk1DPathEffect {
reed@android.com8a1c16f2008-12-17 15:59:43 +000043public:
44 enum Style {
45 kTranslate_Style, // translate the shape to each position
46 kRotate_Style, // rotate the shape about its center
47 kMorph_Style, // transform each point, and turn lines into curves
rmistry@google.comfbfcd562012-08-23 18:09:54 +000048
reed@android.com8a1c16f2008-12-17 15:59:43 +000049 kStyleCount
50 };
rmistry@google.comfbfcd562012-08-23 18:09:54 +000051
reed@android.com8a1c16f2008-12-17 15:59:43 +000052 /** Dash by replicating the specified path.
53 @param path The path to replicate (dash)
54 @param advance The space between instances of path
55 @param phase distance (mod advance) along path for its initial position
56 @param style how to transform path at each point (based on the current
57 position and tangent)
58 */
reedd63f60a2015-12-20 19:38:20 -080059 static SkPathEffect* Create(const SkPath& path, SkScalar advance, SkScalar phase, Style style) {
halcanary385fe4d2015-08-26 13:07:48 -070060 return new SkPath1DPathEffect(path, advance, phase, style);
commit-bot@chromium.org0a2bf902014-02-20 20:40:19 +000061 }
reed@android.com8a1c16f2008-12-17 15:59:43 +000062
reed@google.com548a1f32012-12-18 16:12:09 +000063 virtual bool filterPath(SkPath*, const SkPath&,
mtklein36352bf2015-03-25 18:17:31 -070064 SkStrokeRec*, const SkRect*) const override;
reed@android.com8a1c16f2008-12-17 15:59:43 +000065
robertphillips42dbfa82015-01-26 06:08:52 -080066 SK_TO_STRING_OVERRIDE()
djsollen@google.comba28d032012-03-26 17:57:35 +000067 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkPath1DPathEffect)
reed@google.come28b9172011-08-09 18:14:31 +000068
reed@android.com8a1c16f2008-12-17 15:59:43 +000069protected:
commit-bot@chromium.orgbd0be252014-05-15 15:40:41 +000070 SkPath1DPathEffect(const SkPath& path, SkScalar advance, SkScalar phase, Style);
mtklein36352bf2015-03-25 18:17:31 -070071 void flatten(SkWriteBuffer&) const override;
reed@android.com8a1c16f2008-12-17 15:59:43 +000072
73 // overrides from Sk1DPathEffect
mtklein36352bf2015-03-25 18:17:31 -070074 SkScalar begin(SkScalar contourLength) const override;
75 SkScalar next(SkPath*, SkScalar, SkPathMeasure&) const override;
rmistry@google.comfbfcd562012-08-23 18:09:54 +000076
reed@android.com8a1c16f2008-12-17 15:59:43 +000077private:
78 SkPath fPath; // copied from constructor
79 SkScalar fAdvance; // copied from constructor
80 SkScalar fInitialOffset; // computed from phase
81 Style fStyle; // copied from constructor
reed@android.com8a1c16f2008-12-17 15:59:43 +000082
83 typedef Sk1DPathEffect INHERITED;
84};
85
reed@android.com8a1c16f2008-12-17 15:59:43 +000086#endif