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