Torque3D Documentation / _generateds / guiDragAndDropCtrl.h

guiDragAndDropCtrl.h

Engine/source/gui/containers/guiDragAndDropCtrl.h

More...

Classes:

class

A special control that implements drag-and-drop behavior.

Detailed Description

 1
 2//-----------------------------------------------------------------------------
 3// Copyright (c) 2012 GarageGames, LLC
 4//
 5// Permission is hereby granted, free of charge, to any person obtaining a copy
 6// of this software and associated documentation files (the "Software"), to
 7// deal in the Software without restriction, including without limitation the
 8// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
 9// sell copies of the Software, and to permit persons to whom the Software is
10// furnished to do so, subject to the following conditions:
11//
12// The above copyright notice and this permission notice shall be included in
13// all copies or substantial portions of the Software.
14//
15// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21// IN THE SOFTWARE.
22//-----------------------------------------------------------------------------
23
24#ifndef _GUIDRAGANDDROPCTRL_H_
25#define _GUIDRAGANDDROPCTRL_H_
26
27#ifndef _GUICONTROL_H_
28   #include "gui/core/guiControl.h"
29#endif
30#ifndef _GFXDEVICE_H_
31   #include "gfx/gfxDevice.h"
32#endif
33#ifndef _CONSOLE_H_
34   #include "console/console.h"
35#endif
36#ifndef _CONSOLETYPES_H_
37   #include "console/consoleTypes.h"
38#endif
39
40
41/// A special control that implements drag-and-drop behavior.
42///
43class GuiDragAndDropControl : public GuiControl
44{
45   public:
46
47      typedef GuiControl Parent;
48   
49   private:
50   
51      /// The mouse down offset from the upper left of the control.
52      Point2I mOffset;
53      
54      /// If true, the control deletes itself when the left mouse button is released.
55      bool mDeleteOnMouseUp;
56
57      bool mUseWholeCanvas;
58
59      /// Controls may want to react when they are dragged over, entered or exited.
60      SimObjectPtr<GuiControl> mLastTarget;
61      
62      GuiControl* findDragTarget(Point2I mousePoint, const char* method);
63      
64      Point2I getDropPoint() const
65      {
66         return getPosition() + (getExtent() / 2);
67      }
68
69   public:
70   
71      GuiDragAndDropControl();
72
73      void startDragging(Point2I offset = Point2I(0, 0));
74
75      // GuiControl.
76      virtual void onMouseDown(const GuiEvent& event);
77      virtual void onMouseDragged(const GuiEvent& event);
78      virtual void onMouseUp(const GuiEvent& event);
79
80      static void initPersistFields();
81
82      DECLARE_CONOBJECT( GuiDragAndDropControl );
83      DECLARE_CATEGORY( "Gui Other" );
84      DECLARE_DESCRIPTION( "A special control that implements drag&drop behavior.\n"
85                           "The control will notify other controls as it moves across the canvas.\n"
86                           "Content can be attached through dynamic fields or child objects." );
87
88      DECLARE_CALLBACK(void, onControlDragCancelled, ());
89};
90
91#endif
92