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.

100 lines
3.6KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2015 - ROLI 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. #ifndef JUCE_COMPONENTDRAGGER_H_INCLUDED
  18. #define JUCE_COMPONENTDRAGGER_H_INCLUDED
  19. //==============================================================================
  20. /**
  21. An object to take care of the logic for dragging components around with the mouse.
  22. Very easy to use - in your mouseDown() callback, call startDraggingComponent(),
  23. then in your mouseDrag() callback, call dragComponent().
  24. When starting a drag, you can give it a ComponentBoundsConstrainer to use
  25. to limit the component's position and keep it on-screen.
  26. e.g. @code
  27. class MyDraggableComp
  28. {
  29. ComponentDragger myDragger;
  30. void mouseDown (const MouseEvent& e)
  31. {
  32. myDragger.startDraggingComponent (this, e);
  33. }
  34. void mouseDrag (const MouseEvent& e)
  35. {
  36. myDragger.dragComponent (this, e, nullptr);
  37. }
  38. };
  39. @endcode
  40. */
  41. class JUCE_API ComponentDragger
  42. {
  43. public:
  44. //==============================================================================
  45. /** Creates a ComponentDragger. */
  46. ComponentDragger();
  47. /** Destructor. */
  48. virtual ~ComponentDragger();
  49. //==============================================================================
  50. /** Call this from your component's mouseDown() method, to prepare for dragging.
  51. @param componentToDrag the component that you want to drag
  52. @param e the mouse event that is triggering the drag
  53. @see dragComponent
  54. */
  55. void startDraggingComponent (Component* componentToDrag,
  56. const MouseEvent& e);
  57. /** Call this from your mouseDrag() callback to move the component.
  58. This will move the component, using the given constrainer object to check
  59. the new position.
  60. @param componentToDrag the component that you want to drag
  61. @param e the current mouse-drag event
  62. @param constrainer an optional constrainer object that should be used
  63. to apply limits to the component's position. Pass
  64. null if you don't want to contrain the movement.
  65. @see startDraggingComponent
  66. */
  67. void dragComponent (Component* componentToDrag,
  68. const MouseEvent& e,
  69. ComponentBoundsConstrainer* constrainer);
  70. private:
  71. //==============================================================================
  72. Point<int> mouseDownWithinTarget;
  73. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ComponentDragger)
  74. };
  75. #endif // JUCE_COMPONENTDRAGGER_H_INCLUDED