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

  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. void applyCustomPaintSnippets (StringArray& snippets);
  76. //==============================================================================
  77. static const char* getTagName() noexcept { return "PATH"; }
  78. XmlElement* createXml() const;
  79. bool loadFromXml (const XmlElement& xml);
  80. void setToPath (const Path& p);
  81. //==============================================================================
  82. void draw (Graphics& g, const ComponentLayout* layout, const Rectangle<int>& parentArea);
  83. void drawExtraEditorGraphics (Graphics& g, const Rectangle<int>& relativeTo);
  84. void resized();
  85. void parentSizeChanged();
  86. void mouseDown (const MouseEvent& e);
  87. void mouseDrag (const MouseEvent& e);
  88. void mouseUp (const MouseEvent& e);
  89. void createSiblingComponents();
  90. void changed();
  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. };