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.

100 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. namespace juce
  20. {
  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 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();
  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