BsGUIDockSlider.cpp 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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. 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::_hasCustomCursor(const CM::Vector2I position, CursorType& type) const
  42. {
  43. if(_isInBounds(position))
  44. {
  45. type = mHorizontal ? CursorType::SizeNS : CursorType::SizeWE;
  46. return true;
  47. }
  48. return false;
  49. }
  50. bool GUIDockSlider::mouseEvent(const GUIMouseEvent& ev)
  51. {
  52. bool processed = GUIButtonBase::mouseEvent(ev);
  53. if(ev.getType() == GUIMouseEventType::MouseDragStart)
  54. {
  55. mLastDragPosition = ev.getPosition();
  56. mDragInProgress = true;
  57. return true;
  58. }
  59. else if(ev.getType() == GUIMouseEventType::MouseDrag)
  60. {
  61. Vector2I delta = ev.getPosition() - mLastDragPosition;
  62. mLastDragPosition = ev.getPosition();
  63. if(!onDragged.empty())
  64. onDragged(delta);
  65. return true;
  66. }
  67. else if(ev.getType() == GUIMouseEventType::MouseDragEnd)
  68. {
  69. mDragInProgress = false;
  70. return true;
  71. }
  72. return processed;
  73. }
  74. }