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.

131 lines
5.6KB

  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 speech-bubble component that displays a short message.
  24. This can be used to show a message with the tail of the speech bubble
  25. pointing to a particular component or location on the screen.
  26. @see BubbleComponent
  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();
  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. For details about exactly how it decides where to position itself, see
  50. BubbleComponent::updatePosition().
  51. @param position the coords of the object to point to
  52. @param message the text to display
  53. @param numMillisecondsBeforeRemoving how long to leave it on the screen before removing itself
  54. from its parent compnent. If this is 0 or less, it
  55. will stay there until manually removed.
  56. @param removeWhenMouseClicked if this is true, the bubble will disappear as soon as a
  57. mouse button is pressed (anywhere on the screen)
  58. @param deleteSelfAfterUse if true, then the component will delete itself after
  59. it becomes invisible
  60. */
  61. void showAt (const Rectangle<int>& position,
  62. const AttributedString& message,
  63. int numMillisecondsBeforeRemoving,
  64. bool removeWhenMouseClicked = true,
  65. bool deleteSelfAfterUse = false);
  66. /** Shows a message bubble next to a particular component.
  67. This shows the bubble with its stem pointing at the given component.
  68. For details about exactly how it decides where to position itself, see
  69. BubbleComponent::updatePosition().
  70. @param component the component that you want to point at
  71. @param message the text to display
  72. @param numMillisecondsBeforeRemoving how long to leave it on the screen before removing itself
  73. from its parent compnent. If this is 0 or less, it
  74. will stay there until manually removed.
  75. @param removeWhenMouseClicked if this is true, the bubble will disappear as soon as a
  76. mouse button is pressed (anywhere on the screen)
  77. @param deleteSelfAfterUse if true, then the component will delete itself after
  78. it becomes invisible
  79. */
  80. void showAt (Component* component,
  81. const AttributedString& message,
  82. int numMillisecondsBeforeRemoving,
  83. bool removeWhenMouseClicked = true,
  84. bool deleteSelfAfterUse = false);
  85. //==============================================================================
  86. /** @internal */
  87. void getContentSize (int& w, int& h) override;
  88. /** @internal */
  89. void paintContent (Graphics& g, int w, int h) override;
  90. /** @internal */
  91. void timerCallback() override;
  92. private:
  93. //==============================================================================
  94. int fadeOutLength, mouseClickCounter;
  95. TextLayout textLayout;
  96. int64 expiryTime;
  97. bool deleteAfterUse;
  98. void createLayout (const AttributedString&);
  99. void init (int, bool, bool);
  100. void hide (bool fadeOut);
  101. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (BubbleMessageComponent)
  102. };
  103. } // namespace juce