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