BsGUITabButton.cpp 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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, const GUIToggleGroupPtr& toggleGroup, CM::UINT32 index, const GUIContent& content, const GUILayoutOptions& layoutOptions)
  18. :GUIToggle(parent, style, content, toggleGroup, layoutOptions), mIndex(index)
  19. {
  20. }
  21. GUITabButton* GUITabButton::create(GUIWidget& parent, const GUIToggleGroupPtr& toggleGroup, 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, toggleGroup, index, GUIContent(text), GUILayoutOptions::create(style));
  29. }
  30. GUITabButton* GUITabButton::create(GUIWidget& parent, const GUIToggleGroupPtr& toggleGroup, CM::UINT32 index, const HString& text, const GUIOptions& layoutOptions, 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, toggleGroup, index, GUIContent(text), GUILayoutOptions::create(layoutOptions, style));
  38. }
  39. GUITabButton* GUITabButton::create(GUIWidget& parent, const GUIToggleGroupPtr& toggleGroup, 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, toggleGroup, index, content, GUILayoutOptions::create(style));
  47. }
  48. GUITabButton* GUITabButton::create(GUIWidget& parent, const GUIToggleGroupPtr& toggleGroup, CM::UINT32 index, const GUIContent& content, const GUIOptions& layoutOptions, 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, toggleGroup, index, content, GUILayoutOptions::create(layoutOptions, style));
  56. }
  57. bool GUITabButton::mouseEvent(const GUIMouseEvent& ev)
  58. {
  59. bool eventProcessed = GUIButtonBase::mouseEvent(ev);
  60. if(ev.getType() == GUIMouseEventType::MouseUp)
  61. {
  62. if(!mIsToggled)
  63. toggleOn();
  64. return true;
  65. }
  66. else if(ev.getType() == GUIMouseEventType::MouseDragStart)
  67. {
  68. mDragStartPosition = ev.getPosition();
  69. return true;
  70. }
  71. else if(ev.getType() == GUIMouseEventType::MouseDrag)
  72. {
  73. UINT32 dist = mDragStartPosition.manhattanDist(ev.getPosition());
  74. if(dist > DRAG_MIN_DISTANCE)
  75. {
  76. if(!onDragged.empty())
  77. onDragged(mIndex, ev.getPosition());
  78. }
  79. return true;
  80. }
  81. else if(ev.getType() == GUIMouseEventType::MouseDragEnd)
  82. {
  83. UINT32 dist = mDragStartPosition.manhattanDist(ev.getPosition());
  84. if(dist > DRAG_MIN_DISTANCE)
  85. {
  86. if(!onDragEnd.empty())
  87. onDragEnd(mIndex, ev.getPosition());
  88. }
  89. return true;
  90. }
  91. return eventProcessed;
  92. }
  93. }