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.

juce_TooltipWindow.h 6.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2017 - ROLI Ltd.
  5. JUCE is an open source library subject to commercial or open-source
  6. licensing.
  7. By using JUCE, you agree to the terms of both the JUCE 5 End-User License
  8. Agreement and JUCE 5 Privacy Policy (both updated and effective as of the
  9. 27th April 2017).
  10. End User License Agreement: www.juce.com/juce-5-licence
  11. Privacy Policy: www.juce.com/juce-5-privacy-policy
  12. Or: You may also use this code under the terms of the GPL v3 (see
  13. www.gnu.org/licenses).
  14. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  15. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  16. DISCLAIMED.
  17. ==============================================================================
  18. */
  19. namespace juce
  20. {
  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! This is a common problem when compiling
  27. audio plug-ins with JUCE: depending on the way you instantiate TooltipWindow,
  28. you may end up with a TooltipWindow for each plug-in instance. To avoid this use a
  29. SharedResourcePointer to instantiate the TooltipWindow only once.
  30. The TooltipWindow object will then stay invisible, waiting until the mouse
  31. hovers for the specified length of time - it will then see if it's currently
  32. over a component which implements the TooltipClient interface, and if so,
  33. it will make itself visible to show the tooltip in the appropriate place.
  34. @see TooltipClient, SettableTooltipClient, SharedResourcePointer
  35. */
  36. class JUCE_API TooltipWindow : public Component,
  37. private Timer
  38. {
  39. public:
  40. //==============================================================================
  41. /** Creates a tooltip window.
  42. Make sure your app only creates one instance of this class, otherwise you'll
  43. get multiple overlaid tooltips appearing. The window will initially be invisible
  44. and will make itself visible when it needs to display a tip.
  45. To change the style of tooltips, see the LookAndFeel class for its tooltip
  46. methods.
  47. @param parentComponent if set to 0, the TooltipWindow will appear on the desktop,
  48. otherwise the tooltip will be added to the given parent
  49. component.
  50. @param millisecondsBeforeTipAppears the time for which the mouse has to stay still
  51. before a tooltip will be shown
  52. @see TooltipClient, LookAndFeel::drawTooltip, LookAndFeel::getTooltipBounds
  53. */
  54. explicit TooltipWindow (Component* parentComponent = nullptr,
  55. int millisecondsBeforeTipAppears = 700);
  56. /** Destructor. */
  57. ~TooltipWindow();
  58. //==============================================================================
  59. /** Changes the time before the tip appears.
  60. This lets you change the value that was set in the constructor.
  61. */
  62. void setMillisecondsBeforeTipAppears (int newTimeMs = 700) noexcept;
  63. /** Can be called to manually force a tip to be shown at a particular location. */
  64. void displayTip (Point<int> screenPosition, const String& text);
  65. /** Can be called to manually hide the tip if it's showing. */
  66. void hideTip();
  67. /** Asks a component for its tooltip.
  68. This can be overridden if you need custom lookup behaviour or to modify the strings.
  69. */
  70. virtual String getTipFor (Component&);
  71. //==============================================================================
  72. /** A set of colour IDs to use to change the colour of various aspects of the tooltip.
  73. These constants can be used either via the Component::setColour(), or LookAndFeel::setColour()
  74. methods.
  75. @see Component::setColour, Component::findColour, LookAndFeel::setColour, LookAndFeel::findColour
  76. */
  77. enum ColourIds
  78. {
  79. backgroundColourId = 0x1001b00, /**< The colour to fill the background with. */
  80. textColourId = 0x1001c00, /**< The colour to use for the text. */
  81. outlineColourId = 0x1001c10 /**< The colour to use to draw an outline around the tooltip. */
  82. };
  83. //==============================================================================
  84. /** This abstract base class is implemented by LookAndFeel classes to provide
  85. window drawing functionality.
  86. */
  87. struct JUCE_API LookAndFeelMethods
  88. {
  89. virtual ~LookAndFeelMethods() {}
  90. /** returns the bounds for a tooltip at the given screen coordinate, constrained within the given desktop area. */
  91. virtual Rectangle<int> getTooltipBounds (const String& tipText, Point<int> screenPos, Rectangle<int> parentArea) = 0;
  92. virtual void drawTooltip (Graphics&, const String& text, int width, int height) = 0;
  93. #if JUCE_CATCH_DEPRECATED_CODE_MISUSE
  94. // This method has been replaced by getTooltipBounds()
  95. virtual int getTooltipSize (const String&, int&, int&) { return 0; }
  96. #endif
  97. };
  98. private:
  99. //==============================================================================
  100. Point<float> lastMousePos;
  101. Component* lastComponentUnderMouse = nullptr;
  102. String tipShowing, lastTipUnderMouse;
  103. int millisecondsBeforeTipAppears;
  104. int mouseClicks = 0, mouseWheelMoves = 0;
  105. unsigned int lastCompChangeTime = 0, lastHideTime = 0;
  106. bool reentrant = false;
  107. void paint (Graphics&) override;
  108. void mouseEnter (const MouseEvent&) override;
  109. void timerCallback() override;
  110. void updatePosition (const String&, Point<int>, Rectangle<int>);
  111. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (TooltipWindow)
  112. };
  113. } // namespace juce