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.

152 lines
6.3KB

  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. Normally, you'd create one of these on the stack and run it modally, e.g.
  28. @code
  29. void mouseUp (const MouseEvent& e)
  30. {
  31. MyContentComponent content;
  32. content.setSize (300, 300);
  33. CallOutBox callOut (content, *this, nullptr);
  34. callOut.runModalLoop();
  35. }
  36. @endcode
  37. The call-out will resize and position itself when the content changes size.
  38. */
  39. class JUCE_API CallOutBox : public Component
  40. {
  41. public:
  42. //==============================================================================
  43. /** Creates a CallOutBox.
  44. @param contentComponent the component to display inside the call-out. This should
  45. already have a size set (although the call-out will also
  46. update itself when the component's size is changed later).
  47. Obviously this component must not be deleted until the
  48. call-out box has been deleted.
  49. @param areaToPointTo the area that the call-out's arrow should point towards. If
  50. a parentComponent is supplied, then this is relative to that
  51. parent; otherwise, it's a global screen coord.
  52. @param parentComponent if non-zero, this is the component to add the call-out to. If
  53. this is a nullptr, the call-out will be added to the desktop.
  54. */
  55. CallOutBox (Component& contentComponent,
  56. const Rectangle<int>& areaToPointTo,
  57. Component* parentComponent);
  58. /** Destructor. */
  59. ~CallOutBox();
  60. //==============================================================================
  61. /** Changes the length of the arrow. */
  62. void setArrowSize (float newSize);
  63. /** Updates the position and size of the box.
  64. You shouldn't normally need to call this, unless you need more precise control over the
  65. layout.
  66. @param newAreaToPointTo the rectangle to make the box's arrow point to
  67. @param newAreaToFitIn the area within which the box's position should be constrained
  68. */
  69. void updatePosition (const Rectangle<int>& newAreaToPointTo,
  70. const Rectangle<int>& newAreaToFitIn);
  71. /** This will launch a callout box containing the given content, pointing to the
  72. specified target component.
  73. This method will create and display a callout, returning immediately, after which
  74. the box will continue to run modally until the user clicks on some other component, at
  75. which point it will be dismissed automatically.
  76. @param contentComponent the component to display inside the call-out. This should
  77. already have a size set (although the call-out will also
  78. update itself when the component's size is changed later).
  79. This component will be owned by the callout box and deleted
  80. later when the box is dismissed.
  81. @param areaToPointTo the area that the call-out's arrow should point towards. If
  82. a parentComponent is supplied, then this is relative to that
  83. parent; otherwise, it's a global screen coord.
  84. @param parentComponent if non-zero, this is the component to add the call-out to. If
  85. this is a nullptr, the call-out will be added to the desktop.
  86. */
  87. static CallOutBox& launchAsynchronously (Component* contentComponent,
  88. const Rectangle<int>& areaToPointTo,
  89. Component* parentComponent);
  90. //==============================================================================
  91. /** @internal */
  92. void paint (Graphics&) override;
  93. /** @internal */
  94. void resized() override;
  95. /** @internal */
  96. void moved() override;
  97. /** @internal */
  98. void childBoundsChanged (Component*) override;
  99. /** @internal */
  100. bool hitTest (int x, int y) override;
  101. /** @internal */
  102. void inputAttemptWhenModal() override;
  103. /** @internal */
  104. bool keyPressed (const KeyPress&) override;
  105. /** @internal */
  106. void handleCommandMessage (int commandId) override;
  107. private:
  108. //==============================================================================
  109. int borderSpace;
  110. float arrowSize;
  111. Component& content;
  112. Path outline;
  113. Point<float> targetPoint;
  114. Rectangle<int> availableArea, targetArea;
  115. Image background;
  116. void refreshPath();
  117. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (CallOutBox)
  118. };
  119. #endif // __JUCE_CALLOUTBOX_JUCEHEADER__