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.7KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2020 - Raw Material Software Limited
  5. JUCE is an open source library subject to commercial or open-source
  6. licensing.
  7. By using JUCE, you agree to the terms of both the JUCE 6 End-User License
  8. Agreement and JUCE Privacy Policy (both effective as of the 16th June 2020).
  9. End User License Agreement: www.juce.com/juce-6-licence
  10. Privacy Policy: www.juce.com/juce-privacy-policy
  11. Or: You may also use this code under the terms of the GPL v3 (see
  12. www.gnu.org/licenses).
  13. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  14. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  15. DISCLAIMED.
  16. ==============================================================================
  17. */
  18. #pragma once
  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. static constexpr auto maxRects = 3;
  32. PaintElementPath* owner;
  33. Path::Iterator::PathElementType type;
  34. RelativePositionedRectangle pos [maxRects];
  35. int getNumPoints() const;
  36. void changePointType (const Path::Iterator::PathElementType newType,
  37. const Rectangle<int>& parentArea,
  38. const bool undoable);
  39. void deleteFromPath();
  40. void getEditableProperties (Array<PropertyComponent*>& props, bool multipleSelected);
  41. private:
  42. PathPoint withChangedPointType (const Path::Iterator::PathElementType newType,
  43. const Rectangle<int>& parentArea) const;
  44. };
  45. //==============================================================================
  46. class PaintElementPath : public ColouredElement
  47. {
  48. public:
  49. PaintElementPath (PaintRoutine* owner);
  50. ~PaintElementPath() override;
  51. //==============================================================================
  52. void setInitialBounds (int parentWidth, int parentHeight) override;
  53. Rectangle<int> getCurrentBounds (const Rectangle<int>& parentArea) const override;
  54. void setCurrentBounds (const Rectangle<int>& b, const Rectangle<int>& parentArea, const bool undoable) override;
  55. //==============================================================================
  56. bool getPoint (int index, int pointNumber, double& x, double& y, const Rectangle<int>& parentArea) const;
  57. void movePoint (int index, int pointNumber, double newX, double newY, const Rectangle<int>& parentArea, const bool undoable);
  58. RelativePositionedRectangle getPoint (int index, int pointNumber) const;
  59. void setPoint (int index, int pointNumber, const RelativePositionedRectangle& newPoint, const bool undoable);
  60. int getNumPoints() const noexcept { return points.size(); }
  61. PathPoint* getPoint (int index) const noexcept { return points [index]; }
  62. int indexOfPoint (PathPoint* const p) const noexcept { return points.indexOf (p); }
  63. PathPoint* addPoint (int pointIndexToAddItAfter, const bool undoable);
  64. void deletePoint (int pointIndex, const bool undoable);
  65. void pointListChanged();
  66. int findSegmentAtXY (int x, int y) const;
  67. //==============================================================================
  68. bool isSubpathClosed (int pointIndex) const;
  69. void setSubpathClosed (int pointIndex, const bool closed, const bool undoable);
  70. bool isNonZeroWinding() const noexcept { return nonZeroWinding; }
  71. void setNonZeroWinding (const bool nonZero, const bool undoable);
  72. //==============================================================================
  73. void getEditableProperties (Array<PropertyComponent*>& props, bool multipleSelected) override;
  74. void fillInGeneratedCode (GeneratedCode& code, String& paintMethodCode) override;
  75. void applyCustomPaintSnippets (StringArray& snippets) override;
  76. //==============================================================================
  77. static const char* getTagName() noexcept { return "PATH"; }
  78. XmlElement* createXml() const override;
  79. bool loadFromXml (const XmlElement& xml) override;
  80. void setToPath (const Path& p);
  81. //==============================================================================
  82. void draw (Graphics& g, const ComponentLayout* layout, const Rectangle<int>& parentArea) override;
  83. void drawExtraEditorGraphics (Graphics& g, const Rectangle<int>& relativeTo) override;
  84. void resized() override;
  85. void parentSizeChanged() override;
  86. void mouseDown (const MouseEvent& e) override;
  87. void mouseDrag (const MouseEvent& e) override;
  88. void mouseUp (const MouseEvent& e) override;
  89. void createSiblingComponents() override;
  90. void changed() override;
  91. private:
  92. friend class PathPoint;
  93. friend class PathPointComponent;
  94. OwnedArray<PathPoint> points;
  95. bool nonZeroWinding;
  96. mutable Path path;
  97. mutable Rectangle<int> lastPathBounds;
  98. int mouseDownOnSegment;
  99. bool mouseDownSelectSegmentStatus;
  100. String customPaintCode;
  101. String pathToString() const;
  102. void restorePathFromString (const String& s);
  103. void updateStoredPath (const ComponentLayout* layout, const Rectangle<int>& parentArea) const;
  104. int getBorderSize() const;
  105. void rescalePoint (RelativePositionedRectangle& pos, int dx, int dy,
  106. double scaleX, double scaleY,
  107. double scaleStartX, double scaleStartY,
  108. const Rectangle<int>& parentArea) const;
  109. };
  110. //==============================================================================
  111. class PathPointComponent : public ElementSiblingComponent
  112. {
  113. public:
  114. PathPointComponent (PaintElementPath* const path_,
  115. const int index, const int pointNumber);
  116. ~PathPointComponent();
  117. void updatePosition();
  118. void showPopupMenu();
  119. void paint (Graphics& g);
  120. void mouseDown (const MouseEvent& e);
  121. void mouseDrag (const MouseEvent& e);
  122. void mouseUp (const MouseEvent& e);
  123. void changeListenerCallback (ChangeBroadcaster*);
  124. private:
  125. PaintElementPath* const path;
  126. PaintRoutine* const routine;
  127. const int index;
  128. const int pointNumber;
  129. int dragX, dragY;
  130. bool selected, dragging, mouseDownSelectStatus;
  131. };