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.

158 lines
6.5KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2015 - ROLI Ltd.
  5. Permission is granted to use this software under the terms of either:
  6. a) the GPL v2 (or any later version)
  7. b) the Affero GPL v3
  8. Details of these licenses can be found at: www.gnu.org/licenses
  9. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  10. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  11. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  12. ------------------------------------------------------------------------------
  13. To release a closed-source product which uses JUCE, commercial licenses are
  14. available: visit www.juce.com for more information.
  15. ==============================================================================
  16. */
  17. #pragma once
  18. //==============================================================================
  19. /**
  20. A drawable object which acts as a container for a set of other Drawables.
  21. Note that although this is a Component, it takes ownership of its child components
  22. and will delete them, so that you can use it as a self-contained graphic object.
  23. The intention is that you should not add your own components to it, only add other
  24. Drawable objects.
  25. @see Drawable
  26. */
  27. class JUCE_API DrawableComposite : public Drawable
  28. {
  29. public:
  30. //==============================================================================
  31. /** Creates a composite Drawable. */
  32. DrawableComposite();
  33. /** Creates a copy of a DrawableComposite. */
  34. DrawableComposite (const DrawableComposite&);
  35. /** Destructor. */
  36. ~DrawableComposite();
  37. //==============================================================================
  38. /** Sets the parallelogram that defines the target position of the content rectangle when the drawable is rendered.
  39. @see setContentArea
  40. */
  41. void setBoundingBox (const RelativeParallelogram& newBoundingBox);
  42. /** Returns the parallelogram that defines the target position of the content rectangle when the drawable is rendered.
  43. @see setBoundingBox
  44. */
  45. const RelativeParallelogram& getBoundingBox() const noexcept { return bounds; }
  46. /** Changes the bounding box transform to match the content area, so that any sub-items will
  47. be drawn at their untransformed positions.
  48. */
  49. void resetBoundingBoxToContentArea();
  50. /** Returns the main content rectangle.
  51. The content area is actually defined by the markers named "left", "right", "top" and
  52. "bottom", but this method is a shortcut that returns them all at once.
  53. @see contentLeftMarkerName, contentRightMarkerName, contentTopMarkerName, contentBottomMarkerName
  54. */
  55. RelativeRectangle getContentArea() const;
  56. /** Changes the main content area.
  57. The content area is actually defined by the markers named "left", "right", "top" and
  58. "bottom", but this method is a shortcut that sets them all at once.
  59. @see setBoundingBox, contentLeftMarkerName, contentRightMarkerName, contentTopMarkerName, contentBottomMarkerName
  60. */
  61. void setContentArea (const RelativeRectangle& newArea);
  62. /** Resets the content area and the bounding transform to fit around the area occupied
  63. by the child components (ignoring any markers).
  64. */
  65. void resetContentAreaAndBoundingBoxToFitChildren();
  66. //==============================================================================
  67. /** The name of the marker that defines the left edge of the content area. */
  68. static const char* const contentLeftMarkerName;
  69. /** The name of the marker that defines the right edge of the content area. */
  70. static const char* const contentRightMarkerName;
  71. /** The name of the marker that defines the top edge of the content area. */
  72. static const char* const contentTopMarkerName;
  73. /** The name of the marker that defines the bottom edge of the content area. */
  74. static const char* const contentBottomMarkerName;
  75. //==============================================================================
  76. /** @internal */
  77. Drawable* createCopy() const override;
  78. /** @internal */
  79. void refreshFromValueTree (const ValueTree&, ComponentBuilder&);
  80. /** @internal */
  81. ValueTree createValueTree (ComponentBuilder::ImageProvider* imageProvider) const override;
  82. /** @internal */
  83. static const Identifier valueTreeType;
  84. /** @internal */
  85. Rectangle<float> getDrawableBounds() const override;
  86. /** @internal */
  87. void childBoundsChanged (Component*) override;
  88. /** @internal */
  89. void childrenChanged() override;
  90. /** @internal */
  91. void parentHierarchyChanged() override;
  92. /** @internal */
  93. MarkerList* getMarkers (bool xAxis) override;
  94. //==============================================================================
  95. /** Internally-used class for wrapping a DrawableComposite's state into a ValueTree. */
  96. class ValueTreeWrapper : public Drawable::ValueTreeWrapperBase
  97. {
  98. public:
  99. ValueTreeWrapper (const ValueTree& state);
  100. ValueTree getChildList() const;
  101. ValueTree getChildListCreating (UndoManager* undoManager);
  102. RelativeParallelogram getBoundingBox() const;
  103. void setBoundingBox (const RelativeParallelogram& newBounds, UndoManager* undoManager);
  104. void resetBoundingBoxToContentArea (UndoManager* undoManager);
  105. RelativeRectangle getContentArea() const;
  106. void setContentArea (const RelativeRectangle& newArea, UndoManager* undoManager);
  107. MarkerList::ValueTreeWrapper getMarkerList (bool xAxis) const;
  108. MarkerList::ValueTreeWrapper getMarkerListCreating (bool xAxis, UndoManager* undoManager);
  109. static const Identifier topLeft, topRight, bottomLeft;
  110. private:
  111. static const Identifier childGroupTag, markerGroupTagX, markerGroupTagY;
  112. };
  113. private:
  114. //==============================================================================
  115. RelativeParallelogram bounds;
  116. MarkerList markersX, markersY;
  117. bool updateBoundsReentrant;
  118. friend class Drawable::Positioner<DrawableComposite>;
  119. bool registerCoordinates (RelativeCoordinatePositionerBase&);
  120. void recalculateCoordinates (Expression::Scope*);
  121. void updateBoundsToFitChildren();
  122. DrawableComposite& operator= (const DrawableComposite&);
  123. JUCE_LEAK_DETECTOR (DrawableComposite)
  124. };