BsGUIDropButton.cpp 2.5 KB

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