BsGUIDropButton.cpp 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. #include "BsGUIDropButton.h"
  2. #include "BsImageSprite.h"
  3. #include "BsGUIWidget.h"
  4. #include "BsGUISkin.h"
  5. #include "BsSpriteTexture.h"
  6. #include "BsTextSprite.h"
  7. #include "BsGUILayoutOptions.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 GUILayoutOptions& layoutOptions)
  20. :GUIButtonBase(styleName, GUIContent(HString(L"None")), layoutOptions)
  21. {
  22. }
  23. GUIDropButton::~GUIDropButton()
  24. { }
  25. GUIDropButton* GUIDropButton::create(UINT32 dragType, const String& styleName)
  26. {
  27. return new (bs_alloc<GUIDropButton, PoolAlloc>()) GUIDropButton(dragType,
  28. getStyleName<GUIDropButton>(styleName), GUILayoutOptions::create());
  29. }
  30. GUIDropButton* GUIDropButton::create(UINT32 dragType, const GUIOptions& layoutOptions, const String& styleName)
  31. {
  32. return new (bs_alloc<GUIDropButton, PoolAlloc>()) GUIDropButton(dragType,
  33. getStyleName<GUIDropButton>(styleName), GUILayoutOptions::create(layoutOptions));
  34. }
  35. bool GUIDropButton::mouseEvent(const GUIMouseEvent& ev)
  36. {
  37. bool processed = GUIButtonBase::mouseEvent(ev);
  38. if(ev.getType() == GUIMouseEventType::MouseDragAndDropDragged)
  39. {
  40. if(DragAndDropManager::instance().isDragInProgress())
  41. {
  42. if(DragAndDropManager::instance().getDragTypeId() == mDragType)
  43. {
  44. if(!_isOn())
  45. _setOn(true);
  46. }
  47. else
  48. {
  49. if(_isOn())
  50. _setOn(false);
  51. }
  52. }
  53. else
  54. {
  55. if(_isOn())
  56. _setOn(false);
  57. }
  58. processed = true;
  59. }
  60. else if(ev.getType() == GUIMouseEventType::MouseDragAndDropDropped)
  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. return processed;
  71. }
  72. }