BsGUITabButton.h 5.1 KB

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