BsGUIDockSlider.cpp 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. #include "BsGUIDockSlider.h"
  2. #include "BsCGUIWidget.h"
  3. #include "BsGUISkin.h"
  4. #include "BsGUIDimensions.h"
  5. #include "BsGUIMouseEvent.h"
  6. #include "BsGUITabbedTitleBar.h"
  7. #include "BsCursor.h"
  8. #include "BsPlatform.h"
  9. namespace BansheeEngine
  10. {
  11. const String& GUIDockSlider::getGUITypeName()
  12. {
  13. static String name = "DockSlider";
  14. return name;
  15. }
  16. GUIDockSlider::GUIDockSlider(bool horizontal, const String& styleName, const GUIDimensions& dimensions)
  17. :GUIButtonBase(styleName, GUIContent(HString(L"")), dimensions),
  18. mDragInProgress(false), mHorizontal(horizontal), mIsCursorSet(false)
  19. {
  20. }
  21. GUIDockSlider* GUIDockSlider::create(bool horizontal, const String& styleName)
  22. {
  23. return new (bs_alloc<GUIDockSlider>()) GUIDockSlider(horizontal,
  24. getStyleName<GUIDockSlider>(styleName), GUIDimensions::create());
  25. }
  26. GUIDockSlider* GUIDockSlider::create(bool horizontal, const GUIOptions& options, const String& styleName)
  27. {
  28. return new (bs_alloc<GUIDockSlider>()) GUIDockSlider(horizontal,
  29. getStyleName<GUIDockSlider>(styleName), GUIDimensions::create(options));
  30. }
  31. bool GUIDockSlider::_hasCustomCursor(const Vector2I position, CursorType& type) const
  32. {
  33. if (_isInBounds(position) && !_isDisabled())
  34. {
  35. type = mHorizontal ? CursorType::SizeNS : CursorType::SizeWE;
  36. return true;
  37. }
  38. return false;
  39. }
  40. bool GUIDockSlider::_mouseEvent(const GUIMouseEvent& ev)
  41. {
  42. bool processed = GUIButtonBase::_mouseEvent(ev);
  43. if(ev.getType() == GUIMouseEventType::MouseDragStart)
  44. {
  45. if (!_isDisabled())
  46. {
  47. mLastDragPosition = ev.getPosition();
  48. mDragInProgress = true;
  49. }
  50. return true;
  51. }
  52. else if(ev.getType() == GUIMouseEventType::MouseDrag)
  53. {
  54. if (!_isDisabled())
  55. {
  56. Vector2I delta = ev.getPosition() - mLastDragPosition;
  57. mLastDragPosition = ev.getPosition();
  58. if (!onDragged.empty())
  59. onDragged(delta);
  60. }
  61. return true;
  62. }
  63. else if(ev.getType() == GUIMouseEventType::MouseDragEnd)
  64. {
  65. if (!_isDisabled())
  66. mDragInProgress = false;
  67. return true;
  68. }
  69. return processed;
  70. }
  71. }