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
5 #ifndef __C_GUI_LIST_BOX_H_INCLUDED__
\r
6 #define __C_GUI_LIST_BOX_H_INCLUDED__
\r
8 #include "IrrCompileConfig.h"
\r
9 #include "IGUIListBox.h"
\r
10 #include "irrArray.h"
\r
18 class IGUIScrollBar;
\r
20 class CGUIListBox : public IGUIListBox
\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
29 virtual ~CGUIListBox();
\r
31 //! returns amount of list items
\r
32 u32 getItemCount() const override;
\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
37 //! adds an list item, returns id of item
\r
38 u32 addItem(const wchar_t* text) override;
\r
41 void clear() override;
\r
43 //! returns id of selected item. returns -1 if no item is selected.
\r
44 s32 getSelected() const override;
\r
46 //! sets the selected item. Set this to -1 if no item should be selected
\r
47 void setSelected(s32 id) override;
\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
52 //! called if an event happened.
\r
53 bool OnEvent(const SEvent& event) override;
\r
55 //! draws the element and its children
\r
56 void draw() override;
\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
62 //! returns the id of the new created item
\r
63 u32 addItem(const wchar_t* text, s32 icon) override;
\r
65 //! Returns the icon of an item
\r
66 s32 getIcon(u32 id) const override;
\r
68 //! removes an item from the list
\r
69 void removeItem(u32 id) override;
\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
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
80 //! set whether the listbox should scroll to newly selected items
\r
81 void setAutoScrollEnabled(bool scroll) override;
\r
83 //! returns true if automatic scrolling is enabled, false if not.
\r
84 bool isAutoScrollEnabled() const override;
\r
86 //! Update the position and size of the listbox, and update the scrollbar
\r
87 void updateAbsolutePosition() override;
\r
89 //! set all item colors at given index to color
\r
90 void setItemOverrideColor(u32 index, video::SColor color) override;
\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
95 //! clear all item colors at index
\r
96 void clearItemOverrideColor(u32 index) override;
\r
98 //! clear item color at index for given colortype
\r
99 void clearItemOverrideColor(u32 index, EGUI_LISTBOX_COLOR colorType) override;
\r
101 //! has the item at index its color overwritten?
\r
102 bool hasItemOverrideColor(u32 index, EGUI_LISTBOX_COLOR colorType) const override;
\r
104 //! return the overwrite color at given item index.
\r
105 video::SColor getItemOverrideColor(u32 index, EGUI_LISTBOX_COLOR colorType) const override;
\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
110 //! set the item at the given index
\r
111 void setItem(u32 index, const wchar_t* text, s32 icon) override;
\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
117 //! Swap the items at the given indices
\r
118 void swapItems(u32 index1, u32 index2) override;
\r
120 //! set global itemHeight
\r
121 void setItemHeight( s32 height ) override;
\r
123 //! Sets whether to draw the background
\r
124 void setDrawBackground(bool draw) override;
\r
126 //! Access the vertical scrollbar
\r
127 IGUIScrollBar* getVerticalScrollBar() const override;
\r
133 core::stringw Text;
\r
136 // A multicolor extension
\r
137 struct ListItemOverrideColor
\r
140 video::SColor Color;
\r
142 ListItemOverrideColor OverrideColors[EGUI_LBC_COUNT]{};
\r
145 void recalculateItemHeight();
\r
146 void selectNew(s32 ypos, bool onlyHover=false);
\r
147 void recalculateScrollPos();
\r
148 void updateScrollBarSize(s32 size);
\r
150 // extracted that function to avoid copy&paste code
\r
151 void recalculateItemWidth(s32 icon);
\r
153 // get labels used for serialization
\r
154 bool getSerializationLabels(EGUI_LISTBOX_COLOR colorType, core::stringc & useColorLabel, core::stringc & colorLabel) const;
\r
156 core::array< ListItem > Items;
\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
167 core::stringw KeyBuffer;
\r
170 bool MoveOverSelect;
\r
172 bool HighlightWhenNotFocused;
\r
176 } // end namespace gui
\r
177 } // end namespace irr
\r