2
0

BsGUIDockSlider.cpp 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. #include "BsGUIDockSlider.h"
  2. #include "BsGUIWidget.h"
  3. #include "BsGUISkin.h"
  4. #include "BsGUILayoutOptions.h"
  5. #include "BsGUIMouseEvent.h"
  6. #include "BsGUITabbedTitleBar.h"
  7. #include "BsCursor.h"
  8. #include "CmPlatform.h"
  9. using namespace CamelotFramework;
  10. using namespace BansheeEngine;
  11. namespace BansheeEditor
  12. {
  13. const String& GUIDockSlider::getGUITypeName()
  14. {
  15. static String name = "DockSlider";
  16. return name;
  17. }
  18. GUIDockSlider::GUIDockSlider(BS::GUIWidget& parent, bool horizontal, const BS::GUIElementStyle* style, const BS::GUILayoutOptions& layoutOptions)
  19. :GUIButtonBase(parent, style, GUIContent(HString(L"")), layoutOptions),
  20. mIsMouseOver(false), mDragInProgress(false), mHorizontal(horizontal), mIsCursorSet(false)
  21. {
  22. }
  23. GUIDockSlider* GUIDockSlider::create(GUIWidget& parent, bool horizontal, const GUIElementStyle* style)
  24. {
  25. if(style == nullptr)
  26. {
  27. const GUISkin& skin = parent.getSkin();
  28. style = skin.getStyle(getGUITypeName());
  29. }
  30. return new (cm_alloc<GUIDockSlider, PoolAlloc>()) GUIDockSlider(parent, horizontal, style, GUILayoutOptions::create(style));
  31. }
  32. GUIDockSlider* GUIDockSlider::create(GUIWidget& parent, bool horizontal, const GUIOptions& layoutOptions, const BS::GUIElementStyle* style)
  33. {
  34. if(style == nullptr)
  35. {
  36. const GUISkin& skin = parent.getSkin();
  37. style = skin.getStyle(getGUITypeName());
  38. }
  39. return new (cm_alloc<GUIDockSlider, PoolAlloc>()) GUIDockSlider(parent, horizontal, style, GUILayoutOptions::create(layoutOptions, style));
  40. }
  41. bool GUIDockSlider::mouseEvent(const GUIMouseEvent& ev)
  42. {
  43. bool processed = GUIButtonBase::mouseEvent(ev);
  44. if(ev.getType() == GUIMouseEventType::MouseOver)
  45. {
  46. mIsMouseOver = true;
  47. if(!mIsCursorSet)
  48. {
  49. Cursor::instance().setCursor(mHorizontal ? CursorType::SizeNS : CursorType::SizeWE);
  50. mIsCursorSet = true;
  51. }
  52. return true;
  53. }
  54. else if(ev.getType() == GUIMouseEventType::MouseOut)
  55. {
  56. mIsMouseOver = false;
  57. if(!mDragInProgress && mIsCursorSet)
  58. {
  59. Cursor::instance().setCursor(CursorType::Arrow);
  60. mIsCursorSet = false;
  61. }
  62. return true;
  63. }
  64. else if(ev.getType() == GUIMouseEventType::MouseDragStart)
  65. {
  66. mLastDragPosition = ev.getPosition();
  67. mDragInProgress = true;
  68. return true;
  69. }
  70. else if(ev.getType() == GUIMouseEventType::MouseDrag)
  71. {
  72. Vector2I delta = ev.getPosition() - mLastDragPosition;
  73. mLastDragPosition = ev.getPosition();
  74. if(!onDragged.empty())
  75. onDragged(delta);
  76. return true;
  77. }
  78. else if(ev.getType() == GUIMouseEventType::MouseDragEnd)
  79. {
  80. mDragInProgress = false;
  81. if(mIsCursorSet && !mIsMouseOver)
  82. {
  83. Cursor::instance().setCursor(CursorType::Arrow);
  84. mIsCursorSet = false;
  85. }
  86. return true;
  87. }
  88. return processed;
  89. }
  90. }