blob: ce49460e653733836b8b27441c86adf0a827d185 [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,
reed@google.com4bbdeac2013-01-24 21:03:11 +000020 SkStrokeRec*, const SkRect*) const SK_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
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
rmistry@google.comfbfcd562012-08-23 18:09:54 +000044
reed@android.com8a1c16f2008-12-17 15:59:43 +000045 kStyleCount
46 };
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 */
commit-bot@chromium.org0a2bf902014-02-20 20:40:19 +000055 static SkPath1DPathEffect* Create(const SkPath& path, SkScalar advance, SkScalar phase,
56 Style style) {
57 return SkNEW_ARGS(SkPath1DPathEffect, (path, advance, phase, style));
58 }
reed@android.com8a1c16f2008-12-17 15:59:43 +000059
reed@google.com548a1f32012-12-18 16:12:09 +000060 virtual bool filterPath(SkPath*, const SkPath&,
reed@google.com4bbdeac2013-01-24 21:03:11 +000061 SkStrokeRec*, const SkRect*) const SK_OVERRIDE;
reed@android.com8a1c16f2008-12-17 15:59:43 +000062
djsollen@google.comba28d032012-03-26 17:57:35 +000063 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkPath1DPathEffect)
reed@google.come28b9172011-08-09 18:14:31 +000064
reed@android.com8a1c16f2008-12-17 15:59:43 +000065protected:
commit-bot@chromium.org8b0e8ac2014-01-30 18:58:24 +000066 SkPath1DPathEffect(SkReadBuffer& buffer);
67 virtual void flatten(SkWriteBuffer&) const SK_OVERRIDE;
reed@android.com8a1c16f2008-12-17 15:59:43 +000068
69 // overrides from Sk1DPathEffect
reed@google.com548a1f32012-12-18 16:12:09 +000070 virtual SkScalar begin(SkScalar contourLength) const SK_OVERRIDE;
71 virtual SkScalar next(SkPath*, SkScalar, SkPathMeasure&) const SK_OVERRIDE;
rmistry@google.comfbfcd562012-08-23 18:09:54 +000072
commit-bot@chromium.org0a2bf902014-02-20 20:40:19 +000073#ifdef SK_SUPPORT_LEGACY_PUBLICEFFECTCONSTRUCTORS
74public:
75#endif
76 SkPath1DPathEffect(const SkPath& path, SkScalar advance, SkScalar phase, Style);
77
reed@android.com8a1c16f2008-12-17 15:59:43 +000078private:
79 SkPath fPath; // copied from constructor
80 SkScalar fAdvance; // copied from constructor
81 SkScalar fInitialOffset; // computed from phase
82 Style fStyle; // copied from constructor
reed@android.com8a1c16f2008-12-17 15:59:43 +000083
84 typedef Sk1DPathEffect INHERITED;
85};
86
reed@android.com8a1c16f2008-12-17 15:59:43 +000087#endif