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.

177 lines
6.6KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2013 - Raw Material Software Ltd.
  5. Permission is granted to use this software under the terms of either:
  6. a) the GPL v2 (or any later version)
  7. b) the Affero GPL v3
  8. Details of these licenses can be found at: www.gnu.org/licenses
  9. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  10. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  11. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  12. ------------------------------------------------------------------------------
  13. To release a closed-source product which uses JUCE, commercial licenses are
  14. available: visit www.juce.com for more information.
  15. ==============================================================================
  16. */
  17. #ifndef __JUCER_PAINTELEMENTPATH_JUCEHEADER__
  18. #define __JUCER_PAINTELEMENTPATH_JUCEHEADER__
  19. #include "jucer_ColouredElement.h"
  20. #include "jucer_ElementSiblingComponent.h"
  21. class PathPointComponent;
  22. class PaintElementPath;
  23. //==============================================================================
  24. class PathPoint
  25. {
  26. public:
  27. PathPoint (PaintElementPath* const owner);
  28. PathPoint (const PathPoint& other);
  29. PathPoint& operator= (const PathPoint& other);
  30. ~PathPoint();
  31. PaintElementPath* owner;
  32. Path::Iterator::PathElementType type;
  33. RelativePositionedRectangle pos [3];
  34. int getNumPoints() const;
  35. void changePointType (const Path::Iterator::PathElementType newType,
  36. const Rectangle<int>& parentArea,
  37. const bool undoable);
  38. void deleteFromPath();
  39. void getEditableProperties (Array<PropertyComponent*>& props);
  40. private:
  41. PathPoint withChangedPointType (const Path::Iterator::PathElementType newType,
  42. const Rectangle<int>& parentArea) const;
  43. };
  44. //==============================================================================
  45. class PaintElementPath : public ColouredElement
  46. {
  47. public:
  48. PaintElementPath (PaintRoutine* owner);
  49. ~PaintElementPath();
  50. //==============================================================================
  51. void setInitialBounds (int parentWidth, int parentHeight);
  52. Rectangle<int> getCurrentBounds (const Rectangle<int>& parentArea) const;
  53. void setCurrentBounds (const Rectangle<int>& b, const Rectangle<int>& parentArea, const bool undoable);
  54. //==============================================================================
  55. bool getPoint (int index, int pointNumber, double& x, double& y, const Rectangle<int>& parentArea) const;
  56. void movePoint (int index, int pointNumber, double newX, double newY, const Rectangle<int>& parentArea, const bool undoable);
  57. RelativePositionedRectangle getPoint (int index, int pointNumber) const;
  58. void setPoint (int index, int pointNumber, const RelativePositionedRectangle& newPoint, const bool undoable);
  59. int getNumPoints() const noexcept { return points.size(); }
  60. PathPoint* getPoint (int index) const noexcept { return points [index]; }
  61. int indexOfPoint (PathPoint* const p) const noexcept { return points.indexOf (p); }
  62. PathPoint* addPoint (int pointIndexToAddItAfter, const bool undoable);
  63. void deletePoint (int pointIndex, const bool undoable);
  64. void pointListChanged();
  65. int findSegmentAtXY (int x, int y) const;
  66. //==============================================================================
  67. bool isSubpathClosed (int pointIndex) const;
  68. void setSubpathClosed (int pointIndex, const bool closed, const bool undoable);
  69. bool isNonZeroWinding() const noexcept { return nonZeroWinding; }
  70. void setNonZeroWinding (const bool nonZero, const bool undoable);
  71. //==============================================================================
  72. void getEditableProperties (Array<PropertyComponent*>& props);
  73. void fillInGeneratedCode (GeneratedCode& code, String& paintMethodCode);
  74. //==============================================================================
  75. static const char* getTagName() noexcept { return "PATH"; }
  76. XmlElement* createXml() const;
  77. bool loadFromXml (const XmlElement& xml);
  78. void setToPath (const Path& p);
  79. //==============================================================================
  80. void draw (Graphics& g, const ComponentLayout* layout, const Rectangle<int>& parentArea);
  81. void drawExtraEditorGraphics (Graphics& g, const Rectangle<int>& relativeTo);
  82. void resized();
  83. void parentSizeChanged();
  84. void mouseDown (const MouseEvent& e);
  85. void mouseDrag (const MouseEvent& e);
  86. void mouseUp (const MouseEvent& e);
  87. void createSiblingComponents();
  88. void changed();
  89. private:
  90. friend class PathPoint;
  91. friend class PathPointComponent;
  92. OwnedArray <PathPoint> points;
  93. bool nonZeroWinding;
  94. mutable Path path;
  95. mutable Rectangle<int> lastPathBounds;
  96. int mouseDownOnSegment;
  97. bool mouseDownSelectSegmentStatus;
  98. String pathToString() const;
  99. void restorePathFromString (const String& s);
  100. void updateStoredPath (const ComponentLayout* layout, const Rectangle<int>& parentArea) const;
  101. int getBorderSize() const;
  102. void rescalePoint (RelativePositionedRectangle& pos, int dx, int dy,
  103. double scaleX, double scaleY,
  104. double scaleStartX, double scaleStartY,
  105. const Rectangle<int>& parentArea) const;
  106. };
  107. //==============================================================================
  108. class PathPointComponent : public ElementSiblingComponent
  109. {
  110. public:
  111. PathPointComponent (PaintElementPath* const path_,
  112. const int index, const int pointNumber);
  113. ~PathPointComponent();
  114. void updatePosition();
  115. void showPopupMenu();
  116. void paint (Graphics& g);
  117. void mouseDown (const MouseEvent& e);
  118. void mouseDrag (const MouseEvent& e);
  119. void mouseUp (const MouseEvent& e);
  120. void changeListenerCallback (ChangeBroadcaster*);
  121. private:
  122. PaintElementPath* const path;
  123. PaintRoutine* const routine;
  124. const int index;
  125. const int pointNumber;
  126. int dragX, dragY;
  127. bool selected, dragging, mouseDownSelectStatus;
  128. };
  129. #endif // __JUCER_PAINTELEMENTPATH_JUCEHEADER__