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.h 3.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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. #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, but will first check the validity of the
  59. component's new position using the checkPosition() method, which you
  60. can override if you need to enforce special positioning limits on the
  61. component.
  62. @param componentToDrag the component that you want to drag
  63. @param e the current mouse-drag event
  64. @param constrainer an optional constrainer object that should be used
  65. to apply limits to the component's position. Pass
  66. null if you don't want to contrain the movement.
  67. @see startDraggingComponent
  68. */
  69. void dragComponent (Component* componentToDrag,
  70. const MouseEvent& e,
  71. ComponentBoundsConstrainer* constrainer);
  72. private:
  73. //==============================================================================
  74. Point<int> mouseDownWithinTarget;
  75. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ComponentDragger)
  76. };
  77. #endif // JUCE_COMPONENTDRAGGER_H_INCLUDED