]> git.lizzy.rs Git - irrlicht.git/blob - source/Irrlicht/CGUIListBox.h
8e1566d6c6fd357e87df96a48f4c5ed4a84b8587
[irrlicht.git] / source / Irrlicht / CGUIListBox.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_LIST_BOX_H_INCLUDED__\r
6 #define __C_GUI_LIST_BOX_H_INCLUDED__\r
7 \r
8 #include "IrrCompileConfig.h"\r
9 #ifdef _IRR_COMPILE_WITH_GUI_\r
10 \r
11 #include "IGUIListBox.h"\r
12 #include "irrArray.h"\r
13 \r
14 namespace irr\r
15 {\r
16 namespace gui\r
17 {\r
18 \r
19         class IGUIFont;\r
20         class IGUIScrollBar;\r
21 \r
22         class CGUIListBox : public IGUIListBox\r
23         {\r
24         public:\r
25                 //! constructor\r
26                 CGUIListBox(IGUIEnvironment* environment, IGUIElement* parent,\r
27                         s32 id, core::rect<s32> rectangle, bool clip=true,\r
28                         bool drawBack=false, bool moveOverSelect=false);\r
29 \r
30                 //! destructor\r
31                 virtual ~CGUIListBox();\r
32 \r
33                 //! returns amount of list items\r
34                 u32 getItemCount() const override;\r
35 \r
36                 //! returns string of a list item. the id may be a value from 0 to itemCount-1\r
37                 const wchar_t* getListItem(u32 id) const override;\r
38 \r
39                 //! adds an list item, returns id of item\r
40                 u32 addItem(const wchar_t* text) override;\r
41 \r
42                 //! clears the list\r
43                 void clear() override;\r
44 \r
45                 //! returns id of selected item. returns -1 if no item is selected.\r
46                 s32 getSelected() const override;\r
47 \r
48                 //! sets the selected item. Set this to -1 if no item should be selected\r
49                 void setSelected(s32 id) override;\r
50 \r
51                 //! sets the selected item. Set this to -1 if no item should be selected\r
52                 void setSelected(const wchar_t *item) override;\r
53 \r
54                 //! called if an event happened.\r
55                 bool OnEvent(const SEvent& event) override;\r
56 \r
57                 //! draws the element and its children\r
58                 void draw() override;\r
59 \r
60                 //! adds an list item with an icon\r
61                 //! \param text Text of list entry\r
62                 //! \param icon Sprite index of the Icon within the current sprite bank. Set it to -1 if you want no icon\r
63                 //! \return\r
64                 //! returns the id of the new created item\r
65                 u32 addItem(const wchar_t* text, s32 icon) override;\r
66 \r
67                 //! Returns the icon of an item\r
68                 s32 getIcon(u32 id) const override;\r
69 \r
70                 //! removes an item from the list\r
71                 void removeItem(u32 id) override;\r
72 \r
73                 //! get the the id of the item at the given absolute coordinates\r
74                 s32 getItemAt(s32 xpos, s32 ypos) const override;\r
75 \r
76                 //! Sets the sprite bank which should be used to draw list icons. This font is set to the sprite bank of\r
77                 //! the built-in-font by default. A sprite can be displayed in front of every list item.\r
78                 //! An icon is an index within the icon sprite bank. Several default icons are available in the\r
79                 //! skin through getIcon\r
80                 void setSpriteBank(IGUISpriteBank* bank) override;\r
81 \r
82                 //! set whether the listbox should scroll to newly selected items\r
83                 void setAutoScrollEnabled(bool scroll) override;\r
84 \r
85                 //! returns true if automatic scrolling is enabled, false if not.\r
86                 bool isAutoScrollEnabled() const override;\r
87 \r
88                 //! Update the position and size of the listbox, and update the scrollbar\r
89                 void updateAbsolutePosition() override;\r
90 \r
91                 //! set all item colors at given index to color\r
92                 void setItemOverrideColor(u32 index, video::SColor color) override;\r
93 \r
94                 //! set all item colors of specified type at given index to color\r
95                 void setItemOverrideColor(u32 index, EGUI_LISTBOX_COLOR colorType, video::SColor color) override;\r
96 \r
97                 //! clear all item colors at index\r
98                 void clearItemOverrideColor(u32 index) override;\r
99 \r
100                 //! clear item color at index for given colortype\r
101                 void clearItemOverrideColor(u32 index, EGUI_LISTBOX_COLOR colorType) override;\r
102 \r
103                 //! has the item at index its color overwritten?\r
104                 bool hasItemOverrideColor(u32 index, EGUI_LISTBOX_COLOR colorType) const override;\r
105 \r
106                 //! return the overwrite color at given item index.\r
107                 video::SColor getItemOverrideColor(u32 index, EGUI_LISTBOX_COLOR colorType) const override;\r
108 \r
109                 //! return the default color which is used for the given colorType\r
110                 video::SColor getItemDefaultColor(EGUI_LISTBOX_COLOR colorType) const override;\r
111 \r
112                 //! set the item at the given index\r
113                 void setItem(u32 index, const wchar_t* text, s32 icon) override;\r
114 \r
115                 //! Insert the item at the given index\r
116                 //! Return the index on success or -1 on failure.\r
117                 s32 insertItem(u32 index, const wchar_t* text, s32 icon) override;\r
118 \r
119                 //! Swap the items at the given indices\r
120                 void swapItems(u32 index1, u32 index2) override;\r
121 \r
122                 //! set global itemHeight\r
123                 void setItemHeight( s32 height ) override;\r
124 \r
125                 //! Sets whether to draw the background\r
126                 void setDrawBackground(bool draw) override;\r
127 \r
128                 //! Access the vertical scrollbar\r
129                 IGUIScrollBar* getVerticalScrollBar() const override;\r
130 \r
131         private:\r
132 \r
133                 struct ListItem\r
134                 {\r
135                         core::stringw Text;\r
136                         s32 Icon = -1;\r
137 \r
138                         // A multicolor extension\r
139                         struct ListItemOverrideColor\r
140                         {\r
141                                 bool Use = false;\r
142                                 video::SColor Color;\r
143                         };\r
144                         ListItemOverrideColor OverrideColors[EGUI_LBC_COUNT]{};\r
145                 };\r
146 \r
147                 void recalculateItemHeight();\r
148                 void selectNew(s32 ypos, bool onlyHover=false);\r
149                 void recalculateScrollPos();\r
150                 void updateScrollBarSize(s32 size);\r
151 \r
152                 // extracted that function to avoid copy&paste code\r
153                 void recalculateItemWidth(s32 icon);\r
154 \r
155                 // get labels used for serialization\r
156                 bool getSerializationLabels(EGUI_LISTBOX_COLOR colorType, core::stringc & useColorLabel, core::stringc & colorLabel) const;\r
157 \r
158                 core::array< ListItem > Items;\r
159                 s32 Selected;\r
160                 s32 ItemHeight;\r
161                 s32 ItemHeightOverride;\r
162                 s32 TotalItemHeight;\r
163                 s32 ItemsIconWidth;\r
164                 gui::IGUIFont* Font;\r
165                 gui::IGUISpriteBank* IconBank;\r
166                 gui::IGUIScrollBar* ScrollBar;\r
167                 u32 selectTime;\r
168                 u32 LastKeyTime;\r
169                 core::stringw KeyBuffer;\r
170                 bool Selecting;\r
171                 bool DrawBack;\r
172                 bool MoveOverSelect;\r
173                 bool AutoScroll;\r
174                 bool HighlightWhenNotFocused;\r
175         };\r
176 \r
177 \r
178 } // end namespace gui\r
179 } // end namespace irr\r
180 \r
181 #endif // _IRR_COMPILE_WITH_GUI_\r
182 \r
183 #endif\r