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 x the x co-ordinate of end of the bubble's tail
  51. @param y the y co-ordinate of end of the bubble's tail
  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 (int x, int y,
  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);
  88. /** @internal */
  89. void paintContent (Graphics& g, int w, int h);
  90. /** @internal */
  91. void timerCallback();
  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 numMillisecondsBeforeRemoving,
  100. bool removeWhenMouseClicked,
  101. bool deleteSelfAfterUse);
  102. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (BubbleMessageComponent);
  103. };
  104. #endif // __JUCE_BUBBLEMESSAGECOMPONENT_JUCEHEADER__