BsGUITabButton.cpp 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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);
  72. }
  73. }
  74. return eventProcessed;
  75. }
  76. }