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.

120 lines
4.8KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2013 - Raw Material Software Ltd.
  5. Permission is granted to use this software under the terms of either:
  6. a) the GPL v2 (or any later version)
  7. b) the Affero GPL v3
  8. Details of these licenses can be found at: www.gnu.org/licenses
  9. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  10. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  11. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  12. ------------------------------------------------------------------------------
  13. To release a closed-source product which uses JUCE, commercial licenses are
  14. available: visit www.juce.com for more information.
  15. ==============================================================================
  16. */
  17. #ifndef __JUCE_TOOLTIPWINDOW_JUCEHEADER__
  18. #define __JUCE_TOOLTIPWINDOW_JUCEHEADER__
  19. #include "../components/juce_Component.h"
  20. #include "../mouse/juce_TooltipClient.h"
  21. //==============================================================================
  22. /**
  23. A window that displays a pop-up tooltip when the mouse hovers over another component.
  24. To enable tooltips in your app, just create a single instance of a TooltipWindow
  25. object. Note that if you instantiate more than one instance of this class, you'll
  26. end up with multiple tooltips being shown!
  27. The TooltipWindow object will then stay invisible, waiting until the mouse
  28. hovers for the specified length of time - it will then see if it's currently
  29. over a component which implements the TooltipClient interface, and if so,
  30. it will make itself visible to show the tooltip in the appropriate place.
  31. @see TooltipClient, SettableTooltipClient
  32. */
  33. class JUCE_API TooltipWindow : public Component,
  34. private Timer
  35. {
  36. public:
  37. //==============================================================================
  38. /** Creates a tooltip window.
  39. Make sure your app only creates one instance of this class, otherwise you'll
  40. get multiple overlaid tooltips appearing. The window will initially be invisible
  41. and will make itself visible when it needs to display a tip.
  42. To change the style of tooltips, see the LookAndFeel class for its tooltip
  43. methods.
  44. @param parentComponent if set to 0, the TooltipWindow will appear on the desktop,
  45. otherwise the tooltip will be added to the given parent
  46. component.
  47. @param millisecondsBeforeTipAppears the time for which the mouse has to stay still
  48. before a tooltip will be shown
  49. @see TooltipClient, LookAndFeel::drawTooltip, LookAndFeel::getTooltipSize
  50. */
  51. explicit TooltipWindow (Component* parentComponent = nullptr,
  52. int millisecondsBeforeTipAppears = 700);
  53. /** Destructor. */
  54. ~TooltipWindow();
  55. //==============================================================================
  56. /** Changes the time before the tip appears.
  57. This lets you change the value that was set in the constructor.
  58. */
  59. void setMillisecondsBeforeTipAppears (int newTimeMs = 700) noexcept;
  60. //==============================================================================
  61. /** A set of colour IDs to use to change the colour of various aspects of the tooltip.
  62. These constants can be used either via the Component::setColour(), or LookAndFeel::setColour()
  63. methods.
  64. @see Component::setColour, Component::findColour, LookAndFeel::setColour, LookAndFeel::findColour
  65. */
  66. enum ColourIds
  67. {
  68. backgroundColourId = 0x1001b00, /**< The colour to fill the background with. */
  69. textColourId = 0x1001c00, /**< The colour to use for the text. */
  70. outlineColourId = 0x1001c10 /**< The colour to use to draw an outline around the tooltip. */
  71. };
  72. private:
  73. //==============================================================================
  74. int millisecondsBeforeTipAppears;
  75. Point<int> lastMousePos;
  76. int mouseClicks, mouseWheelMoves;
  77. unsigned int lastCompChangeTime, lastHideTime;
  78. Component* lastComponentUnderMouse;
  79. bool changedCompsSinceShown;
  80. String tipShowing, lastTipUnderMouse;
  81. void paint (Graphics&) override;
  82. void mouseEnter (const MouseEvent&) override;
  83. void timerCallback() override;
  84. static String getTipFor (Component*);
  85. void showFor (const String&);
  86. void hide();
  87. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (TooltipWindow)
  88. };
  89. #endif // __JUCE_TOOLTIPWINDOW_JUCEHEADER__