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.

187 lines
7.2KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2022 - Raw Material Software Limited
  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 7 End-User License
  8. Agreement and JUCE Privacy Policy.
  9. End User License Agreement: www.juce.com/juce-7-licence
  10. Privacy Policy: www.juce.com/juce-privacy-policy
  11. Or: You may also use this code under the terms of the GPL v3 (see
  12. www.gnu.org/licenses).
  13. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  14. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  15. DISCLAIMED.
  16. ==============================================================================
  17. */
  18. namespace juce
  19. {
  20. //==============================================================================
  21. /**
  22. A component for showing a message or other graphics inside a speech-bubble-shaped
  23. outline, pointing at a location on the screen.
  24. This is a base class that just draws and positions the bubble shape, but leaves
  25. the drawing of any content up to a subclass. See BubbleMessageComponent for a subclass
  26. that draws a text message.
  27. To use it, create your subclass, then either add it to a parent component or
  28. put it on the desktop with addToDesktop (0), use setPosition() to
  29. resize and position it, then make it visible.
  30. @see BubbleMessageComponent
  31. @tags{GUI}
  32. */
  33. class JUCE_API BubbleComponent : public Component
  34. {
  35. protected:
  36. //==============================================================================
  37. /** Creates a BubbleComponent.
  38. Your subclass will need to implement the getContentSize() and paintContent()
  39. methods to draw the bubble's contents.
  40. */
  41. BubbleComponent();
  42. public:
  43. /** Destructor. */
  44. ~BubbleComponent() override;
  45. //==============================================================================
  46. /** A list of permitted placements for the bubble, relative to the coordinates
  47. at which it should be pointing.
  48. @see setAllowedPlacement
  49. */
  50. enum BubblePlacement
  51. {
  52. above = 1,
  53. below = 2,
  54. left = 4,
  55. right = 8
  56. };
  57. /** Tells the bubble which positions it's allowed to put itself in, relative to the
  58. point at which it's pointing.
  59. By default when setPosition() is called, the bubble will place itself either
  60. above, below, left, or right of the target area. You can pass in a bitwise-'or' of
  61. the values in BubblePlacement to restrict this choice.
  62. E.g. if you only want your bubble to appear above or below the target area,
  63. use setAllowedPlacement (above | below);
  64. @see BubblePlacement
  65. */
  66. void setAllowedPlacement (int newPlacement);
  67. //==============================================================================
  68. /** Moves and resizes the bubble to point at a given component.
  69. This will resize the bubble to fit its content, then find a position for it
  70. so that it's next to, but doesn't overlap the given component.
  71. It'll put itself either above, below, or to the side of the component depending
  72. on where there's the most space, honouring any restrictions that were set
  73. with setAllowedPlacement().
  74. */
  75. void setPosition (Component* componentToPointTo,
  76. int distanceFromTarget = 15, int arrowLength = 10);
  77. /** Moves and resizes the bubble to point at a given point.
  78. This will resize the bubble to fit its content, then position it
  79. so that the tip of the bubble points to the given coordinate. The coordinates
  80. are relative to either the bubble component's parent component if it has one, or
  81. they are screen coordinates if not.
  82. It'll put itself either above, below, or to the side of this point, depending
  83. on where there's the most space, honouring any restrictions that were set
  84. with setAllowedPlacement().
  85. */
  86. void setPosition (Point<int> arrowTipPosition, int arrowLength = 10);
  87. /** Moves and resizes the bubble to point at a given rectangle.
  88. This will resize the bubble to fit its content, then find a position for it
  89. so that it's next to, but doesn't overlap the given rectangle. The rectangle's
  90. coordinates are relative to either the bubble component's parent component
  91. if it has one, or they are screen coordinates if not.
  92. It'll put itself either above, below, or to the side of the component depending
  93. on where there's the most space, honouring any restrictions that were set
  94. with setAllowedPlacement().
  95. distanceFromTarget is the amount of space to leave between the bubble and the
  96. target rectangle, and arrowLength is the length of the arrow that it will draw.
  97. */
  98. void setPosition (Rectangle<int> rectangleToPointTo,
  99. int distanceFromTarget = 15, int arrowLength = 10);
  100. //==============================================================================
  101. /** A set of colour IDs to use to change the colour of various aspects of the bubble component.
  102. These constants can be used either via the Component::setColour(), or LookAndFeel::setColour()
  103. methods.
  104. @see Component::setColour, Component::findColour, LookAndFeel::setColour, LookAndFeel::findColour
  105. */
  106. enum ColourIds
  107. {
  108. backgroundColourId = 0x1000af0, /**< A background colour to fill the bubble with. */
  109. outlineColourId = 0x1000af1 /**< The colour to use for an outline around the bubble. */
  110. };
  111. //==============================================================================
  112. /** This abstract base class is implemented by LookAndFeel classes.
  113. */
  114. struct JUCE_API LookAndFeelMethods
  115. {
  116. virtual ~LookAndFeelMethods() = default;
  117. virtual void drawBubble (Graphics&, BubbleComponent&,
  118. const Point<float>& positionOfTip,
  119. const Rectangle<float>& body) = 0;
  120. };
  121. //==============================================================================
  122. /** @internal */
  123. void paint (Graphics&) override;
  124. protected:
  125. //==============================================================================
  126. /** Subclasses should override this to return the size of the content they
  127. want to draw inside the bubble.
  128. */
  129. virtual void getContentSize (int& width, int& height) = 0;
  130. /** Subclasses should override this to draw their bubble's contents.
  131. The graphics object's clip region and the dimensions passed in here are
  132. set up to paint just the rectangle inside the bubble.
  133. */
  134. virtual void paintContent (Graphics& g, int width, int height) = 0;
  135. private:
  136. Rectangle<int> content;
  137. Point<int> arrowTip;
  138. int allowablePlacements;
  139. DropShadowEffect shadow;
  140. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (BubbleComponent)
  141. };
  142. } // namespace juce