The JUCE cross-platform C++ framework, with DISTRHO/KXStudio specific changes
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

150 lines
5.7KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library - "Jules' Utility Class Extensions"
  4. Copyright 2004-11 by Raw Material Software Ltd.
  5. ------------------------------------------------------------------------------
  6. JUCE can be redistributed and/or modified under the terms of the GNU General
  7. Public License (Version 2), as published by the Free Software Foundation.
  8. A copy of the license is included in the JUCE distribution, or can be found
  9. online at www.gnu.org/licenses.
  10. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  11. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  12. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  13. ------------------------------------------------------------------------------
  14. To release a closed-source product which uses JUCE, commercial licenses are
  15. available: visit www.rawmaterialsoftware.com/juce for more information.
  16. ==============================================================================
  17. */
  18. #ifndef __JUCE_DRAWABLEPATH_JUCEHEADER__
  19. #define __JUCE_DRAWABLEPATH_JUCEHEADER__
  20. #include "juce_DrawableShape.h"
  21. #include "../positioning/juce_RelativePointPath.h"
  22. //==============================================================================
  23. /**
  24. A drawable object which renders a filled or outlined shape.
  25. For details on how to change the fill and stroke, see the DrawableShape class.
  26. @see Drawable, DrawableShape
  27. */
  28. class JUCE_API DrawablePath : public DrawableShape
  29. {
  30. public:
  31. //==============================================================================
  32. /** Creates a DrawablePath. */
  33. DrawablePath();
  34. DrawablePath (const DrawablePath& other);
  35. /** Destructor. */
  36. ~DrawablePath();
  37. //==============================================================================
  38. /** Changes the path that will be drawn.
  39. @see setFillColour, setStrokeType
  40. */
  41. void setPath (const Path& newPath);
  42. /** Sets the path using a RelativePointPath.
  43. Calling this will set up a Component::Positioner to automatically update the path
  44. if any of the points in the source path are dynamic.
  45. */
  46. void setPath (const RelativePointPath& newPath);
  47. /** Returns the current path. */
  48. const Path& getPath() const;
  49. /** Returns the current path for the outline. */
  50. const Path& getStrokePath() const;
  51. //==============================================================================
  52. /** @internal */
  53. Drawable* createCopy() const;
  54. /** @internal */
  55. void refreshFromValueTree (const ValueTree& tree, ComponentBuilder& builder);
  56. /** @internal */
  57. ValueTree createValueTree (ComponentBuilder::ImageProvider* imageProvider) const;
  58. /** @internal */
  59. static const Identifier valueTreeType;
  60. //==============================================================================
  61. /** Internally-used class for wrapping a DrawablePath's state into a ValueTree. */
  62. class ValueTreeWrapper : public DrawableShape::FillAndStrokeState
  63. {
  64. public:
  65. ValueTreeWrapper (const ValueTree& state);
  66. bool usesNonZeroWinding() const;
  67. void setUsesNonZeroWinding (bool b, UndoManager* undoManager);
  68. class Element
  69. {
  70. public:
  71. explicit Element (const ValueTree& state);
  72. ~Element();
  73. const Identifier getType() const noexcept { return state.getType(); }
  74. int getNumControlPoints() const noexcept;
  75. RelativePoint getControlPoint (int index) const;
  76. Value getControlPointValue (int index, UndoManager*) const;
  77. RelativePoint getStartPoint() const;
  78. RelativePoint getEndPoint() const;
  79. void setControlPoint (int index, const RelativePoint& point, UndoManager*);
  80. float getLength (Expression::Scope*) const;
  81. ValueTreeWrapper getParent() const;
  82. Element getPreviousElement() const;
  83. String getModeOfEndPoint() const;
  84. void setModeOfEndPoint (const String& newMode, UndoManager*);
  85. void convertToLine (UndoManager*);
  86. void convertToCubic (Expression::Scope*, UndoManager*);
  87. void convertToPathBreak (UndoManager* undoManager);
  88. ValueTree insertPoint (const Point<float>& targetPoint, Expression::Scope*, UndoManager*);
  89. void removePoint (UndoManager* undoManager);
  90. float findProportionAlongLine (const Point<float>& targetPoint, Expression::Scope*) const;
  91. static const Identifier mode, startSubPathElement, closeSubPathElement,
  92. lineToElement, quadraticToElement, cubicToElement;
  93. static const char* cornerMode;
  94. static const char* roundedMode;
  95. static const char* symmetricMode;
  96. ValueTree state;
  97. };
  98. ValueTree getPathState();
  99. void readFrom (const RelativePointPath& path, UndoManager* undoManager);
  100. void writeTo (RelativePointPath& path) const;
  101. static const Identifier nonZeroWinding, point1, point2, point3;
  102. };
  103. private:
  104. //==============================================================================
  105. ScopedPointer<RelativePointPath> relativePath;
  106. class RelativePositioner;
  107. friend class RelativePositioner;
  108. void applyRelativePath (const RelativePointPath&, Expression::Scope*);
  109. DrawablePath& operator= (const DrawablePath&);
  110. JUCE_LEAK_DETECTOR (DrawablePath);
  111. };
  112. #endif // __JUCE_DRAWABLEPATH_JUCEHEADER__