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.

119 lines
5.1KB

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