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.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  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 component for showing a message or other graphics inside a speech-bubble-shaped
  24. outline, pointing at a location on the screen.
  25. This is a base class that just draws and positions the bubble shape, but leaves
  26. the drawing of any content up to a subclass. See BubbleMessageComponent for a subclass
  27. that draws a text message.
  28. To use it, create your subclass, then either add it to a parent component or
  29. put it on the desktop with addToDesktop (0), use setPosition() to
  30. resize and position it, then make it visible.
  31. @see BubbleMessageComponent
  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();
  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() {}
  117. virtual void drawBubble (Graphics&, BubbleComponent&,
  118. const Point<float>& positionOfTip,
  119. const Rectangle<float>& body) = 0;
  120. };
  121. protected:
  122. //==============================================================================
  123. /** Subclasses should override this to return the size of the content they
  124. want to draw inside the bubble.
  125. */
  126. virtual void getContentSize (int& width, int& height) = 0;
  127. /** Subclasses should override this to draw their bubble's contents.
  128. The graphics object's clip region and the dimensions passed in here are
  129. set up to paint just the rectangle inside the bubble.
  130. */
  131. virtual void paintContent (Graphics& g, int width, int height) = 0;
  132. public:
  133. /** @internal */
  134. void paint (Graphics&) override;
  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