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_CallOutBox.h 7.1KB

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