BsGUIDropButton.cpp 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. #include "BsGUIDropButton.h"
  2. #include "BsGUIDimensions.h"
  3. #include "BsGUIMouseEvent.h"
  4. #include "BsDragAndDropManager.h"
  5. namespace BansheeEngine
  6. {
  7. const String& GUIDropButton::getGUITypeName()
  8. {
  9. static String name = "DropButton";
  10. return name;
  11. }
  12. GUIDropButton::GUIDropButton(UINT32 dragType, const String& styleName, const GUIDimensions& dimensions)
  13. :GUIButtonBase(styleName, GUIContent(HString(L"None")), dimensions), mDragType(dragType)
  14. {
  15. }
  16. GUIDropButton::~GUIDropButton()
  17. { }
  18. GUIDropButton* GUIDropButton::create(UINT32 dragType, const String& styleName)
  19. {
  20. return new (bs_alloc<GUIDropButton>()) GUIDropButton(dragType,
  21. getStyleName<GUIDropButton>(styleName), GUIDimensions::create());
  22. }
  23. GUIDropButton* GUIDropButton::create(UINT32 dragType, const GUIOptions& options, const String& styleName)
  24. {
  25. return new (bs_alloc<GUIDropButton>()) GUIDropButton(dragType,
  26. getStyleName<GUIDropButton>(styleName), GUIDimensions::create(options));
  27. }
  28. bool GUIDropButton::_mouseEvent(const GUIMouseEvent& ev)
  29. {
  30. bool processed = GUIButtonBase::_mouseEvent(ev);
  31. if(ev.getType() == GUIMouseEventType::MouseDragAndDropDragged)
  32. {
  33. if (!_isDisabled())
  34. {
  35. if (DragAndDropManager::instance().isDragInProgress())
  36. {
  37. if (DragAndDropManager::instance().getDragTypeId() == mDragType)
  38. {
  39. if (!_isOn())
  40. _setOn(true);
  41. }
  42. else
  43. {
  44. if (_isOn())
  45. _setOn(false);
  46. }
  47. }
  48. else
  49. {
  50. if (_isOn())
  51. _setOn(false);
  52. }
  53. }
  54. processed = true;
  55. }
  56. else if(ev.getType() == GUIMouseEventType::MouseDragAndDropDropped)
  57. {
  58. if (!_isDisabled())
  59. {
  60. if (_isOn())
  61. _setOn(false);
  62. if (DragAndDropManager::instance().isDragInProgress() && DragAndDropManager::instance().getDragTypeId() == mDragType)
  63. {
  64. if (!onDataDropped.empty())
  65. onDataDropped(DragAndDropManager::instance().getDragData());
  66. }
  67. }
  68. processed = true;
  69. }
  70. else if (ev.getType() == GUIMouseEventType::MouseDragAndDropLeft)
  71. {
  72. if (!_isDisabled())
  73. {
  74. if (_isOn())
  75. _setOn(false);
  76. }
  77. processed = true;
  78. }
  79. return processed;
  80. }
  81. bool GUIDropButton::_acceptDragAndDrop(const Vector2I position, UINT32 typeId) const
  82. {
  83. return typeId == mDragType && !_isDisabled();
  84. }
  85. }