BsGUITabButton.cpp 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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 WString& text, const GUILayoutOptions& layoutOptions)
  18. :GUIToggle(parent, style, text, nullptr, layoutOptions), mTitleBar(titleBar), mIndex(index)
  19. {
  20. }
  21. GUITabButton* GUITabButton::create(GUIWidget& parent, GUITabbedTitleBar* titleBar, CM::UINT32 index, const WString& 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, text, getDefaultLayoutOptions(style));
  29. }
  30. GUITabButton* GUITabButton::create(GUIWidget& parent, const GUILayoutOptions& layoutOptions, GUITabbedTitleBar* titleBar, CM::UINT32 index, const WString& 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, text, layoutOptions);
  38. }
  39. bool GUITabButton::mouseEvent(const GUIMouseEvent& ev)
  40. {
  41. bool eventProcessed = GUIToggle::mouseEvent(ev);
  42. if(ev.getType() == GUIMouseEventType::MouseDragStart)
  43. {
  44. mDragStartPosition = ev.getPosition();
  45. return true;
  46. }
  47. else if(ev.getType() == GUIMouseEventType::MouseDrag)
  48. {
  49. UINT32 dist = mDragStartPosition.manhattanDist(ev.getPosition());
  50. if(dist > DRAG_MIN_DISTANCE)
  51. {
  52. if(!onDragged.empty())
  53. onDragged(mIndex);
  54. }
  55. }
  56. return eventProcessed;
  57. }
  58. }