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_BubbleMessageComponent.h 5.7KB

9 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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_BUBBLEMESSAGECOMPONENT_H_INCLUDED
  18. #define JUCE_BUBBLEMESSAGECOMPONENT_H_INCLUDED
  19. //==============================================================================
  20. /**
  21. A speech-bubble component that displays a short message.
  22. This can be used to show a message with the tail of the speech bubble
  23. pointing to a particular component or location on the screen.
  24. @see BubbleComponent
  25. */
  26. class JUCE_API BubbleMessageComponent : public BubbleComponent,
  27. private Timer
  28. {
  29. public:
  30. //==============================================================================
  31. /** Creates a bubble component.
  32. After creating one a BubbleComponent, do the following:
  33. - add it to an appropriate parent component, or put it on the
  34. desktop with Component::addToDesktop (0).
  35. - use the showAt() method to show a message.
  36. - it will make itself invisible after it times-out (and can optionally
  37. also delete itself), or you can reuse it somewhere else by calling
  38. showAt() again.
  39. */
  40. BubbleMessageComponent (int fadeOutLengthMs = 150);
  41. /** Destructor. */
  42. ~BubbleMessageComponent();
  43. //==============================================================================
  44. /** Shows a message bubble at a particular position.
  45. This shows the bubble with its stem pointing to the given location
  46. (coordinates being relative to its parent component).
  47. For details about exactly how it decides where to position itself, see
  48. BubbleComponent::updatePosition().
  49. @param position the coords of the object to point to
  50. @param message the text to display
  51. @param numMillisecondsBeforeRemoving how long to leave it on the screen before removing itself
  52. from its parent compnent. If this is 0 or less, it
  53. will stay there until manually removed.
  54. @param removeWhenMouseClicked if this is true, the bubble will disappear as soon as a
  55. mouse button is pressed (anywhere on the screen)
  56. @param deleteSelfAfterUse if true, then the component will delete itself after
  57. it becomes invisible
  58. */
  59. void showAt (const Rectangle<int>& position,
  60. const AttributedString& message,
  61. int numMillisecondsBeforeRemoving,
  62. bool removeWhenMouseClicked = true,
  63. bool deleteSelfAfterUse = false);
  64. /** Shows a message bubble next to a particular component.
  65. This shows the bubble with its stem pointing at the given component.
  66. For details about exactly how it decides where to position itself, see
  67. BubbleComponent::updatePosition().
  68. @param component the component that you want to point at
  69. @param message the text to display
  70. @param numMillisecondsBeforeRemoving how long to leave it on the screen before removing itself
  71. from its parent compnent. If this is 0 or less, it
  72. will stay there until manually removed.
  73. @param removeWhenMouseClicked if this is true, the bubble will disappear as soon as a
  74. mouse button is pressed (anywhere on the screen)
  75. @param deleteSelfAfterUse if true, then the component will delete itself after
  76. it becomes invisible
  77. */
  78. void showAt (Component* component,
  79. const AttributedString& message,
  80. int numMillisecondsBeforeRemoving,
  81. bool removeWhenMouseClicked = true,
  82. bool deleteSelfAfterUse = false);
  83. //==============================================================================
  84. /** @internal */
  85. void getContentSize (int& w, int& h) override;
  86. /** @internal */
  87. void paintContent (Graphics& g, int w, int h) override;
  88. /** @internal */
  89. void timerCallback() override;
  90. private:
  91. //==============================================================================
  92. int fadeOutLength, mouseClickCounter;
  93. TextLayout textLayout;
  94. int64 expiryTime;
  95. bool deleteAfterUse;
  96. void createLayout (const AttributedString&);
  97. void init (int, bool, bool);
  98. void hide (bool fadeOut);
  99. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (BubbleMessageComponent)
  100. };
  101. #endif // JUCE_BUBBLEMESSAGECOMPONENT_H_INCLUDED