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.

103 lines
4.1KB

  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_RESIZABLEEDGECOMPONENT_JUCEHEADER__
  19. #define __JUCE_RESIZABLEEDGECOMPONENT_JUCEHEADER__
  20. #include "juce_ComponentBoundsConstrainer.h"
  21. //==============================================================================
  22. /**
  23. A component that resizes its parent component when dragged.
  24. This component forms a bar along one edge of a component, allowing it to
  25. be dragged by that edges to resize it.
  26. To use it, just add it to your component, positioning it along the appropriate
  27. edge. Make sure you reposition the resizer component each time the parent's size
  28. changes, to keep it in the correct position.
  29. @see ResizbleBorderComponent, ResizableCornerComponent
  30. */
  31. class JUCE_API ResizableEdgeComponent : public Component
  32. {
  33. public:
  34. //==============================================================================
  35. enum Edge
  36. {
  37. leftEdge, /**< Indicates a vertical bar that can be dragged left/right to move the component's left-hand edge. */
  38. rightEdge, /**< Indicates a vertical bar that can be dragged left/right to move the component's right-hand edge. */
  39. topEdge, /**< Indicates a horizontal bar that can be dragged up/down to move the top of the component. */
  40. bottomEdge /**< Indicates a horizontal bar that can be dragged up/down to move the bottom of the component. */
  41. };
  42. /** Creates a resizer bar.
  43. Pass in the target component which you want to be resized when this one is
  44. dragged. The target component will usually be this component's parent, but this
  45. isn't mandatory.
  46. Remember that when the target component is resized, it'll need to move and
  47. resize this component to keep it in place, as this won't happen automatically.
  48. If the constrainer parameter is non-zero, then this object will be used to enforce
  49. limits on the size and position that the component can be stretched to. Make sure
  50. that the constrainer isn't deleted while still in use by this object.
  51. @see ComponentBoundsConstrainer
  52. */
  53. ResizableEdgeComponent (Component* componentToResize,
  54. ComponentBoundsConstrainer* constrainer,
  55. Edge edgeToResize);
  56. /** Destructor. */
  57. ~ResizableEdgeComponent();
  58. bool isVertical() const noexcept;
  59. protected:
  60. //==============================================================================
  61. /** @internal */
  62. void paint (Graphics& g);
  63. /** @internal */
  64. void mouseDown (const MouseEvent& e);
  65. /** @internal */
  66. void mouseDrag (const MouseEvent& e);
  67. /** @internal */
  68. void mouseUp (const MouseEvent& e);
  69. private:
  70. WeakReference<Component> component;
  71. ComponentBoundsConstrainer* constrainer;
  72. Rectangle<int> originalBounds;
  73. const Edge edge;
  74. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ResizableEdgeComponent);
  75. };
  76. #endif // __JUCE_RESIZABLEEDGECOMPONENT_JUCEHEADER__