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 Sk1DPathEffect_DEFINED michael@0: #define Sk1DPathEffect_DEFINED michael@0: michael@0: #include "SkPathEffect.h" michael@0: #include "SkPath.h" michael@0: michael@0: class SkPathMeasure; michael@0: michael@0: // This class is not exported to java. michael@0: class SK_API Sk1DPathEffect : public SkPathEffect { michael@0: public: michael@0: virtual bool filterPath(SkPath* dst, const SkPath& src, michael@0: SkStrokeRec*, const SkRect*) const SK_OVERRIDE; michael@0: michael@0: protected: michael@0: /** Called at the start of each contour, returns the initial offset michael@0: into that contour. michael@0: */ michael@0: virtual SkScalar begin(SkScalar contourLength) const = 0; michael@0: /** Called with the current distance along the path, with the current matrix michael@0: for the point/tangent at the specified distance. michael@0: Return the distance to travel for the next call. If return <= 0, then that michael@0: contour is done. michael@0: */ michael@0: virtual SkScalar next(SkPath* dst, SkScalar dist, SkPathMeasure&) const = 0; michael@0: michael@0: private: michael@0: typedef SkPathEffect INHERITED; michael@0: }; michael@0: michael@0: class SK_API SkPath1DPathEffect : public Sk1DPathEffect { michael@0: public: michael@0: enum Style { michael@0: kTranslate_Style, // translate the shape to each position michael@0: kRotate_Style, // rotate the shape about its center michael@0: kMorph_Style, // transform each point, and turn lines into curves michael@0: michael@0: kStyleCount michael@0: }; michael@0: michael@0: /** Dash by replicating the specified path. michael@0: @param path The path to replicate (dash) michael@0: @param advance The space between instances of path michael@0: @param phase distance (mod advance) along path for its initial position michael@0: @param style how to transform path at each point (based on the current michael@0: position and tangent) michael@0: */ michael@0: static SkPath1DPathEffect* Create(const SkPath& path, SkScalar advance, SkScalar phase, michael@0: Style style) { michael@0: return SkNEW_ARGS(SkPath1DPathEffect, (path, advance, phase, style)); michael@0: } michael@0: michael@0: virtual bool filterPath(SkPath*, const SkPath&, michael@0: SkStrokeRec*, const SkRect*) const SK_OVERRIDE; michael@0: michael@0: SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkPath1DPathEffect) michael@0: michael@0: protected: michael@0: SkPath1DPathEffect(SkReadBuffer& buffer); michael@0: virtual void flatten(SkWriteBuffer&) const SK_OVERRIDE; michael@0: michael@0: // overrides from Sk1DPathEffect michael@0: virtual SkScalar begin(SkScalar contourLength) const SK_OVERRIDE; michael@0: virtual SkScalar next(SkPath*, SkScalar, SkPathMeasure&) const SK_OVERRIDE; michael@0: michael@0: #ifdef SK_SUPPORT_LEGACY_PUBLICEFFECTCONSTRUCTORS michael@0: public: michael@0: #endif michael@0: SkPath1DPathEffect(const SkPath& path, SkScalar advance, SkScalar phase, Style); michael@0: michael@0: private: michael@0: SkPath fPath; // copied from constructor michael@0: SkScalar fAdvance; // copied from constructor michael@0: SkScalar fInitialOffset; // computed from phase michael@0: Style fStyle; // copied from constructor michael@0: michael@0: typedef Sk1DPathEffect INHERITED; michael@0: }; michael@0: michael@0: #endif