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.

142 lines
6.1KB

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