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.

173 lines
6.4KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2015 - ROLI 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. #pragma once
  18. #include "jucer_ColouredElement.h"
  19. #include "jucer_ElementSiblingComponent.h"
  20. class PathPointComponent;
  21. class PaintElementPath;
  22. //==============================================================================
  23. class PathPoint
  24. {
  25. public:
  26. PathPoint (PaintElementPath* const owner);
  27. PathPoint (const PathPoint& other);
  28. PathPoint& operator= (const PathPoint& other);
  29. ~PathPoint();
  30. PaintElementPath* owner;
  31. Path::Iterator::PathElementType type;
  32. RelativePositionedRectangle pos [3];
  33. int getNumPoints() const;
  34. void changePointType (const Path::Iterator::PathElementType newType,
  35. const Rectangle<int>& parentArea,
  36. const bool undoable);
  37. void deleteFromPath();
  38. void getEditableProperties (Array<PropertyComponent*>& props);
  39. private:
  40. PathPoint withChangedPointType (const Path::Iterator::PathElementType newType,
  41. const Rectangle<int>& parentArea) const;
  42. };
  43. //==============================================================================
  44. class PaintElementPath : public ColouredElement
  45. {
  46. public:
  47. PaintElementPath (PaintRoutine* owner);
  48. ~PaintElementPath();
  49. //==============================================================================
  50. void setInitialBounds (int parentWidth, int parentHeight);
  51. Rectangle<int> getCurrentBounds (const Rectangle<int>& parentArea) const;
  52. void setCurrentBounds (const Rectangle<int>& b, const Rectangle<int>& parentArea, const bool undoable);
  53. //==============================================================================
  54. bool getPoint (int index, int pointNumber, double& x, double& y, const Rectangle<int>& parentArea) const;
  55. void movePoint (int index, int pointNumber, double newX, double newY, const Rectangle<int>& parentArea, const bool undoable);
  56. RelativePositionedRectangle getPoint (int index, int pointNumber) const;
  57. void setPoint (int index, int pointNumber, const RelativePositionedRectangle& newPoint, const bool undoable);
  58. int getNumPoints() const noexcept { return points.size(); }
  59. PathPoint* getPoint (int index) const noexcept { return points [index]; }
  60. int indexOfPoint (PathPoint* const p) const noexcept { return points.indexOf (p); }
  61. PathPoint* addPoint (int pointIndexToAddItAfter, const bool undoable);
  62. void deletePoint (int pointIndex, const bool undoable);
  63. void pointListChanged();
  64. int findSegmentAtXY (int x, int y) const;
  65. //==============================================================================
  66. bool isSubpathClosed (int pointIndex) const;
  67. void setSubpathClosed (int pointIndex, const bool closed, const bool undoable);
  68. bool isNonZeroWinding() const noexcept { return nonZeroWinding; }
  69. void setNonZeroWinding (const bool nonZero, const bool undoable);
  70. //==============================================================================
  71. void getEditableProperties (Array<PropertyComponent*>& props);
  72. void fillInGeneratedCode (GeneratedCode& code, String& paintMethodCode);
  73. //==============================================================================
  74. static const char* getTagName() noexcept { return "PATH"; }
  75. XmlElement* createXml() const;
  76. bool loadFromXml (const XmlElement& xml);
  77. void setToPath (const Path& p);
  78. //==============================================================================
  79. void draw (Graphics& g, const ComponentLayout* layout, const Rectangle<int>& parentArea);
  80. void drawExtraEditorGraphics (Graphics& g, const Rectangle<int>& relativeTo);
  81. void resized();
  82. void parentSizeChanged();
  83. void mouseDown (const MouseEvent& e);
  84. void mouseDrag (const MouseEvent& e);
  85. void mouseUp (const MouseEvent& e);
  86. void createSiblingComponents();
  87. void changed();
  88. private:
  89. friend class PathPoint;
  90. friend class PathPointComponent;
  91. OwnedArray <PathPoint> points;
  92. bool nonZeroWinding;
  93. mutable Path path;
  94. mutable Rectangle<int> lastPathBounds;
  95. int mouseDownOnSegment;
  96. bool mouseDownSelectSegmentStatus;
  97. String pathToString() const;
  98. void restorePathFromString (const String& s);
  99. void updateStoredPath (const ComponentLayout* layout, const Rectangle<int>& parentArea) const;
  100. int getBorderSize() const;
  101. void rescalePoint (RelativePositionedRectangle& pos, int dx, int dy,
  102. double scaleX, double scaleY,
  103. double scaleStartX, double scaleStartY,
  104. const Rectangle<int>& parentArea) const;
  105. };
  106. //==============================================================================
  107. class PathPointComponent : public ElementSiblingComponent
  108. {
  109. public:
  110. PathPointComponent (PaintElementPath* const path_,
  111. const int index, const int pointNumber);
  112. ~PathPointComponent();
  113. void updatePosition();
  114. void showPopupMenu();
  115. void paint (Graphics& g);
  116. void mouseDown (const MouseEvent& e);
  117. void mouseDrag (const MouseEvent& e);
  118. void mouseUp (const MouseEvent& e);
  119. void changeListenerCallback (ChangeBroadcaster*);
  120. private:
  121. PaintElementPath* const path;
  122. PaintRoutine* const routine;
  123. const int index;
  124. const int pointNumber;
  125. int dragX, dragY;
  126. bool selected, dragging, mouseDownSelectStatus;
  127. };