2
0

BsGUIDropButton.cpp 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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(CM::UINT32 dragType, const CM::String& styleName, const GUILayoutOptions& layoutOptions)
  22. :GUIButtonBase(styleName, GUIContent(HString(L"None")), layoutOptions)
  23. {
  24. }
  25. GUIDropButton::~GUIDropButton()
  26. { }
  27. GUIDropButton* GUIDropButton::create(CM::UINT32 dragType, const CM::String& styleName)
  28. {
  29. return new (cm_alloc<GUIDropButton, PoolAlloc>()) GUIDropButton(dragType,
  30. getStyleName<GUIDropButton>(styleName), GUILayoutOptions::create());
  31. }
  32. GUIDropButton* GUIDropButton::create(CM::UINT32 dragType, const GUIOptions& layoutOptions, const CM::String& styleName)
  33. {
  34. return new (cm_alloc<GUIDropButton, PoolAlloc>()) GUIDropButton(dragType,
  35. getStyleName<GUIDropButton>(styleName), GUILayoutOptions::create(layoutOptions));
  36. }
  37. bool GUIDropButton::mouseEvent(const GUIMouseEvent& ev)
  38. {
  39. bool processed = GUIButtonBase::mouseEvent(ev);
  40. if(ev.getType() == GUIMouseEventType::MouseDragAndDropDragged)
  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. processed = true;
  61. }
  62. else if(ev.getType() == GUIMouseEventType::MouseDragAndDropDropped)
  63. {
  64. if(_isOn())
  65. _setOn(false);
  66. if(DragAndDropManager::instance().isDragInProgress() && DragAndDropManager::instance().getDragTypeId() == mDragType)
  67. {
  68. if(!onDataDropped.empty())
  69. onDataDropped(DragAndDropManager::instance().getDragData());
  70. }
  71. }
  72. return processed;
  73. }
  74. }