BsGUIDropButton.cpp 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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, GUIElementOptions()), mDragType(dragType)
  16. {
  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. }