blob: 10d8d2db4e51e1ffe25b651ac0d4d5ba3926bbcb [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
8#ifndef SkDashPathEffect_DEFINED
9#define SkDashPathEffect_DEFINED
10
11#include "SkPathEffect.h"
12
13/** \class SkDashPathEffect
14
15 SkDashPathEffect is a subclass of SkPathEffect that implements dashing
16*/
ctguil@chromium.org7ffb1b22011-03-15 21:27:08 +000017class SK_API SkDashPathEffect : public SkPathEffect {
reed@android.com8a1c16f2008-12-17 15:59:43 +000018public:
epoger@google.com20bf4ca2012-04-27 13:34:52 +000019 /** 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.
rmistry@google.comfbfcd562012-08-23 18:09:54 +000022 count: number of elements in the intervals array
epoger@google.com20bf4ca2012-04-27 13:34:52 +000023 phase: offset into the intervals array (mod the sum of all of the
24 intervals).
25
26 For example: if intervals[] = {10, 20}, count = 2, and phase = 25,
27 this will set up a dashed path like so:
28 5 pixels off
29 10 pixels on
30 20 pixels off
31 10 pixels on
32 20 pixels off
33 ...
34 A phase of -5, 25, 55, 85, etc. would all result in the same path,
35 because the sum of all the intervals is 30.
36
37 Note: only affects stroked paths.
reed@android.com8a1c16f2008-12-17 15:59:43 +000038 */
commit-bot@chromium.org0a2bf902014-02-20 20:40:19 +000039 static SkDashPathEffect* Create(const SkScalar intervals[], int count,
commit-bot@chromium.org35c03fb2014-03-31 18:52:51 +000040 SkScalar phase) {
41 return SkNEW_ARGS(SkDashPathEffect, (intervals, count, phase));
commit-bot@chromium.org0a2bf902014-02-20 20:40:19 +000042 }
reed@android.com8a1c16f2008-12-17 15:59:43 +000043 virtual ~SkDashPathEffect();
44
reed@google.com548a1f32012-12-18 16:12:09 +000045 virtual bool filterPath(SkPath* dst, const SkPath& src,
reed@google.com4bbdeac2013-01-24 21:03:11 +000046 SkStrokeRec*, const SkRect*) const SK_OVERRIDE;
reed@android.com8a1c16f2008-12-17 15:59:43 +000047
skia.committer@gmail.com687c57c2012-11-29 02:01:19 +000048 virtual bool asPoints(PointData* results, const SkPath& src,
reed@google.com4bbdeac2013-01-24 21:03:11 +000049 const SkStrokeRec&, const SkMatrix&,
50 const SkRect*) const SK_OVERRIDE;
robertphillips@google.com629ab542012-11-28 17:18:11 +000051
commit-bot@chromium.orgaec14382014-04-22 15:21:18 +000052 virtual DashType asADash(DashInfo* info) const SK_OVERRIDE;
53
robertphillips@google.comc2eae472013-10-21 12:26:10 +000054 virtual Factory getFactory() const SK_OVERRIDE;
reed@google.com548a1f32012-12-18 16:12:09 +000055
commit-bot@chromium.org8b0e8ac2014-01-30 18:58:24 +000056 static SkFlattenable* CreateProc(SkReadBuffer&);
reed@google.com6bac9472011-06-21 19:24:00 +000057
reed@android.com8a1c16f2008-12-17 15:59:43 +000058protected:
commit-bot@chromium.org35c03fb2014-03-31 18:52:51 +000059 SkDashPathEffect(const SkScalar intervals[], int count, SkScalar phase);
commit-bot@chromium.orgbd0be252014-05-15 15:40:41 +000060 explicit SkDashPathEffect(SkReadBuffer&);
61 virtual void flatten(SkWriteBuffer&) const SK_OVERRIDE;
commit-bot@chromium.org0a2bf902014-02-20 20:40:19 +000062
reed@android.com8a1c16f2008-12-17 15:59:43 +000063private:
egdaniel90b8caf2014-06-04 09:59:08 -070064 void setInternalMembers(SkScalar phase);
65
reed@android.com8a1c16f2008-12-17 15:59:43 +000066 SkScalar* fIntervals;
67 int32_t fCount;
commit-bot@chromium.orgaec14382014-04-22 15:21:18 +000068 SkScalar fPhase;
reed@android.com8a1c16f2008-12-17 15:59:43 +000069 // computed from phase
70 SkScalar fInitialDashLength;
71 int32_t fInitialDashIndex;
72 SkScalar fIntervalLength;
reed@android.com8a1c16f2008-12-17 15:59:43 +000073
reed@android.com8a1c16f2008-12-17 15:59:43 +000074 typedef SkPathEffect INHERITED;
75};
76
77#endif