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.

158 lines
6.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_CALLOUTBOX_JUCEHEADER__
  18. #define __JUCE_CALLOUTBOX_JUCEHEADER__
  19. #include "../components/juce_Component.h"
  20. //==============================================================================
  21. /**
  22. A box with a small arrow that can be used as a temporary pop-up window to show
  23. extra controls when a button or other component is clicked.
  24. Using one of these is similar to having a popup menu attached to a button or
  25. other component - but it looks fancier, and has an arrow that can indicate the
  26. object that it applies to.
  27. The class works best when shown modally, but obviously running modal loops is
  28. evil and must never be done, so the launchAsynchronously method is provided as
  29. a handy way of launching an instance of a CallOutBox and automatically managing
  30. its lifetime, e.g.
  31. @code
  32. void mouseUp (const MouseEvent&)
  33. {
  34. FoobarContentComp* content = new FoobarContentComp();
  35. content->setSize (300, 300);
  36. CallOutBox& myBox
  37. = CallOutBox::launchAsynchronously (content, getScreenBounds(), nullptr);
  38. }
  39. @endcode
  40. The call-out will resize and position itself when the content changes size.
  41. */
  42. class JUCE_API CallOutBox : public Component
  43. {
  44. public:
  45. //==============================================================================
  46. /** Creates a CallOutBox.
  47. @param contentComponent the component to display inside the call-out. This should
  48. already have a size set (although the call-out will also
  49. update itself when the component's size is changed later).
  50. Obviously this component must not be deleted until the
  51. call-out box has been deleted.
  52. @param areaToPointTo the area that the call-out's arrow should point towards. If
  53. a parentComponent is supplied, then this is relative to that
  54. parent; otherwise, it's a global screen coord.
  55. @param parentComponent if non-zero, this is the component to add the call-out to. If
  56. this is a nullptr, the call-out will be added to the desktop.
  57. */
  58. CallOutBox (Component& contentComponent,
  59. const Rectangle<int>& areaToPointTo,
  60. Component* parentComponent);
  61. /** Destructor. */
  62. ~CallOutBox();
  63. //==============================================================================
  64. /** Changes the length of the arrow. */
  65. void setArrowSize (float newSize);
  66. /** Updates the position and size of the box.
  67. You shouldn't normally need to call this, unless you need more precise control over the
  68. layout.
  69. @param newAreaToPointTo the rectangle to make the box's arrow point to
  70. @param newAreaToFitIn the area within which the box's position should be constrained
  71. */
  72. void updatePosition (const Rectangle<int>& newAreaToPointTo,
  73. const Rectangle<int>& newAreaToFitIn);
  74. /** This will launch a callout box containing the given content, pointing to the
  75. specified target component.
  76. This method will create and display a callout, returning immediately, after which
  77. the box will continue to run modally until the user clicks on some other component, at
  78. which point it will be dismissed and deleted automatically.
  79. It returns a reference to the newly-created box so that you can customise it, but don't
  80. keep a pointer to it, as it'll be deleted at some point when it gets closed.
  81. @param contentComponent the component to display inside the call-out. This should
  82. already have a size set (although the call-out will also
  83. update itself when the component's size is changed later).
  84. This component will be owned by the callout box and deleted
  85. later when the box is dismissed.
  86. @param areaToPointTo the area that the call-out's arrow should point towards. If
  87. a parentComponent is supplied, then this is relative to that
  88. parent; otherwise, it's a global screen coord.
  89. @param parentComponent if non-zero, this is the component to add the call-out to. If
  90. this is a nullptr, the call-out will be added to the desktop.
  91. */
  92. static CallOutBox& launchAsynchronously (Component* contentComponent,
  93. const Rectangle<int>& areaToPointTo,
  94. Component* parentComponent);
  95. //==============================================================================
  96. /** @internal */
  97. void paint (Graphics&) override;
  98. /** @internal */
  99. void resized() override;
  100. /** @internal */
  101. void moved() override;
  102. /** @internal */
  103. void childBoundsChanged (Component*) override;
  104. /** @internal */
  105. bool hitTest (int x, int y) override;
  106. /** @internal */
  107. void inputAttemptWhenModal() override;
  108. /** @internal */
  109. bool keyPressed (const KeyPress&) override;
  110. /** @internal */
  111. void handleCommandMessage (int) override;
  112. private:
  113. //==============================================================================
  114. int borderSpace;
  115. float arrowSize;
  116. Component& content;
  117. Path outline;
  118. Point<float> targetPoint;
  119. Rectangle<int> availableArea, targetArea;
  120. Image background;
  121. void refreshPath();
  122. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (CallOutBox)
  123. };
  124. #endif // __JUCE_CALLOUTBOX_JUCEHEADER__