Sk1DPathEffect.h 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /*
  2. * Copyright 2006 The Android Open Source Project
  3. *
  4. * Use of this source code is governed by a BSD-style license that can be
  5. * found in the LICENSE file.
  6. */
  7. #ifndef Sk1DPathEffect_DEFINED
  8. #define Sk1DPathEffect_DEFINED
  9. #include "SkFlattenable.h"
  10. #include "SkPathEffect.h"
  11. #include "SkPath.h"
  12. class SkPathMeasure;
  13. // This class is not exported to java.
  14. class SK_API Sk1DPathEffect : public SkPathEffect {
  15. public:
  16. protected:
  17. bool onFilterPath(SkPath* dst, const SkPath& src, SkStrokeRec*, const SkRect*) const override;
  18. /** Called at the start of each contour, returns the initial offset
  19. into that contour.
  20. */
  21. virtual SkScalar begin(SkScalar contourLength) const = 0;
  22. /** Called with the current distance along the path, with the current matrix
  23. for the point/tangent at the specified distance.
  24. Return the distance to travel for the next call. If return <= 0, then that
  25. contour is done.
  26. */
  27. virtual SkScalar next(SkPath* dst, SkScalar dist, SkPathMeasure&) const = 0;
  28. private:
  29. typedef SkPathEffect INHERITED;
  30. };
  31. class SK_API SkPath1DPathEffect : public Sk1DPathEffect {
  32. public:
  33. enum Style {
  34. kTranslate_Style, // translate the shape to each position
  35. kRotate_Style, // rotate the shape about its center
  36. kMorph_Style, // transform each point, and turn lines into curves
  37. kLastEnum_Style = kMorph_Style,
  38. };
  39. /** Dash by replicating the specified path.
  40. @param path The path to replicate (dash)
  41. @param advance The space between instances of path
  42. @param phase distance (mod advance) along path for its initial position
  43. @param style how to transform path at each point (based on the current
  44. position and tangent)
  45. */
  46. static sk_sp<SkPathEffect> Make(const SkPath& path, SkScalar advance, SkScalar phase, Style);
  47. protected:
  48. SkPath1DPathEffect(const SkPath& path, SkScalar advance, SkScalar phase, Style);
  49. void flatten(SkWriteBuffer&) const override;
  50. bool onFilterPath(SkPath*, const SkPath&, SkStrokeRec*, const SkRect*) const override;
  51. // overrides from Sk1DPathEffect
  52. SkScalar begin(SkScalar contourLength) const override;
  53. SkScalar next(SkPath*, SkScalar, SkPathMeasure&) const override;
  54. private:
  55. SK_FLATTENABLE_HOOKS(SkPath1DPathEffect)
  56. SkPath fPath; // copied from constructor
  57. SkScalar fAdvance; // copied from constructor
  58. SkScalar fInitialOffset; // computed from phase
  59. Style fStyle; // copied from constructor
  60. typedef Sk1DPathEffect INHERITED;
  61. };
  62. #endif