BsGUIDropButton.cpp 2.5 KB

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