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.

108 lines
3.8KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2015 - ROLI Ltd.
  5. Permission is granted to use this software under the terms of either:
  6. a) the GPL v2 (or any later version)
  7. b) the Affero GPL v3
  8. Details of these licenses can be found at: www.gnu.org/licenses
  9. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  10. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  11. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  12. ------------------------------------------------------------------------------
  13. To release a closed-source product which uses JUCE, commercial licenses are
  14. available: visit www.juce.com for more information.
  15. ==============================================================================
  16. */
  17. ResizableEdgeComponent::ResizableEdgeComponent (Component* const componentToResize,
  18. ComponentBoundsConstrainer* const constrainer_,
  19. Edge edge_)
  20. : component (componentToResize),
  21. constrainer (constrainer_),
  22. edge (edge_)
  23. {
  24. setRepaintsOnMouseActivity (true);
  25. setMouseCursor (isVertical() ? MouseCursor::LeftRightResizeCursor
  26. : MouseCursor::UpDownResizeCursor);
  27. }
  28. ResizableEdgeComponent::~ResizableEdgeComponent()
  29. {
  30. }
  31. //==============================================================================
  32. bool ResizableEdgeComponent::isVertical() const noexcept
  33. {
  34. return edge == leftEdge || edge == rightEdge;
  35. }
  36. void ResizableEdgeComponent::paint (Graphics& g)
  37. {
  38. getLookAndFeel().drawStretchableLayoutResizerBar (g, getWidth(), getHeight(), isVertical(),
  39. isMouseOver(), isMouseButtonDown());
  40. }
  41. void ResizableEdgeComponent::mouseDown (const MouseEvent&)
  42. {
  43. if (component == nullptr)
  44. {
  45. jassertfalse; // You've deleted the component that this resizer was supposed to be using!
  46. return;
  47. }
  48. originalBounds = component->getBounds();
  49. if (constrainer != nullptr)
  50. constrainer->resizeStart();
  51. }
  52. void ResizableEdgeComponent::mouseDrag (const MouseEvent& e)
  53. {
  54. if (component == nullptr)
  55. {
  56. jassertfalse; // You've deleted the component that this resizer was supposed to be using!
  57. return;
  58. }
  59. Rectangle<int> newBounds (originalBounds);
  60. switch (edge)
  61. {
  62. case leftEdge: newBounds.setLeft (jmin (newBounds.getRight(), newBounds.getX() + e.getDistanceFromDragStartX())); break;
  63. case rightEdge: newBounds.setWidth (jmax (0, newBounds.getWidth() + e.getDistanceFromDragStartX())); break;
  64. case topEdge: newBounds.setTop (jmin (newBounds.getBottom(), newBounds.getY() + e.getDistanceFromDragStartY())); break;
  65. case bottomEdge: newBounds.setHeight (jmax (0, newBounds.getHeight() + e.getDistanceFromDragStartY())); break;
  66. default: jassertfalse; break;
  67. }
  68. if (constrainer != nullptr)
  69. {
  70. constrainer->setBoundsForComponent (component, newBounds,
  71. edge == topEdge,
  72. edge == leftEdge,
  73. edge == bottomEdge,
  74. edge == rightEdge);
  75. }
  76. else
  77. {
  78. if (Component::Positioner* const pos = component->getPositioner())
  79. pos->applyNewBounds (newBounds);
  80. else
  81. component->setBounds (newBounds);
  82. }
  83. }
  84. void ResizableEdgeComponent::mouseUp (const MouseEvent&)
  85. {
  86. if (constrainer != nullptr)
  87. constrainer->resizeEnd();
  88. }