BsGUIDockSlider.cpp 2.7 KB

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