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.

180 lines
6.9KB

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