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.

178 lines
6.8KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library - "Jules' Utility Class Extensions"
  4. Copyright 2004-11 by Raw Material Software Ltd.
  5. ------------------------------------------------------------------------------
  6. JUCE can be redistributed and/or modified under the terms of the GNU General
  7. Public License (Version 2), as published by the Free Software Foundation.
  8. A copy of the license is included in the JUCE distribution, or can be found
  9. online at www.gnu.org/licenses.
  10. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  11. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  12. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  13. ------------------------------------------------------------------------------
  14. To release a closed-source product which uses JUCE, commercial licenses are
  15. available: visit www.rawmaterialsoftware.com/juce for more information.
  16. ==============================================================================
  17. */
  18. #ifndef __JUCER_PAINTELEMENTPATH_JUCEHEADER__
  19. #define __JUCER_PAINTELEMENTPATH_JUCEHEADER__
  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*>& properties);
  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*>& properties);
  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. };
  130. #endif // __JUCER_PAINTELEMENTPATH_JUCEHEADER__