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

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2017 - ROLI Ltd.
  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 5 End-User License
  8. Agreement and JUCE 5 Privacy Policy (both updated and effective as of the
  9. 27th April 2017).
  10. End User License Agreement: www.juce.com/juce-5-licence
  11. Privacy Policy: www.juce.com/juce-5-privacy-policy
  12. Or: You may also use this code under the terms of the GPL v3 (see
  13. www.gnu.org/licenses).
  14. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  15. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  16. DISCLAIMED.
  17. ==============================================================================
  18. */
  19. #pragma once
  20. #include "jucer_ColouredElement.h"
  21. #include "jucer_ElementSiblingComponent.h"
  22. class PathPointComponent;
  23. class PaintElementPath;
  24. //==============================================================================
  25. class PathPoint
  26. {
  27. public:
  28. PathPoint (PaintElementPath* const owner);
  29. PathPoint (const PathPoint& other);
  30. PathPoint& operator= (const PathPoint& other);
  31. ~PathPoint();
  32. PaintElementPath* owner;
  33. Path::Iterator::PathElementType type;
  34. RelativePositionedRectangle pos [3];
  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);
  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();
  51. //==============================================================================
  52. void setInitialBounds (int parentWidth, int parentHeight);
  53. Rectangle<int> getCurrentBounds (const Rectangle<int>& parentArea) const;
  54. void setCurrentBounds (const Rectangle<int>& b, const Rectangle<int>& parentArea, const bool undoable);
  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);
  74. void fillInGeneratedCode (GeneratedCode& code, String& paintMethodCode);
  75. //==============================================================================
  76. static const char* getTagName() noexcept { return "PATH"; }
  77. XmlElement* createXml() const;
  78. bool loadFromXml (const XmlElement& xml);
  79. void setToPath (const Path& p);
  80. //==============================================================================
  81. void draw (Graphics& g, const ComponentLayout* layout, const Rectangle<int>& parentArea);
  82. void drawExtraEditorGraphics (Graphics& g, const Rectangle<int>& relativeTo);
  83. void resized();
  84. void parentSizeChanged();
  85. void mouseDown (const MouseEvent& e);
  86. void mouseDrag (const MouseEvent& e);
  87. void mouseUp (const MouseEvent& e);
  88. void createSiblingComponents();
  89. void changed();
  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 pathToString() const;
  100. void restorePathFromString (const String& s);
  101. void updateStoredPath (const ComponentLayout* layout, const Rectangle<int>& parentArea) const;
  102. int getBorderSize() const;
  103. void rescalePoint (RelativePositionedRectangle& pos, int dx, int dy,
  104. double scaleX, double scaleY,
  105. double scaleStartX, double scaleStartY,
  106. const Rectangle<int>& parentArea) const;
  107. };
  108. //==============================================================================
  109. class PathPointComponent : public ElementSiblingComponent
  110. {
  111. public:
  112. PathPointComponent (PaintElementPath* const path_,
  113. const int index, const int pointNumber);
  114. ~PathPointComponent();
  115. void updatePosition();
  116. void showPopupMenu();
  117. void paint (Graphics& g);
  118. void mouseDown (const MouseEvent& e);
  119. void mouseDrag (const MouseEvent& e);
  120. void mouseUp (const MouseEvent& e);
  121. void changeListenerCallback (ChangeBroadcaster*);
  122. private:
  123. PaintElementPath* const path;
  124. PaintRoutine* const routine;
  125. const int index;
  126. const int pointNumber;
  127. int dragX, dragY;
  128. bool selected, dragging, mouseDownSelectStatus;
  129. };