2 ==============================================================================
4 This file is part of the JUCE library - "Jules' Utility Class Extensions"
5 Copyright 2004-11 by Raw Material Software Ltd.
7 ------------------------------------------------------------------------------
9 JUCE can be redistributed and/or modified under the terms of the GNU General
10 Public License (Version 2), as published by the Free Software Foundation.
11 A copy of the license is included in the JUCE distribution, or can be found
12 online at www.gnu.org/licenses.
14 JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
15 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
16 A PARTICULAR PURPOSE. See the GNU General Public License for more details.
18 ------------------------------------------------------------------------------
20 To release a closed-source product which uses JUCE, commercial licenses are
21 available: visit www.rawmaterialsoftware.com/juce for more information.
23 ==============================================================================
26 #ifndef __JUCE_COMPONENTDRAGGER_JUCEHEADER__
27 #define __JUCE_COMPONENTDRAGGER_JUCEHEADER__
29 #include "juce_MouseEvent.h"
30 #include "../layout/juce_ComponentBoundsConstrainer.h"
33 //==============================================================================
35 An object to take care of the logic for dragging components around with the mouse.
37 Very easy to use - in your mouseDown() callback, call startDraggingComponent(),
38 then in your mouseDrag() callback, call dragComponent().
40 When starting a drag, you can give it a ComponentBoundsConstrainer to use
41 to limit the component's position and keep it on-screen.
46 ComponentDragger myDragger;
48 void mouseDown (const MouseEvent& e)
50 myDragger.startDraggingComponent (this, e);
53 void mouseDrag (const MouseEvent& e)
55 myDragger.dragComponent (this, e, nullptr);
60 class JUCE_API ComponentDragger
63 //==============================================================================
64 /** Creates a ComponentDragger. */
68 virtual ~ComponentDragger();
70 //==============================================================================
71 /** Call this from your component's mouseDown() method, to prepare for dragging.
73 @param componentToDrag the component that you want to drag
74 @param e the mouse event that is triggering the drag
77 void startDraggingComponent (Component
* componentToDrag
,
80 /** Call this from your mouseDrag() callback to move the component.
82 This will move the component, but will first check the validity of the
83 component's new position using the checkPosition() method, which you
84 can override if you need to enforce special positioning limits on the
87 @param componentToDrag the component that you want to drag
88 @param e the current mouse-drag event
89 @param constrainer an optional constrainer object that should be used
90 to apply limits to the component's position. Pass
91 null if you don't want to contrain the movement.
92 @see startDraggingComponent
94 void dragComponent (Component
* componentToDrag
,
96 ComponentBoundsConstrainer
* constrainer
);
99 //==============================================================================
100 Point
<int> mouseDownWithinTarget
;
102 JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ComponentDragger
);
105 #endif // __JUCE_COMPONENTDRAGGER_JUCEHEADER__