juce_DrawableComposite.h 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  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. #ifndef JUCE_DRAWABLECOMPOSITE_H_INCLUDED
  18. #define JUCE_DRAWABLECOMPOSITE_H_INCLUDED
  19. //==============================================================================
  20. /**
  21. A drawable object which acts as a container for a set of other Drawables.
  22. Note that although this is a Component, it takes ownership of its child components
  23. and will delete them, so that you can use it as a self-contained graphic object.
  24. The intention is that you should not add your own components to it, only add other
  25. Drawable objects.
  26. @see Drawable
  27. */
  28. class JUCE_API DrawableComposite : public Drawable
  29. {
  30. public:
  31. //==============================================================================
  32. /** Creates a composite Drawable. */
  33. DrawableComposite();
  34. /** Creates a copy of a DrawableComposite. */
  35. DrawableComposite (const DrawableComposite&);
  36. /** Destructor. */
  37. ~DrawableComposite();
  38. //==============================================================================
  39. /** Sets the parallelogram that defines the target position of the content rectangle when the drawable is rendered.
  40. @see setContentArea
  41. */
  42. void setBoundingBox (const RelativeParallelogram& newBoundingBox);
  43. /** Returns the parallelogram that defines the target position of the content rectangle when the drawable is rendered.
  44. @see setBoundingBox
  45. */
  46. const RelativeParallelogram& getBoundingBox() const noexcept { return bounds; }
  47. /** Changes the bounding box transform to match the content area, so that any sub-items will
  48. be drawn at their untransformed positions.
  49. */
  50. void resetBoundingBoxToContentArea();
  51. /** Returns the main content rectangle.
  52. The content area is actually defined by the markers named "left", "right", "top" and
  53. "bottom", but this method is a shortcut that returns them all at once.
  54. @see contentLeftMarkerName, contentRightMarkerName, contentTopMarkerName, contentBottomMarkerName
  55. */
  56. RelativeRectangle getContentArea() const;
  57. /** Changes the main content area.
  58. The content area is actually defined by the markers named "left", "right", "top" and
  59. "bottom", but this method is a shortcut that sets them all at once.
  60. @see setBoundingBox, contentLeftMarkerName, contentRightMarkerName, contentTopMarkerName, contentBottomMarkerName
  61. */
  62. void setContentArea (const RelativeRectangle& newArea);
  63. /** Resets the content area and the bounding transform to fit around the area occupied
  64. by the child components (ignoring any markers).
  65. */
  66. void resetContentAreaAndBoundingBoxToFitChildren();
  67. //==============================================================================
  68. /** The name of the marker that defines the left edge of the content area. */
  69. static const char* const contentLeftMarkerName;
  70. /** The name of the marker that defines the right edge of the content area. */
  71. static const char* const contentRightMarkerName;
  72. /** The name of the marker that defines the top edge of the content area. */
  73. static const char* const contentTopMarkerName;
  74. /** The name of the marker that defines the bottom edge of the content area. */
  75. static const char* const contentBottomMarkerName;
  76. //==============================================================================
  77. /** @internal */
  78. Drawable* createCopy() const override;
  79. /** @internal */
  80. void refreshFromValueTree (const ValueTree&, ComponentBuilder&);
  81. /** @internal */
  82. ValueTree createValueTree (ComponentBuilder::ImageProvider* imageProvider) const override;
  83. /** @internal */
  84. static const Identifier valueTreeType;
  85. /** @internal */
  86. Rectangle<float> getDrawableBounds() const override;
  87. /** @internal */
  88. void childBoundsChanged (Component*) override;
  89. /** @internal */
  90. void childrenChanged() override;
  91. /** @internal */
  92. void parentHierarchyChanged() override;
  93. /** @internal */
  94. MarkerList* getMarkers (bool xAxis) override;
  95. //==============================================================================
  96. /** Internally-used class for wrapping a DrawableComposite's state into a ValueTree. */
  97. class ValueTreeWrapper : public Drawable::ValueTreeWrapperBase
  98. {
  99. public:
  100. ValueTreeWrapper (const ValueTree& state);
  101. ValueTree getChildList() const;
  102. ValueTree getChildListCreating (UndoManager* undoManager);
  103. RelativeParallelogram getBoundingBox() const;
  104. void setBoundingBox (const RelativeParallelogram& newBounds, UndoManager* undoManager);
  105. void resetBoundingBoxToContentArea (UndoManager* undoManager);
  106. RelativeRectangle getContentArea() const;
  107. void setContentArea (const RelativeRectangle& newArea, UndoManager* undoManager);
  108. MarkerList::ValueTreeWrapper getMarkerList (bool xAxis) const;
  109. MarkerList::ValueTreeWrapper getMarkerListCreating (bool xAxis, UndoManager* undoManager);
  110. static const Identifier topLeft, topRight, bottomLeft;
  111. private:
  112. static const Identifier childGroupTag, markerGroupTagX, markerGroupTagY;
  113. };
  114. private:
  115. //==============================================================================
  116. RelativeParallelogram bounds;
  117. MarkerList markersX, markersY;
  118. bool updateBoundsReentrant;
  119. friend class Drawable::Positioner<DrawableComposite>;
  120. bool registerCoordinates (RelativeCoordinatePositionerBase&);
  121. void recalculateCoordinates (Expression::Scope*);
  122. void updateBoundsToFitChildren();
  123. DrawableComposite& operator= (const DrawableComposite&);
  124. JUCE_LEAK_DETECTOR (DrawableComposite)
  125. };
  126. #endif // JUCE_DRAWABLECOMPOSITE_H_INCLUDED