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.

160 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. //==============================================================================
  21. /**
  22. A drawable object which acts as a container for a set of other Drawables.
  23. Note that although this is a Component, it takes ownership of its child components
  24. and will delete them, so that you can use it as a self-contained graphic object.
  25. The intention is that you should not add your own components to it, only add other
  26. Drawable objects.
  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&);
  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 override;
  80. /** @internal */
  81. void refreshFromValueTree (const ValueTree&, ComponentBuilder&);
  82. /** @internal */
  83. ValueTree createValueTree (ComponentBuilder::ImageProvider* imageProvider) const override;
  84. /** @internal */
  85. static const Identifier valueTreeType;
  86. /** @internal */
  87. Rectangle<float> getDrawableBounds() const override;
  88. /** @internal */
  89. void childBoundsChanged (Component*) override;
  90. /** @internal */
  91. void childrenChanged() override;
  92. /** @internal */
  93. void parentHierarchyChanged() override;
  94. /** @internal */
  95. MarkerList* getMarkers (bool xAxis) override;
  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. };