guiDragAndDropCtrl.h
Engine/source/gui/containers/guiDragAndDropCtrl.h
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 /// Controls may want to react when they are dragged over, entered or exited. 58 SimObjectPtr<GuiControl> mLastTarget; 59 60 GuiControl* findDragTarget(Point2I mousePoint, const char* method); 61 62 Point2I getDropPoint() const 63 { 64 return getPosition() + (getExtent() / 2); 65 } 66 67 public: 68 69 GuiDragAndDropControl() {} 70 71 void startDragging(Point2I offset = Point2I(0, 0)); 72 73 // GuiControl. 74 virtual void onMouseDown(const GuiEvent& event); 75 virtual void onMouseDragged(const GuiEvent& event); 76 virtual void onMouseUp(const GuiEvent& event); 77 78 static void initPersistFields(); 79 80 DECLARE_CONOBJECT( GuiDragAndDropControl ); 81 DECLARE_CATEGORY( "Gui Other" ); 82 DECLARE_DESCRIPTION( "A special control that implements drag&drop behavior.\n" 83 "The control will notify other controls as it moves across the canvas.\n" 84 "Content can be attached through dynamic fields or child objects." ); 85}; 86 87#endif 88
