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.

75 lines
2.9KB

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