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.

175 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. 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, bool multipleSelected);
  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() override;
  50. //==============================================================================
  51. void setInitialBounds (int parentWidth, int parentHeight) override;
  52. Rectangle<int> getCurrentBounds (const Rectangle<int>& parentArea) const override;
  53. void setCurrentBounds (const Rectangle<int>& b, const Rectangle<int>& parentArea, const bool undoable) override;
  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, bool multipleSelected) override;
  73. void fillInGeneratedCode (GeneratedCode& code, String& paintMethodCode) override;
  74. void applyCustomPaintSnippets (StringArray& snippets) override;
  75. //==============================================================================
  76. static const char* getTagName() noexcept { return "PATH"; }
  77. XmlElement* createXml() const override;
  78. bool loadFromXml (const XmlElement& xml) override;
  79. void setToPath (const Path& p);
  80. //==============================================================================
  81. void draw (Graphics& g, const ComponentLayout* layout, const Rectangle<int>& parentArea) override;
  82. void drawExtraEditorGraphics (Graphics& g, const Rectangle<int>& relativeTo) override;
  83. void resized() override;
  84. void parentSizeChanged() override;
  85. void mouseDown (const MouseEvent& e) override;
  86. void mouseDrag (const MouseEvent& e) override;
  87. void mouseUp (const MouseEvent& e) override;
  88. void createSiblingComponents() override;
  89. void changed() override;
  90. private:
  91. friend class PathPoint;
  92. friend class PathPointComponent;
  93. OwnedArray <PathPoint> points;
  94. bool nonZeroWinding;
  95. mutable Path path;
  96. mutable Rectangle<int> lastPathBounds;
  97. int mouseDownOnSegment;
  98. bool mouseDownSelectSegmentStatus;
  99. String customPaintCode;
  100. String pathToString() const;
  101. void restorePathFromString (const String& s);
  102. void updateStoredPath (const ComponentLayout* layout, const Rectangle<int>& parentArea) const;
  103. int getBorderSize() const;
  104. void rescalePoint (RelativePositionedRectangle& pos, int dx, int dy,
  105. double scaleX, double scaleY,
  106. double scaleStartX, double scaleStartY,
  107. const Rectangle<int>& parentArea) const;
  108. };
  109. //==============================================================================
  110. class PathPointComponent : public ElementSiblingComponent
  111. {
  112. public:
  113. PathPointComponent (PaintElementPath* const path_,
  114. const int index, const int pointNumber);
  115. ~PathPointComponent();
  116. void updatePosition();
  117. void showPopupMenu();
  118. void paint (Graphics& g);
  119. void mouseDown (const MouseEvent& e);
  120. void mouseDrag (const MouseEvent& e);
  121. void mouseUp (const MouseEvent& e);
  122. void changeListenerCallback (ChangeBroadcaster*);
  123. private:
  124. PaintElementPath* const path;
  125. PaintRoutine* const routine;
  126. const int index;
  127. const int pointNumber;
  128. int dragX, dragY;
  129. bool selected, dragging, mouseDownSelectStatus;
  130. };