BsGUITabButton.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. #pragma once
  4. #include "BsEditorPrerequisites.h"
  5. #include "GUI/BsGUIToggle.h"
  6. #include "GUI/BsGUIToggleGroup.h"
  7. #include "2D/BsImageSprite.h"
  8. #include "Utility/BsEvent.h"
  9. namespace bs
  10. {
  11. /** @addtogroup GUI-Editor-Internal
  12. * @{
  13. */
  14. /**
  15. * Specialization of a GUIToggle element used for displaying tabs in a GUITabbedTitleBar. Aside from being toggleable
  16. * these buttons also track drag and drop operations.
  17. */
  18. class GUITabButton : public GUIToggle
  19. {
  20. public:
  21. /** Returns type name of the GUI element used for finding GUI element styles. */
  22. static const String& getGUITypeName();
  23. /**
  24. * Creates a new GUI tab button element.
  25. *
  26. * @param[in] toggleGroup A toggle group that forms a link between related tab buttons.
  27. * @param[in] index Unique index that can be used for identifying a tab.
  28. * @param[in] text Label to display in the button.
  29. * @param[in] styleName Optional style to use for the element. Style will be retrieved from GUISkin of the
  30. * GUIWidget the element is used on. If not specified default style is used.
  31. */
  32. static GUITabButton* create(const SPtr<GUIToggleGroup>& toggleGroup, UINT32 index, const HString& text,
  33. const String& styleName = StringUtil::BLANK);
  34. /**
  35. * Creates a new GUI tab button element.
  36. *
  37. * @param[in] toggleGroup A toggle group that forms a link between related tab buttons.
  38. * @param[in] index Unique index that can be used for identifying a tab.
  39. * @param[in] text Label to display in the button.
  40. * @param[in] options Options that allow you to control how is the element positioned and sized.
  41. * This will override any similar options set by style.
  42. * @param[in] styleName Optional style to use for the element. Style will be retrieved from GUISkin of the
  43. * GUIWidget the element is used on. If not specified default style is used.
  44. */
  45. static GUITabButton* create(const SPtr<GUIToggleGroup>& toggleGroup, UINT32 index, const HString& text,
  46. const GUIOptions& options, const String& styleName = StringUtil::BLANK);
  47. /**
  48. * Creates a new GUI tab button element.
  49. *
  50. * @param[in] toggleGroup A toggle group that forms a link between related tab buttons.
  51. * @param[in] index Unique index that can be used for identifying a tab.
  52. * @param[in] content Content to display in the button.
  53. * @param[in] styleName Optional style to use for the element. Style will be retrieved from GUISkin of the
  54. * GUIWidget the element is used on. If not specified default style is used.
  55. */
  56. static GUITabButton* create(const SPtr<GUIToggleGroup>& toggleGroup, UINT32 index, const GUIContent& content,
  57. const String& styleName = StringUtil::BLANK);
  58. /**
  59. * Creates a new GUI tab button element.
  60. *
  61. * @param[in] toggleGroup A toggle group that forms a link between related tab buttons.
  62. * @param[in] index Unique index that can be used for identifying a tab.
  63. * @param[in] content Content to display in the button.
  64. * @param[in] options Options that allow you to control how is the element positioned and sized.
  65. * This will override any similar options set by style.
  66. * @param[in] styleName Optional style to use for the element. Style will be retrieved from GUISkin of the
  67. * GUIWidget the element is used on. If not specified default style is used.
  68. */
  69. static GUITabButton* create(const SPtr<GUIToggleGroup>& toggleGroup, UINT32 index, const GUIContent& content,
  70. const GUIOptions& options, const String& styleName = StringUtil::BLANK);
  71. /** Returns the unique index for this tab button. */
  72. UINT32 getIndex() const { return mIndex; }
  73. /** Changes the button state to dragged or not dragged, resulting primarily in a visual change. */
  74. void _setDraggedState(bool active);
  75. /**
  76. * Triggered when the user starts dragging the tab button. Reported parameters are the unique index of the tab and
  77. * pointer position relative to parent GUIWidget.
  78. */
  79. Event<void(UINT32, const Vector2I&)> onDragged;
  80. /**
  81. * Triggered when the user ends dragging the tab button. Reported parameters are the unique index of the tab and
  82. * pointer position relative to parent GUIWidget.
  83. */
  84. Event<void(UINT32, const Vector2I&)> onDragEnd;
  85. protected:
  86. GUITabButton(const String& styleName, const SPtr<GUIToggleGroup>& toggleGroup, UINT32 index, const GUIContent& content, const GUIDimensions& dimensions);
  87. /** @copydoc GUIToggle::toggleOn */
  88. void _toggleOn(bool triggerEvents) override;
  89. /** @copydoc GUIToggle::toggleOff */
  90. void _toggleOff(bool triggerEvents) override;
  91. /** @copydoc GUIElement::_mouseEvent */
  92. bool _mouseEvent(const GUIMouseEvent& ev) override;
  93. UINT32 mIndex;
  94. Vector2I mDragStartPosition;
  95. bool mDraggedState;
  96. GUIElementState mInactiveState;
  97. static const UINT32 DRAG_MIN_DISTANCE;
  98. };
  99. /** @} */
  100. }