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.

80 lines
3.0KB

  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. StretchableLayoutResizerBar::StretchableLayoutResizerBar (StretchableLayoutManager* layout_,
  21. const int itemIndex_,
  22. const bool isVertical_)
  23. : layout (layout_),
  24. itemIndex (itemIndex_),
  25. isVertical (isVertical_)
  26. {
  27. setRepaintsOnMouseActivity (true);
  28. setMouseCursor (MouseCursor (isVertical_ ? MouseCursor::LeftRightResizeCursor
  29. : MouseCursor::UpDownResizeCursor));
  30. }
  31. StretchableLayoutResizerBar::~StretchableLayoutResizerBar()
  32. {
  33. }
  34. //==============================================================================
  35. void StretchableLayoutResizerBar::paint (Graphics& g)
  36. {
  37. getLookAndFeel().drawStretchableLayoutResizerBar (g,
  38. getWidth(), getHeight(),
  39. isVertical,
  40. isMouseOver(),
  41. isMouseButtonDown());
  42. }
  43. void StretchableLayoutResizerBar::mouseDown (const MouseEvent&)
  44. {
  45. mouseDownPos = layout->getItemCurrentPosition (itemIndex);
  46. }
  47. void StretchableLayoutResizerBar::mouseDrag (const MouseEvent& e)
  48. {
  49. const int desiredPos = mouseDownPos + (isVertical ? e.getDistanceFromDragStartX()
  50. : e.getDistanceFromDragStartY());
  51. if (layout->getItemCurrentPosition (itemIndex) != desiredPos)
  52. {
  53. layout->setItemPosition (itemIndex, desiredPos);
  54. hasBeenMoved();
  55. }
  56. }
  57. void StretchableLayoutResizerBar::hasBeenMoved()
  58. {
  59. if (getParentComponent() != nullptr)
  60. getParentComponent()->resized();
  61. }
  62. END_JUCE_NAMESPACE