michael@0: /* michael@0: * Copyright 2006 The Android Open Source Project michael@0: * michael@0: * Use of this source code is governed by a BSD-style license that can be michael@0: * found in the LICENSE file. michael@0: */ michael@0: michael@0: #ifndef SkDashPathEffect_DEFINED michael@0: #define SkDashPathEffect_DEFINED michael@0: michael@0: #include "SkPathEffect.h" michael@0: michael@0: /** \class SkDashPathEffect michael@0: michael@0: SkDashPathEffect is a subclass of SkPathEffect that implements dashing michael@0: */ michael@0: class SK_API SkDashPathEffect : public SkPathEffect { michael@0: public: michael@0: /** intervals: array containing an even number of entries (>=2), with michael@0: the even indices specifying the length of "on" intervals, and the odd michael@0: indices specifying the length of "off" intervals. michael@0: count: number of elements in the intervals array michael@0: phase: offset into the intervals array (mod the sum of all of the michael@0: intervals). michael@0: michael@0: For example: if intervals[] = {10, 20}, count = 2, and phase = 25, michael@0: this will set up a dashed path like so: michael@0: 5 pixels off michael@0: 10 pixels on michael@0: 20 pixels off michael@0: 10 pixels on michael@0: 20 pixels off michael@0: ... michael@0: A phase of -5, 25, 55, 85, etc. would all result in the same path, michael@0: because the sum of all the intervals is 30. michael@0: michael@0: Note: only affects stroked paths. michael@0: */ michael@0: static SkDashPathEffect* Create(const SkScalar intervals[], int count, michael@0: SkScalar phase, bool scaleToFit = false) { michael@0: return SkNEW_ARGS(SkDashPathEffect, (intervals, count, phase, scaleToFit)); michael@0: } michael@0: virtual ~SkDashPathEffect(); michael@0: michael@0: virtual bool filterPath(SkPath* dst, const SkPath& src, michael@0: SkStrokeRec*, const SkRect*) const SK_OVERRIDE; michael@0: michael@0: virtual bool asPoints(PointData* results, const SkPath& src, michael@0: const SkStrokeRec&, const SkMatrix&, michael@0: const SkRect*) const SK_OVERRIDE; michael@0: michael@0: virtual Factory getFactory() const SK_OVERRIDE; michael@0: michael@0: static SkFlattenable* CreateProc(SkReadBuffer&); michael@0: michael@0: protected: michael@0: SkDashPathEffect(SkReadBuffer&); michael@0: virtual void flatten(SkWriteBuffer&) const SK_OVERRIDE; michael@0: michael@0: #ifdef SK_SUPPORT_LEGACY_PUBLICEFFECTCONSTRUCTORS michael@0: public: michael@0: #endif michael@0: SkDashPathEffect(const SkScalar intervals[], int count, SkScalar phase, michael@0: bool scaleToFit = false); michael@0: michael@0: private: michael@0: SkScalar* fIntervals; michael@0: int32_t fCount; michael@0: // computed from phase michael@0: SkScalar fInitialDashLength; michael@0: int32_t fInitialDashIndex; michael@0: SkScalar fIntervalLength; michael@0: bool fScaleToFit; michael@0: michael@0: typedef SkPathEffect INHERITED; michael@0: }; michael@0: michael@0: #endif