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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2020 - Raw Material Software Limited
  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 6 End-User License
  8. Agreement and JUCE Privacy Policy (both effective as of the 16th June 2020).
  9. End User License Agreement: www.juce.com/juce-6-licence
  10. Privacy Policy: www.juce.com/juce-privacy-policy
  11. Or: You may also use this code under the terms of the GPL v3 (see
  12. www.gnu.org/licenses).
  13. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  14. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  15. DISCLAIMED.
  16. ==============================================================================
  17. */
  18. namespace juce
  19. {
  20. //==============================================================================
  21. /**
  22. A speech-bubble component that displays a short message.
  23. This can be used to show a message with the tail of the speech bubble
  24. pointing to a particular component or location on the screen.
  25. @see BubbleComponent
  26. @tags{GUI}
  27. */
  28. class JUCE_API BubbleMessageComponent : public BubbleComponent,
  29. private Timer
  30. {
  31. public:
  32. //==============================================================================
  33. /** Creates a bubble component.
  34. After creating one a BubbleComponent, do the following:
  35. - add it to an appropriate parent component, or put it on the
  36. desktop with Component::addToDesktop (0).
  37. - use the showAt() method to show a message.
  38. - it will make itself invisible after it times-out (and can optionally
  39. also delete itself), or you can reuse it somewhere else by calling
  40. showAt() again.
  41. */
  42. BubbleMessageComponent (int fadeOutLengthMs = 150);
  43. /** Destructor. */
  44. ~BubbleMessageComponent() override;
  45. //==============================================================================
  46. /** Shows a message bubble at a particular position.
  47. This shows the bubble with its stem pointing to the given location
  48. (coordinates being relative to its parent component).
  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 component. 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. @param component the component that you want to point at
  67. @param message the text to display
  68. @param numMillisecondsBeforeRemoving how long to leave it on the screen before removing itself
  69. from its parent component. If this is 0 or less, it
  70. will stay there until manually removed.
  71. @param removeWhenMouseClicked if this is true, the bubble will disappear as soon as a
  72. mouse button is pressed (anywhere on the screen)
  73. @param deleteSelfAfterUse if true, then the component will delete itself after
  74. it becomes invisible
  75. */
  76. void showAt (Component* component,
  77. const AttributedString& message,
  78. int numMillisecondsBeforeRemoving,
  79. bool removeWhenMouseClicked = true,
  80. bool deleteSelfAfterUse = false);
  81. //==============================================================================
  82. /** @internal */
  83. void getContentSize (int& w, int& h) override;
  84. /** @internal */
  85. void paintContent (Graphics& g, int w, int h) override;
  86. /** @internal */
  87. void timerCallback() override;
  88. private:
  89. //==============================================================================
  90. int fadeOutLength, mouseClickCounter;
  91. TextLayout textLayout;
  92. int64 expiryTime;
  93. bool deleteAfterUse;
  94. void createLayout (const AttributedString&);
  95. void init (int, bool, bool);
  96. void hide (bool fadeOut);
  97. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (BubbleMessageComponent)
  98. };
  99. } // namespace juce