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.

132 lines
5.5KB

  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_H_INCLUDED
  18. #define JUCE_TOOLTIPWINDOW_H_INCLUDED
  19. //==============================================================================
  20. /**
  21. A window that displays a pop-up tooltip when the mouse hovers over another component.
  22. To enable tooltips in your app, just create a single instance of a TooltipWindow
  23. object. Note that if you instantiate more than one instance of this class, you'll
  24. end up with multiple tooltips being shown!
  25. The TooltipWindow object will then stay invisible, waiting until the mouse
  26. hovers for the specified length of time - it will then see if it's currently
  27. over a component which implements the TooltipClient interface, and if so,
  28. it will make itself visible to show the tooltip in the appropriate place.
  29. @see TooltipClient, SettableTooltipClient
  30. */
  31. class JUCE_API TooltipWindow : public Component,
  32. private Timer
  33. {
  34. public:
  35. //==============================================================================
  36. /** Creates a tooltip window.
  37. Make sure your app only creates one instance of this class, otherwise you'll
  38. get multiple overlaid tooltips appearing. The window will initially be invisible
  39. and will make itself visible when it needs to display a tip.
  40. To change the style of tooltips, see the LookAndFeel class for its tooltip
  41. methods.
  42. @param parentComponent if set to 0, the TooltipWindow will appear on the desktop,
  43. otherwise the tooltip will be added to the given parent
  44. component.
  45. @param millisecondsBeforeTipAppears the time for which the mouse has to stay still
  46. before a tooltip will be shown
  47. @see TooltipClient, LookAndFeel::drawTooltip, LookAndFeel::getTooltipSize
  48. */
  49. explicit TooltipWindow (Component* parentComponent = nullptr,
  50. int millisecondsBeforeTipAppears = 700);
  51. /** Destructor. */
  52. ~TooltipWindow();
  53. //==============================================================================
  54. /** Changes the time before the tip appears.
  55. This lets you change the value that was set in the constructor.
  56. */
  57. void setMillisecondsBeforeTipAppears (int newTimeMs = 700) noexcept;
  58. /** Can be called to manually force a tip to be shown at a particular location. */
  59. void displayTip (Point<int> screenPosition, const String& text);
  60. /** Can be called to manually hide the tip if it's showing. */
  61. void hideTip();
  62. //==============================================================================
  63. /** A set of colour IDs to use to change the colour of various aspects of the tooltip.
  64. These constants can be used either via the Component::setColour(), or LookAndFeel::setColour()
  65. methods.
  66. @see Component::setColour, Component::findColour, LookAndFeel::setColour, LookAndFeel::findColour
  67. */
  68. enum ColourIds
  69. {
  70. backgroundColourId = 0x1001b00, /**< The colour to fill the background with. */
  71. textColourId = 0x1001c00, /**< The colour to use for the text. */
  72. outlineColourId = 0x1001c10 /**< The colour to use to draw an outline around the tooltip. */
  73. };
  74. //==============================================================================
  75. /** This abstract base class is implemented by LookAndFeel classes to provide
  76. window drawing functionality.
  77. */
  78. struct JUCE_API LookAndFeelMethods
  79. {
  80. virtual ~LookAndFeelMethods() {}
  81. virtual void getTooltipSize (const String& tipText, int& width, int& height) = 0;
  82. virtual void drawTooltip (Graphics&, const String& text, int width, int height) = 0;
  83. };
  84. private:
  85. //==============================================================================
  86. int millisecondsBeforeTipAppears;
  87. Point<float> lastMousePos;
  88. int mouseClicks, mouseWheelMoves;
  89. unsigned int lastCompChangeTime, lastHideTime;
  90. Component* lastComponentUnderMouse;
  91. String tipShowing, lastTipUnderMouse;
  92. void paint (Graphics&) override;
  93. void mouseEnter (const MouseEvent&) override;
  94. void timerCallback() override;
  95. void updatePosition (const String&, Point<int>, const Rectangle<int>&);
  96. static String getTipFor (Component*);
  97. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (TooltipWindow)
  98. };
  99. #endif // JUCE_TOOLTIPWINDOW_H_INCLUDED