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