guiDragAndDropCtrl.h 3.0 KB

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