Audio plugin host https://kx.studio/carla
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.

juce_DrawableComposite.h 6.6KB

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