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_BubbleComponent.h 6.9KB

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