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.

163 lines
6.7KB

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