The JUCE cross-platform C++ framework, with DISTRHO/KXStudio specific changes
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.

116 lines
4.2KB

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