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.

122 lines
4.2KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library - "Jules' Utility Class Extensions"
  4. Copyright 2004-10 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. #include "../../../core/juce_StandardHeader.h"
  19. BEGIN_JUCE_NAMESPACE
  20. #include "juce_ResizableEdgeComponent.h"
  21. #include "../lookandfeel/juce_LookAndFeel.h"
  22. //==============================================================================
  23. ResizableEdgeComponent::ResizableEdgeComponent (Component* const componentToResize,
  24. ComponentBoundsConstrainer* const constrainer_,
  25. Edge edge_)
  26. : component (componentToResize),
  27. constrainer (constrainer_),
  28. edge (edge_)
  29. {
  30. setRepaintsOnMouseActivity (true);
  31. setMouseCursor (MouseCursor (isVertical() ? MouseCursor::LeftRightResizeCursor
  32. : MouseCursor::UpDownResizeCursor));
  33. }
  34. ResizableEdgeComponent::~ResizableEdgeComponent()
  35. {
  36. }
  37. //==============================================================================
  38. bool ResizableEdgeComponent::isVertical() const throw()
  39. {
  40. return edge == leftEdge || edge == rightEdge;
  41. }
  42. void ResizableEdgeComponent::paint (Graphics& g)
  43. {
  44. getLookAndFeel().drawStretchableLayoutResizerBar (g, getWidth(), getHeight(), isVertical(),
  45. isMouseOver(), isMouseButtonDown());
  46. }
  47. void ResizableEdgeComponent::mouseDown (const MouseEvent&)
  48. {
  49. if (component == 0)
  50. {
  51. jassertfalse; // You've deleted the component that this resizer was supposed to be using!
  52. return;
  53. }
  54. originalBounds = component->getBounds();
  55. if (constrainer != 0)
  56. constrainer->resizeStart();
  57. }
  58. void ResizableEdgeComponent::mouseDrag (const MouseEvent& e)
  59. {
  60. if (component == 0)
  61. {
  62. jassertfalse; // You've deleted the component that this resizer was supposed to be using!
  63. return;
  64. }
  65. Rectangle<int> bounds (originalBounds);
  66. switch (edge)
  67. {
  68. case leftEdge: bounds.setLeft (bounds.getX() + e.getDistanceFromDragStartX()); break;
  69. case rightEdge: bounds.setWidth (bounds.getWidth() + e.getDistanceFromDragStartX()); break;
  70. case topEdge: bounds.setTop (bounds.getY() + e.getDistanceFromDragStartY()); break;
  71. case bottomEdge: bounds.setHeight (bounds.getHeight() + e.getDistanceFromDragStartY()); break;
  72. default: jassertfalse; break;
  73. }
  74. if (constrainer != 0)
  75. {
  76. constrainer->setBoundsForComponent (component, bounds,
  77. edge == topEdge,
  78. edge == leftEdge,
  79. edge == bottomEdge,
  80. edge == rightEdge);
  81. }
  82. else
  83. {
  84. Component::Positioner* const positioner = component->getPositioner();
  85. if (positioner != 0)
  86. positioner->applyNewBounds (bounds);
  87. else
  88. component->setBounds (bounds);
  89. }
  90. }
  91. void ResizableEdgeComponent::mouseUp (const MouseEvent&)
  92. {
  93. if (constrainer != 0)
  94. constrainer->resizeEnd();
  95. }
  96. END_JUCE_NAMESPACE