2008-12-17 15:59:43 +00:00
|
|
|
/*
|
2011-07-28 14:26:00 +00:00
|
|
|
* Copyright 2006 The Android Open Source Project
|
2008-12-17 15:59:43 +00:00
|
|
|
*
|
2011-07-28 14:26:00 +00:00
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
2008-12-17 15:59:43 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef SkDashPathEffect_DEFINED
|
|
|
|
#define SkDashPathEffect_DEFINED
|
|
|
|
|
|
|
|
#include "SkPathEffect.h"
|
|
|
|
|
|
|
|
/** \class SkDashPathEffect
|
|
|
|
|
|
|
|
SkDashPathEffect is a subclass of SkPathEffect that implements dashing
|
|
|
|
*/
|
2011-03-15 21:27:08 +00:00
|
|
|
class SK_API SkDashPathEffect : public SkPathEffect {
|
2008-12-17 15:59:43 +00:00
|
|
|
public:
|
2012-04-27 13:34:52 +00:00
|
|
|
/** intervals: array containing an even number of entries (>=2), with
|
|
|
|
the even indices specifying the length of "on" intervals, and the odd
|
|
|
|
indices specifying the length of "off" intervals.
|
2012-08-23 18:09:54 +00:00
|
|
|
count: number of elements in the intervals array
|
2012-04-27 13:34:52 +00:00
|
|
|
phase: offset into the intervals array (mod the sum of all of the
|
|
|
|
intervals).
|
|
|
|
|
|
|
|
For example: if intervals[] = {10, 20}, count = 2, and phase = 25,
|
|
|
|
this will set up a dashed path like so:
|
|
|
|
5 pixels off
|
|
|
|
10 pixels on
|
|
|
|
20 pixels off
|
|
|
|
10 pixels on
|
|
|
|
20 pixels off
|
|
|
|
...
|
|
|
|
A phase of -5, 25, 55, 85, etc. would all result in the same path,
|
|
|
|
because the sum of all the intervals is 30.
|
|
|
|
|
|
|
|
Note: only affects stroked paths.
|
2008-12-17 15:59:43 +00:00
|
|
|
*/
|
2014-02-20 20:40:19 +00:00
|
|
|
static SkDashPathEffect* Create(const SkScalar intervals[], int count,
|
2014-03-31 18:52:51 +00:00
|
|
|
SkScalar phase) {
|
|
|
|
return SkNEW_ARGS(SkDashPathEffect, (intervals, count, phase));
|
2014-02-20 20:40:19 +00:00
|
|
|
}
|
2008-12-17 15:59:43 +00:00
|
|
|
virtual ~SkDashPathEffect();
|
|
|
|
|
2012-12-18 16:12:09 +00:00
|
|
|
virtual bool filterPath(SkPath* dst, const SkPath& src,
|
2015-03-26 01:17:31 +00:00
|
|
|
SkStrokeRec*, const SkRect*) const override;
|
2008-12-17 15:59:43 +00:00
|
|
|
|
2012-11-29 02:01:19 +00:00
|
|
|
virtual bool asPoints(PointData* results, const SkPath& src,
|
2013-01-24 21:03:11 +00:00
|
|
|
const SkStrokeRec&, const SkMatrix&,
|
2015-03-26 01:17:31 +00:00
|
|
|
const SkRect*) const override;
|
2012-11-28 17:18:11 +00:00
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
DashType asADash(DashInfo* info) const override;
|
2014-04-22 15:21:18 +00:00
|
|
|
|
2015-01-26 14:08:52 +00:00
|
|
|
SK_TO_STRING_OVERRIDE()
|
2014-08-21 14:59:51 +00:00
|
|
|
SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkDashPathEffect)
|
2011-06-21 19:24:00 +00:00
|
|
|
|
2015-03-05 16:01:07 +00:00
|
|
|
#ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK
|
2015-03-26 01:17:31 +00:00
|
|
|
bool exposedInAndroidJavaAPI() const override { return true; }
|
2015-03-05 16:01:07 +00:00
|
|
|
#endif
|
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
protected:
|
2014-03-31 18:52:51 +00:00
|
|
|
SkDashPathEffect(const SkScalar intervals[], int count, SkScalar phase);
|
2015-03-26 01:17:31 +00:00
|
|
|
void flatten(SkWriteBuffer&) const override;
|
2014-02-20 20:40:19 +00:00
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
private:
|
|
|
|
SkScalar* fIntervals;
|
|
|
|
int32_t fCount;
|
2014-04-22 15:21:18 +00:00
|
|
|
SkScalar fPhase;
|
2008-12-17 15:59:43 +00:00
|
|
|
// computed from phase
|
|
|
|
SkScalar fInitialDashLength;
|
|
|
|
int32_t fInitialDashIndex;
|
|
|
|
SkScalar fIntervalLength;
|
|
|
|
|
|
|
|
typedef SkPathEffect INHERITED;
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|