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.

95 lines
3.2KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE 6 technical preview.
  4. Copyright (c) 2020 - Raw Material Software Limited
  5. You may use this code under the terms of the GPL v3
  6. (see www.gnu.org/licenses).
  7. For this technical preview, this file is not subject to commercial licensing.
  8. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  9. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  10. DISCLAIMED.
  11. ==============================================================================
  12. */
  13. namespace juce
  14. {
  15. //==============================================================================
  16. /**
  17. An object to take care of the logic for dragging components around with the mouse.
  18. Very easy to use - in your mouseDown() callback, call startDraggingComponent(),
  19. then in your mouseDrag() callback, call dragComponent().
  20. When starting a drag, you can give it a ComponentBoundsConstrainer to use
  21. to limit the component's position and keep it on-screen.
  22. e.g. @code
  23. class MyDraggableComp
  24. {
  25. ComponentDragger myDragger;
  26. void mouseDown (const MouseEvent& e)
  27. {
  28. myDragger.startDraggingComponent (this, e);
  29. }
  30. void mouseDrag (const MouseEvent& e)
  31. {
  32. myDragger.dragComponent (this, e, nullptr);
  33. }
  34. };
  35. @endcode
  36. @tags{GUI}
  37. */
  38. class JUCE_API ComponentDragger
  39. {
  40. public:
  41. //==============================================================================
  42. /** Creates a ComponentDragger. */
  43. ComponentDragger();
  44. /** Destructor. */
  45. virtual ~ComponentDragger();
  46. //==============================================================================
  47. /** Call this from your component's mouseDown() method, to prepare for dragging.
  48. @param componentToDrag the component that you want to drag
  49. @param e the mouse event that is triggering the drag
  50. @see dragComponent
  51. */
  52. void startDraggingComponent (Component* componentToDrag,
  53. const MouseEvent& e);
  54. /** Call this from your mouseDrag() callback to move the component.
  55. This will move the component, using the given constrainer object to check
  56. the new position.
  57. @param componentToDrag the component that you want to drag
  58. @param e the current mouse-drag event
  59. @param constrainer an optional constrainer object that should be used
  60. to apply limits to the component's position. Pass
  61. null if you don't want to constrain the movement.
  62. @see startDraggingComponent
  63. */
  64. void dragComponent (Component* componentToDrag,
  65. const MouseEvent& e,
  66. ComponentBoundsConstrainer* constrainer);
  67. private:
  68. //==============================================================================
  69. Point<int> mouseDownWithinTarget;
  70. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ComponentDragger)
  71. };
  72. } // namespace juce