The JUCE cross-platform C++ framework, with DISTRHO/KXStudio specific changes
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.

134 lines
6.0KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library - "Jules' Utility Class Extensions"
  4. Copyright 2004-11 by Raw Material Software Ltd.
  5. ------------------------------------------------------------------------------
  6. JUCE can be redistributed and/or modified under the terms of the GNU General
  7. Public License (Version 2), as published by the Free Software Foundation.
  8. A copy of the license is included in the JUCE distribution, or can be found
  9. online at www.gnu.org/licenses.
  10. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  11. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  12. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  13. ------------------------------------------------------------------------------
  14. To release a closed-source product which uses JUCE, commercial licenses are
  15. available: visit www.rawmaterialsoftware.com/juce for more information.
  16. ==============================================================================
  17. */
  18. #ifndef __JUCE_BUBBLEMESSAGECOMPONENT_JUCEHEADER__
  19. #define __JUCE_BUBBLEMESSAGECOMPONENT_JUCEHEADER__
  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. */
  27. class JUCE_API BubbleMessageComponent : public BubbleComponent,
  28. private Timer
  29. {
  30. public:
  31. //==============================================================================
  32. /** Creates a bubble component.
  33. After creating one a BubbleComponent, do the following:
  34. - add it to an appropriate parent component, or put it on the
  35. desktop with Component::addToDesktop (0).
  36. - use the showAt() method to show a message.
  37. - it will make itself invisible after it times-out (and can optionally
  38. also delete itself), or you can reuse it somewhere else by calling
  39. showAt() again.
  40. */
  41. BubbleMessageComponent (int fadeOutLengthMs = 150);
  42. /** Destructor. */
  43. ~BubbleMessageComponent();
  44. //==============================================================================
  45. /** Shows a message bubble at a particular position.
  46. This shows the bubble with its stem pointing to the given location
  47. (co-ordinates being relative to its parent component).
  48. For details about exactly how it decides where to position itself, see
  49. BubbleComponent::updatePosition().
  50. @param position the coords of the object to point to
  51. @param message the text to display
  52. @param numMillisecondsBeforeRemoving how long to leave it on the screen before removing itself
  53. from its parent compnent. If this is 0 or less, it
  54. will stay there until manually removed.
  55. @param removeWhenMouseClicked if this is true, the bubble will disappear as soon as a
  56. mouse button is pressed (anywhere on the screen)
  57. @param deleteSelfAfterUse if true, then the component will delete itself after
  58. it becomes invisible
  59. */
  60. void showAt (const Rectangle<int>& position,
  61. const AttributedString& message,
  62. int numMillisecondsBeforeRemoving,
  63. bool removeWhenMouseClicked = true,
  64. bool deleteSelfAfterUse = false);
  65. /** Shows a message bubble next to a particular component.
  66. This shows the bubble with its stem pointing at the given component.
  67. For details about exactly how it decides where to position itself, see
  68. BubbleComponent::updatePosition().
  69. @param component the component that you want to point at
  70. @param message the text to display
  71. @param numMillisecondsBeforeRemoving how long to leave it on the screen before removing itself
  72. from its parent compnent. If this is 0 or less, it
  73. will stay there until manually removed.
  74. @param removeWhenMouseClicked if this is true, the bubble will disappear as soon as a
  75. mouse button is pressed (anywhere on the screen)
  76. @param deleteSelfAfterUse if true, then the component will delete itself after
  77. it becomes invisible
  78. */
  79. void showAt (Component* component,
  80. const AttributedString& message,
  81. int numMillisecondsBeforeRemoving,
  82. bool removeWhenMouseClicked = true,
  83. bool deleteSelfAfterUse = false);
  84. //==============================================================================
  85. /** @internal */
  86. void getContentSize (int& w, int& h);
  87. /** @internal */
  88. void paintContent (Graphics& g, int w, int h);
  89. /** @internal */
  90. void timerCallback();
  91. private:
  92. //==============================================================================
  93. int fadeOutLength, mouseClickCounter;
  94. TextLayout textLayout;
  95. int64 expiryTime;
  96. bool deleteAfterUse;
  97. void createLayout (const AttributedString&);
  98. void init (int numMillisecondsBeforeRemoving,
  99. bool removeWhenMouseClicked,
  100. bool deleteSelfAfterUse);
  101. void hide (bool fadeOut);
  102. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (BubbleMessageComponent);
  103. };
  104. #endif // __JUCE_BUBBLEMESSAGECOMPONENT_JUCEHEADER__