BsGUIDropButton.cpp 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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 "CmTexture.h"
  11. #include "BsDragAndDropManager.h"
  12. using namespace CamelotFramework;
  13. using namespace BansheeEngine;
  14. namespace BansheeEditor
  15. {
  16. const String& GUIDropButton::getGUITypeName()
  17. {
  18. static String name = "DropButton";
  19. return name;
  20. }
  21. GUIDropButton::GUIDropButton(GUIWidget& parent, CM::UINT32 dragType, const GUIElementStyle* style, const GUILayoutOptions& layoutOptions)
  22. :GUIButtonBase(parent, style, GUIContent(HString(L"None")), layoutOptions)
  23. {
  24. }
  25. GUIDropButton::~GUIDropButton()
  26. { }
  27. GUIDropButton* GUIDropButton::create(GUIWidget& parent, CM::UINT32 dragType, const GUIElementStyle* style)
  28. {
  29. if(style == nullptr)
  30. {
  31. const GUISkin& skin = parent.getSkin();
  32. style = skin.getStyle(getGUITypeName());
  33. }
  34. return new (cm_alloc<GUIDropButton, PoolAlloc>()) GUIDropButton(parent, dragType, style, GUILayoutOptions::create(style));
  35. }
  36. GUIDropButton* GUIDropButton::create(GUIWidget& parent, CM::UINT32 dragType, const GUIOptions& layoutOptions, const GUIElementStyle* style)
  37. {
  38. if(style == nullptr)
  39. {
  40. const GUISkin& skin = parent.getSkin();
  41. style = skin.getStyle(getGUITypeName());
  42. }
  43. return new (cm_alloc<GUIDropButton, PoolAlloc>()) GUIDropButton(parent, dragType, style, GUILayoutOptions::create(layoutOptions, style));
  44. }
  45. bool GUIDropButton::mouseEvent(const GUIMouseEvent& ev)
  46. {
  47. bool processed = GUIButtonBase::mouseEvent(ev);
  48. if(ev.getType() == GUIMouseEventType::MouseDragAndDropDragged)
  49. {
  50. if(DragAndDropManager::instance().isDragInProgress())
  51. {
  52. if(DragAndDropManager::instance().getDragTypeId() == mDragType)
  53. {
  54. if(!_isOn())
  55. _setOn(true);
  56. }
  57. else
  58. {
  59. if(_isOn())
  60. _setOn(false);
  61. }
  62. }
  63. else
  64. {
  65. if(_isOn())
  66. _setOn(false);
  67. }
  68. processed = true;
  69. }
  70. else if(ev.getType() == GUIMouseEventType::MouseDragAndDropDropped)
  71. {
  72. if(_isOn())
  73. _setOn(false);
  74. if(DragAndDropManager::instance().isDragInProgress() && DragAndDropManager::instance().getDragTypeId() == mDragType)
  75. {
  76. if(!onDataDropped.empty())
  77. onDataDropped(DragAndDropManager::instance().getDragData());
  78. }
  79. }
  80. return processed;
  81. }
  82. }