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.

94 lines
3.5KB

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