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 "IGUIListBox.h"
\r
9 #include "irrArray.h"
\r
17 class IGUIScrollBar;
\r
19 class CGUIListBox : public IGUIListBox
\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
28 virtual ~CGUIListBox();
\r
30 //! returns amount of list items
\r
31 u32 getItemCount() const override;
\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
36 //! adds an list item, returns id of item
\r
37 u32 addItem(const wchar_t* text) override;
\r
40 void clear() override;
\r
42 //! returns id of selected item. returns -1 if no item is selected.
\r
43 s32 getSelected() const override;
\r
45 //! sets the selected item. Set this to -1 if no item should be selected
\r
46 void setSelected(s32 id) override;
\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
51 //! called if an event happened.
\r
52 bool OnEvent(const SEvent& event) override;
\r
54 //! draws the element and its children
\r
55 void draw() override;
\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
61 //! returns the id of the new created item
\r
62 u32 addItem(const wchar_t* text, s32 icon) override;
\r
64 //! Returns the icon of an item
\r
65 s32 getIcon(u32 id) const override;
\r
67 //! removes an item from the list
\r
68 void removeItem(u32 id) override;
\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
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
79 //! set whether the listbox should scroll to newly selected items
\r
80 void setAutoScrollEnabled(bool scroll) override;
\r
82 //! returns true if automatic scrolling is enabled, false if not.
\r
83 bool isAutoScrollEnabled() const override;
\r
85 //! Update the position and size of the listbox, and update the scrollbar
\r
86 void updateAbsolutePosition() override;
\r
88 //! set all item colors at given index to color
\r
89 void setItemOverrideColor(u32 index, video::SColor color) override;
\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
94 //! clear all item colors at index
\r
95 void clearItemOverrideColor(u32 index) override;
\r
97 //! clear item color at index for given colortype
\r
98 void clearItemOverrideColor(u32 index, EGUI_LISTBOX_COLOR colorType) override;
\r
100 //! has the item at index its color overwritten?
\r
101 bool hasItemOverrideColor(u32 index, EGUI_LISTBOX_COLOR colorType) const override;
\r
103 //! return the overwrite color at given item index.
\r
104 video::SColor getItemOverrideColor(u32 index, EGUI_LISTBOX_COLOR colorType) const override;
\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
109 //! set the item at the given index
\r
110 void setItem(u32 index, const wchar_t* text, s32 icon) override;
\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
116 //! Swap the items at the given indices
\r
117 void swapItems(u32 index1, u32 index2) override;
\r
119 //! set global itemHeight
\r
120 void setItemHeight( s32 height ) override;
\r
122 //! Sets whether to draw the background
\r
123 void setDrawBackground(bool draw) override;
\r
125 //! Access the vertical scrollbar
\r
126 IGUIScrollBar* getVerticalScrollBar() const override;
\r
132 core::stringw Text;
\r
135 // A multicolor extension
\r
136 struct ListItemOverrideColor
\r
139 video::SColor Color;
\r
141 ListItemOverrideColor OverrideColors[EGUI_LBC_COUNT]{};
\r
144 void recalculateItemHeight();
\r
145 void selectNew(s32 ypos, bool onlyHover=false);
\r
146 void recalculateScrollPos();
\r
147 void updateScrollBarSize(s32 size);
\r
149 // extracted that function to avoid copy&paste code
\r
150 void recalculateItemWidth(s32 icon);
\r
152 // get labels used for serialization
\r
153 bool getSerializationLabels(EGUI_LISTBOX_COLOR colorType, core::stringc & useColorLabel, core::stringc & colorLabel) const;
\r
155 core::array< ListItem > Items;
\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
166 core::stringw KeyBuffer;
\r
169 bool MoveOverSelect;
\r
171 bool HighlightWhenNotFocused;
\r
175 } // end namespace gui
\r
176 } // end namespace irr
\r