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.

98 lines
3.7KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2017 - ROLI Ltd.
  5. JUCE is an open source library subject to commercial or open-source
  6. licensing.
  7. By using JUCE, you agree to the terms of both the JUCE 5 End-User License
  8. Agreement and JUCE 5 Privacy Policy (both updated and effective as of the
  9. 27th April 2017).
  10. End User License Agreement: www.juce.com/juce-5-licence
  11. Privacy Policy: www.juce.com/juce-5-privacy-policy
  12. Or: You may also use this code under the terms of the GPL v3 (see
  13. www.gnu.org/licenses).
  14. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  15. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  16. DISCLAIMED.
  17. ==============================================================================
  18. */
  19. #pragma once
  20. //==============================================================================
  21. /**
  22. A component that resizes its parent component when dragged.
  23. This component forms a bar along one edge of a component, allowing it to
  24. be dragged by that edges to resize it.
  25. To use it, just add it to your component, positioning it along the appropriate
  26. edge. Make sure you reposition the resizer component each time the parent's size
  27. changes, to keep it in the correct position.
  28. @see ResizbleBorderComponent, ResizableCornerComponent
  29. */
  30. class JUCE_API ResizableEdgeComponent : public Component
  31. {
  32. public:
  33. //==============================================================================
  34. enum Edge
  35. {
  36. leftEdge, /**< Indicates a vertical bar that can be dragged left/right to move the component's left-hand edge. */
  37. rightEdge, /**< Indicates a vertical bar that can be dragged left/right to move the component's right-hand edge. */
  38. topEdge, /**< Indicates a horizontal bar that can be dragged up/down to move the top of the component. */
  39. bottomEdge /**< Indicates a horizontal bar that can be dragged up/down to move the bottom of the component. */
  40. };
  41. /** Creates a resizer bar.
  42. Pass in the target component which you want to be resized when this one is
  43. dragged. The target component will usually be this component's parent, but this
  44. isn't mandatory.
  45. Remember that when the target component is resized, it'll need to move and
  46. resize this component to keep it in place, as this won't happen automatically.
  47. If the constrainer parameter is not a nullptr, then this object will be used to
  48. enforce limits on the size and position that the component can be stretched to.
  49. Make sure that the constrainer isn't deleted while still in use by this object.
  50. @see ComponentBoundsConstrainer
  51. */
  52. ResizableEdgeComponent (Component* componentToResize,
  53. ComponentBoundsConstrainer* constrainer,
  54. Edge edgeToResize);
  55. /** Destructor. */
  56. ~ResizableEdgeComponent();
  57. bool isVertical() const noexcept;
  58. protected:
  59. //==============================================================================
  60. /** @internal */
  61. void paint (Graphics&) override;
  62. /** @internal */
  63. void mouseDown (const MouseEvent&) override;
  64. /** @internal */
  65. void mouseDrag (const MouseEvent&) override;
  66. /** @internal */
  67. void mouseUp (const MouseEvent&) override;
  68. private:
  69. WeakReference<Component> component;
  70. ComponentBoundsConstrainer* constrainer;
  71. Rectangle<int> originalBounds;
  72. const Edge edge;
  73. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ResizableEdgeComponent)
  74. };