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.

62 lines
2.7KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2013 - Raw Material Software 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. ComponentDragger::ComponentDragger() {}
  18. ComponentDragger::~ComponentDragger() {}
  19. //==============================================================================
  20. void ComponentDragger::startDraggingComponent (Component* const componentToDrag, const MouseEvent& e)
  21. {
  22. jassert (componentToDrag != nullptr);
  23. jassert (e.mods.isAnyMouseButtonDown()); // The event has to be a drag event!
  24. if (componentToDrag != nullptr)
  25. mouseDownWithinTarget = e.getEventRelativeTo (componentToDrag).getMouseDownPosition();
  26. }
  27. void ComponentDragger::dragComponent (Component* const componentToDrag, const MouseEvent& e,
  28. ComponentBoundsConstrainer* const constrainer)
  29. {
  30. jassert (componentToDrag != nullptr);
  31. jassert (e.mods.isAnyMouseButtonDown()); // The event has to be a drag event!
  32. if (componentToDrag != nullptr)
  33. {
  34. Rectangle<int> bounds (componentToDrag->getBounds());
  35. // If the component is a window, multiple mouse events can get queued while it's in the same position,
  36. // so their coordinates become wrong after the first one moves the window, so in that case, we'll use
  37. // the current mouse position instead of the one that the event contains...
  38. if (componentToDrag->isOnDesktop())
  39. bounds += componentToDrag->getLocalPoint (nullptr, e.source.getScreenPosition()).roundToInt() - mouseDownWithinTarget;
  40. else
  41. bounds += e.getEventRelativeTo (componentToDrag).getPosition() - mouseDownWithinTarget;
  42. if (constrainer != nullptr)
  43. constrainer->setBoundsForComponent (componentToDrag, bounds, false, false, false, false);
  44. else
  45. componentToDrag->setBounds (bounds);
  46. }
  47. }