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.

128 lines
4.8KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library - "Jules' Utility Class Extensions"
  4. Copyright 2004-11 by Raw Material Software Ltd.
  5. ------------------------------------------------------------------------------
  6. JUCE can be redistributed and/or modified under the terms of the GNU General
  7. Public License (Version 2), as published by the Free Software Foundation.
  8. A copy of the license is included in the JUCE distribution, or can be found
  9. online at www.gnu.org/licenses.
  10. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  11. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  12. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  13. ------------------------------------------------------------------------------
  14. To release a closed-source product which uses JUCE, commercial licenses are
  15. available: visit www.rawmaterialsoftware.com/juce for more information.
  16. ==============================================================================
  17. */
  18. #ifndef __JUCE_CALLOUTBOX_JUCEHEADER__
  19. #define __JUCE_CALLOUTBOX_JUCEHEADER__
  20. #include "../components/juce_Component.h"
  21. //==============================================================================
  22. /**
  23. A box with a small arrow that can be used as a temporary pop-up window to show
  24. extra controls when a button or other component is clicked.
  25. Using one of these is similar to having a popup menu attached to a button or
  26. other component - but it looks fancier, and has an arrow that can indicate the
  27. object that it applies to.
  28. Normally, you'd create one of these on the stack and run it modally, e.g.
  29. @code
  30. void mouseUp (const MouseEvent& e)
  31. {
  32. MyContentComponent content;
  33. content.setSize (300, 300);
  34. CallOutBox callOut (content, *this, nullptr);
  35. callOut.runModalLoop();
  36. }
  37. @endcode
  38. The call-out will resize and position itself when the content changes size.
  39. */
  40. class JUCE_API CallOutBox : public Component
  41. {
  42. public:
  43. //==============================================================================
  44. /** Creates a CallOutBox.
  45. @param contentComponent the component to display inside the call-out. This should
  46. already have a size set (although the call-out will also
  47. update itself when the component's size is changed later).
  48. Obviously this component must not be deleted until the
  49. call-out box has been deleted.
  50. @param componentToPointTo the component that the call-out's arrow should point towards
  51. @param parentComponent if non-zero, this is the component to add the call-out to. If
  52. this is zero, the call-out will be added to the desktop.
  53. */
  54. CallOutBox (Component& contentComponent,
  55. Component& componentToPointTo,
  56. Component* parentComponent);
  57. /** Destructor. */
  58. ~CallOutBox();
  59. //==============================================================================
  60. /** Changes the length of the arrow. */
  61. void setArrowSize (float newSize);
  62. /** Updates the position and size of the box.
  63. You shouldn't normally need to call this, unless you need more precise control over the
  64. layout.
  65. @param newAreaToPointTo the rectangle to make the box's arrow point to
  66. @param newAreaToFitIn the area within which the box's position should be constrained
  67. */
  68. void updatePosition (const Rectangle<int>& newAreaToPointTo,
  69. const Rectangle<int>& newAreaToFitIn);
  70. //==============================================================================
  71. /** @internal */
  72. void paint (Graphics& g);
  73. /** @internal */
  74. void resized();
  75. /** @internal */
  76. void moved();
  77. /** @internal */
  78. void childBoundsChanged (Component*);
  79. /** @internal */
  80. bool hitTest (int x, int y);
  81. /** @internal */
  82. void inputAttemptWhenModal();
  83. /** @internal */
  84. bool keyPressed (const KeyPress& key);
  85. /** @internal */
  86. void handleCommandMessage (int commandId);
  87. private:
  88. //==============================================================================
  89. int borderSpace;
  90. float arrowSize;
  91. Component& content;
  92. Path outline;
  93. Point<float> targetPoint;
  94. Rectangle<int> availableArea, targetArea;
  95. Image background;
  96. void refreshPath();
  97. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (CallOutBox);
  98. };
  99. #endif // __JUCE_CALLOUTBOX_JUCEHEADER__