BsGUITabButton.cpp 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. #include "BsGUITabButton.h"
  2. #include "BsGUIWidget.h"
  3. #include "BsGUISkin.h"
  4. #include "BsGUILayoutOptions.h"
  5. #include "BsGUIMouseEvent.h"
  6. #include "BsGUITabbedTitleBar.h"
  7. using namespace CamelotFramework;
  8. using namespace BansheeEngine;
  9. namespace BansheeEditor
  10. {
  11. const CM::UINT32 GUITabButton::DRAG_MIN_DISTANCE = 3;
  12. const String& GUITabButton::getGUITypeName()
  13. {
  14. static String name = "TabButton";
  15. return name;
  16. }
  17. GUITabButton::GUITabButton(GUIWidget& parent, const GUIElementStyle* style, GUITabbedTitleBar* titleBar, CM::UINT32 index, const GUIContent& content, const GUILayoutOptions& layoutOptions)
  18. :GUIToggle(parent, style, content, nullptr, layoutOptions), mTitleBar(titleBar), mIndex(index)
  19. {
  20. }
  21. GUITabButton* GUITabButton::create(GUIWidget& parent, GUITabbedTitleBar* titleBar, CM::UINT32 index, const HString& text, const GUIElementStyle* style)
  22. {
  23. if(style == nullptr)
  24. {
  25. const GUISkin& skin = parent.getSkin();
  26. style = skin.getStyle(getGUITypeName());
  27. }
  28. return new (cm_alloc<GUITabButton, PoolAlloc>()) GUITabButton(parent, style, titleBar, index, GUIContent(text), GUILayoutOptions::create(style));
  29. }
  30. GUITabButton* GUITabButton::create(GUIWidget& parent, const GUIOptions& layoutOptions, GUITabbedTitleBar* titleBar, CM::UINT32 index, const HString& text, const GUIElementStyle* style)
  31. {
  32. if(style == nullptr)
  33. {
  34. const GUISkin& skin = parent.getSkin();
  35. style = skin.getStyle(getGUITypeName());
  36. }
  37. return new (cm_alloc<GUITabButton, PoolAlloc>()) GUITabButton(parent, style, titleBar, index, GUIContent(text), GUILayoutOptions::create(layoutOptions, style));
  38. }
  39. GUITabButton* GUITabButton::create(GUIWidget& parent, GUITabbedTitleBar* titleBar, CM::UINT32 index, const GUIContent& content, const GUIElementStyle* style)
  40. {
  41. if(style == nullptr)
  42. {
  43. const GUISkin& skin = parent.getSkin();
  44. style = skin.getStyle(getGUITypeName());
  45. }
  46. return new (cm_alloc<GUITabButton, PoolAlloc>()) GUITabButton(parent, style, titleBar, index, content, GUILayoutOptions::create(style));
  47. }
  48. GUITabButton* GUITabButton::create(GUIWidget& parent, const GUIOptions& layoutOptions, GUITabbedTitleBar* titleBar, CM::UINT32 index, const GUIContent& content, const GUIElementStyle* style)
  49. {
  50. if(style == nullptr)
  51. {
  52. const GUISkin& skin = parent.getSkin();
  53. style = skin.getStyle(getGUITypeName());
  54. }
  55. return new (cm_alloc<GUITabButton, PoolAlloc>()) GUITabButton(parent, style, titleBar, index, content, GUILayoutOptions::create(layoutOptions, style));
  56. }
  57. bool GUITabButton::mouseEvent(const GUIMouseEvent& ev)
  58. {
  59. bool eventProcessed = GUIToggle::mouseEvent(ev);
  60. if(ev.getType() == GUIMouseEventType::MouseDragStart)
  61. {
  62. mDragStartPosition = ev.getPosition();
  63. return true;
  64. }
  65. else if(ev.getType() == GUIMouseEventType::MouseDrag)
  66. {
  67. UINT32 dist = mDragStartPosition.manhattanDist(ev.getPosition());
  68. if(dist > DRAG_MIN_DISTANCE)
  69. {
  70. if(!onDragged.empty())
  71. onDragged(mIndex, ev.getPosition());
  72. }
  73. }
  74. else if(ev.getType() == GUIMouseEventType::MouseDragEnd)
  75. {
  76. UINT32 dist = mDragStartPosition.manhattanDist(ev.getPosition());
  77. if(dist > DRAG_MIN_DISTANCE)
  78. {
  79. if(!onDragEnd.empty())
  80. onDragEnd(mIndex, ev.getPosition());
  81. }
  82. }
  83. return eventProcessed;
  84. }
  85. }