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.

101 lines
3.8KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2020 - Raw Material Software Limited
  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 6 End-User License
  8. Agreement and JUCE Privacy Policy (both effective as of the 16th June 2020).
  9. End User License Agreement: www.juce.com/juce-6-licence
  10. Privacy Policy: www.juce.com/juce-privacy-policy
  11. Or: You may also use this code under the terms of the GPL v3 (see
  12. www.gnu.org/licenses).
  13. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  14. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  15. DISCLAIMED.
  16. ==============================================================================
  17. */
  18. namespace juce
  19. {
  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 ResizableBorderComponent, ResizableCornerComponent
  29. @tags{GUI}
  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 not a nullptr, then this object will be used to
  49. enforce limits on the size and position that the component can be stretched to.
  50. Make sure 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() override;
  58. bool isVertical() const noexcept;
  59. protected:
  60. //==============================================================================
  61. /** @internal */
  62. void paint (Graphics&) override;
  63. /** @internal */
  64. void mouseDown (const MouseEvent&) override;
  65. /** @internal */
  66. void mouseDrag (const MouseEvent&) override;
  67. /** @internal */
  68. void mouseUp (const MouseEvent&) override;
  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. } // namespace juce