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.

168 lines
6.4KB

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