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 7.2KB

9 years ago
8 years ago
8 years ago
8 years ago
8 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2015 - ROLI 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. int distanceFromTarget = 15, int arrowLength = 10);
  75. /** Moves and resizes the bubble to point at a given point.
  76. This will resize the bubble to fit its content, then position it
  77. so that the tip of the bubble points to the given coordinate. The coordinates
  78. are relative to either the bubble component's parent component if it has one, or
  79. they are screen coordinates if not.
  80. It'll put itself either above, below, or to the side of this point, depending
  81. on where there's the most space, honouring any restrictions that were set
  82. with setAllowedPlacement().
  83. */
  84. void setPosition (Point<int> arrowTipPosition, int arrowLength = 10);
  85. /** Moves and resizes the bubble to point at a given rectangle.
  86. This will resize the bubble to fit its content, then find a position for it
  87. so that it's next to, but doesn't overlap the given rectangle. The rectangle's
  88. coordinates are relative to either the bubble component's parent component
  89. if it has one, or they are screen coordinates if not.
  90. It'll put itself either above, below, or to the side of the component depending
  91. on where there's the most space, honouring any restrictions that were set
  92. with setAllowedPlacement().
  93. distanceFromTarget is the amount of space to leave between the bubble and the
  94. target rectangle, and arrowLength is the length of the arrow that it will draw.
  95. */
  96. void setPosition (Rectangle<int> rectangleToPointTo,
  97. int distanceFromTarget = 15, int arrowLength = 10);
  98. //==============================================================================
  99. /** A set of colour IDs to use to change the colour of various aspects of the bubble component.
  100. These constants can be used either via the Component::setColour(), or LookAndFeel::setColour()
  101. methods.
  102. @see Component::setColour, Component::findColour, LookAndFeel::setColour, LookAndFeel::findColour
  103. */
  104. enum ColourIds
  105. {
  106. backgroundColourId = 0x1000af0, /**< A background colour to fill the bubble with. */
  107. outlineColourId = 0x1000af1 /**< The colour to use for an outline around the bubble. */
  108. };
  109. //==============================================================================
  110. /** This abstract base class is implemented by LookAndFeel classes.
  111. */
  112. struct JUCE_API LookAndFeelMethods
  113. {
  114. virtual ~LookAndFeelMethods() {}
  115. virtual void drawBubble (Graphics&, BubbleComponent&,
  116. const Point<float>& positionOfTip,
  117. const Rectangle<float>& body) = 0;
  118. };
  119. protected:
  120. //==============================================================================
  121. /** Subclasses should override this to return the size of the content they
  122. want to draw inside the bubble.
  123. */
  124. virtual void getContentSize (int& width, int& height) = 0;
  125. /** Subclasses should override this to draw their bubble's contents.
  126. The graphics object's clip region and the dimensions passed in here are
  127. set up to paint just the rectangle inside the bubble.
  128. */
  129. virtual void paintContent (Graphics& g, int width, int height) = 0;
  130. public:
  131. /** @internal */
  132. void paint (Graphics&) override;
  133. private:
  134. Rectangle<int> content;
  135. Point<int> arrowTip;
  136. int allowablePlacements;
  137. DropShadowEffect shadow;
  138. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (BubbleComponent)
  139. };
  140. #endif // JUCE_BUBBLECOMPONENT_H_INCLUDED