2
0

CGUITabControl.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. // Copyright (C) 2002-2012 Nikolaus Gebhardt
  2. // This file is part of the "Irrlicht Engine".
  3. // For conditions of distribution and use, see copyright notice in irrlicht.h
  4. #pragma once
  5. #include "IGUITabControl.h"
  6. #include "irrArray.h"
  7. #include "IGUISkin.h"
  8. namespace irr
  9. {
  10. namespace gui
  11. {
  12. class CGUITabControl;
  13. class IGUIButton;
  14. // A tab, onto which other gui elements could be added.
  15. class CGUITab : public IGUITab
  16. {
  17. public:
  18. //! constructor
  19. CGUITab(IGUIEnvironment *environment,
  20. IGUIElement *parent, const core::rect<s32> &rectangle,
  21. s32 id);
  22. //! draws the element and its children
  23. void draw() override;
  24. //! sets if the tab should draw its background
  25. void setDrawBackground(bool draw = true) override;
  26. //! sets the color of the background, if it should be drawn.
  27. void setBackgroundColor(video::SColor c) override;
  28. //! sets the color of the text
  29. void setTextColor(video::SColor c) override;
  30. //! returns true if the tab is drawing its background, false if not
  31. bool isDrawingBackground() const override;
  32. //! returns the color of the background
  33. video::SColor getBackgroundColor() const override;
  34. video::SColor getTextColor() const override;
  35. private:
  36. video::SColor BackColor;
  37. bool OverrideTextColorEnabled;
  38. video::SColor TextColor;
  39. bool DrawBackground;
  40. };
  41. //! A standard tab control
  42. class CGUITabControl : public IGUITabControl
  43. {
  44. public:
  45. //! destructor
  46. CGUITabControl(IGUIEnvironment *environment,
  47. IGUIElement *parent, const core::rect<s32> &rectangle,
  48. bool fillbackground = true, bool border = true, s32 id = -1);
  49. //! destructor
  50. virtual ~CGUITabControl();
  51. //! Adds a tab
  52. IGUITab *addTab(const wchar_t *caption, s32 id = -1) override;
  53. //! Adds an existing tab
  54. s32 addTab(IGUITab *tab) override;
  55. //! Insert the tab at the given index
  56. IGUITab *insertTab(s32 idx, const wchar_t *caption, s32 id = -1) override;
  57. //! Insert an existing tab
  58. /** Note that it will also add the tab as a child of this TabControl.
  59. \return Index of added tab (should be same as the one passed) or -1 for failure*/
  60. s32 insertTab(s32 idx, IGUITab *tab, bool serializationMode) override;
  61. //! Removes a tab from the tabcontrol
  62. void removeTab(s32 idx) override;
  63. //! Clears the tabcontrol removing all tabs
  64. void clear() override;
  65. //! Returns amount of tabs in the tabcontrol
  66. s32 getTabCount() const override;
  67. //! Returns a tab based on zero based index
  68. IGUITab *getTab(s32 idx) const override;
  69. //! Brings a tab to front.
  70. bool setActiveTab(s32 idx) override;
  71. //! Brings a tab to front.
  72. bool setActiveTab(IGUITab *tab) override;
  73. //! For given given tab find it's zero-based index (or -1 for not found)
  74. s32 getTabIndex(const IGUIElement *tab) const override;
  75. //! Returns which tab is currently active
  76. s32 getActiveTab() const override;
  77. //! get the the id of the tab at the given absolute coordinates
  78. s32 getTabAt(s32 xpos, s32 ypos) const override;
  79. //! called if an event happened.
  80. bool OnEvent(const SEvent &event) override;
  81. //! draws the element and its children
  82. void draw() override;
  83. //! Removes a child.
  84. void removeChild(IGUIElement *child) override;
  85. //! Set the height of the tabs
  86. void setTabHeight(s32 height) override;
  87. //! Get the height of the tabs
  88. s32 getTabHeight() const override;
  89. //! set the maximal width of a tab. Per default width is 0 which means "no width restriction".
  90. void setTabMaxWidth(s32 width) override;
  91. //! get the maximal width of a tab
  92. s32 getTabMaxWidth() const override;
  93. //! Set the alignment of the tabs
  94. //! note: EGUIA_CENTER is not an option
  95. void setTabVerticalAlignment(gui::EGUI_ALIGNMENT alignment) override;
  96. //! Get the alignment of the tabs
  97. gui::EGUI_ALIGNMENT getTabVerticalAlignment() const override;
  98. //! Set the extra width added to tabs on each side of the text
  99. void setTabExtraWidth(s32 extraWidth) override;
  100. //! Get the extra width added to tabs on each side of the text
  101. s32 getTabExtraWidth() const override;
  102. //! Update the position of the element, decides scroll button status
  103. void updateAbsolutePosition() override;
  104. private:
  105. void scrollLeft();
  106. void scrollRight();
  107. //! Indicates whether the tabs overflow in X direction
  108. bool needScrollControl(s32 startIndex = 0, bool withScrollControl = false, s32 *pos_rightmost = nullptr);
  109. //! Left index calculation based on the selected tab
  110. s32 calculateScrollIndexFromActive();
  111. s32 calcTabWidth(IGUIFont *font, const wchar_t *text) const;
  112. core::rect<s32> calcTabPos();
  113. void setVisibleTab(s32 idx);
  114. void removeTabButNotChild(s32 idx);
  115. void recalculateScrollButtonPlacement();
  116. void recalculateScrollBar();
  117. void refreshSprites();
  118. core::array<IGUITab *> Tabs;
  119. s32 ActiveTabIndex;
  120. bool Border;
  121. bool FillBackground;
  122. bool ScrollControl;
  123. s32 TabHeight;
  124. gui::EGUI_ALIGNMENT VerticalAlignment;
  125. IGUIButton *UpButton;
  126. IGUIButton *DownButton;
  127. s32 TabMaxWidth;
  128. s32 CurrentScrollTabIndex;
  129. s32 TabExtraWidth;
  130. };
  131. } // end namespace gui
  132. } // end namespace irr