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.

juce_ComponentDragger.cpp 2.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2022 - Raw Material Software Limited
  5. JUCE is an open source library subject to commercial or open-source
  6. licensing.
  7. By using JUCE, you agree to the terms of both the JUCE 7 End-User License
  8. Agreement and JUCE Privacy Policy.
  9. End User License Agreement: www.juce.com/juce-7-licence
  10. Privacy Policy: www.juce.com/juce-privacy-policy
  11. Or: You may also use this code under the terms of the GPL v3 (see
  12. www.gnu.org/licenses).
  13. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  14. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  15. DISCLAIMED.
  16. ==============================================================================
  17. */
  18. namespace juce
  19. {
  20. ComponentDragger::ComponentDragger() {}
  21. ComponentDragger::~ComponentDragger() {}
  22. //==============================================================================
  23. void ComponentDragger::startDraggingComponent (Component* const componentToDrag, const MouseEvent& e)
  24. {
  25. jassert (componentToDrag != nullptr);
  26. jassert (e.mods.isAnyMouseButtonDown()); // The event has to be a drag event!
  27. if (componentToDrag != nullptr)
  28. mouseDownWithinTarget = e.getEventRelativeTo (componentToDrag).getMouseDownPosition();
  29. }
  30. void ComponentDragger::dragComponent (Component* const componentToDrag, const MouseEvent& e,
  31. ComponentBoundsConstrainer* const constrainer)
  32. {
  33. jassert (componentToDrag != nullptr);
  34. jassert (e.mods.isAnyMouseButtonDown()); // The event has to be a drag event!
  35. if (componentToDrag != nullptr)
  36. {
  37. auto bounds = componentToDrag->getBounds();
  38. // If the component is a window, multiple mouse events can get queued while it's in the same position,
  39. // so their coordinates become wrong after the first one moves the window, so in that case, we'll use
  40. // the current mouse position instead of the one that the event contains...
  41. if (componentToDrag->isOnDesktop())
  42. bounds += componentToDrag->getLocalPoint (nullptr, e.source.getScreenPosition()).roundToInt() - mouseDownWithinTarget;
  43. else
  44. bounds += e.getEventRelativeTo (componentToDrag).getPosition() - mouseDownWithinTarget;
  45. if (constrainer != nullptr)
  46. constrainer->setBoundsForComponent (componentToDrag, bounds, false, false, false, false);
  47. else
  48. componentToDrag->setBounds (bounds);
  49. }
  50. }
  51. } // namespace juce