1
// Copyright (C) 2002-2011 Nikolaus Gebhardt
2
// This file is part of the "Irrlicht Engine".
3
// For conditions of distribution and use, see copyright notice in irrlicht.h
5
#ifndef __C_GUI_LIST_BOX_H_INCLUDED__
6
#define __C_GUI_LIST_BOX_H_INCLUDED__
8
#include "IrrCompileConfig.h"
9
#ifdef _IRR_COMPILE_WITH_GUI_
11
#include "IGUIListBox.h"
22
class CGUIListBox : public IGUIListBox
26
CGUIListBox(IGUIEnvironment* environment, IGUIElement* parent,
27
s32 id, core::rect<s32> rectangle, bool clip=true,
28
bool drawBack=false, bool moveOverSelect=false);
31
virtual ~CGUIListBox();
33
//! returns amount of list items
34
virtual u32 getItemCount() const;
36
//! returns string of a list item. the id may be a value from 0 to itemCount-1
37
virtual const wchar_t* getListItem(u32 id) const;
39
//! adds an list item, returns id of item
40
virtual u32 addItem(const wchar_t* text);
45
//! returns id of selected item. returns -1 if no item is selected.
46
virtual s32 getSelected() const;
48
//! sets the selected item. Set this to -1 if no item should be selected
49
virtual void setSelected(s32 id);
51
//! sets the selected item. Set this to -1 if no item should be selected
52
virtual void setSelected(const wchar_t *item);
54
//! called if an event happened.
55
virtual bool OnEvent(const SEvent& event);
57
//! draws the element and its children
60
//! adds an list item with an icon
61
//! \param text Text of list entry
62
//! \param icon Sprite index of the Icon within the current sprite bank. Set it to -1 if you want no icon
64
//! returns the id of the new created item
65
virtual u32 addItem(const wchar_t* text, s32 icon);
67
//! Returns the icon of an item
68
virtual s32 getIcon(u32 id) const;
70
//! removes an item from the list
71
virtual void removeItem(u32 id);
73
//! get the the id of the item at the given absolute coordinates
74
virtual s32 getItemAt(s32 xpos, s32 ypos) const;
76
//! Sets the sprite bank which should be used to draw list icons. This font is set to the sprite bank of
77
//! the built-in-font by default. A sprite can be displayed in front of every list item.
78
//! An icon is an index within the icon sprite bank. Several default icons are available in the
79
//! skin through getIcon
80
virtual void setSpriteBank(IGUISpriteBank* bank);
82
//! set whether the listbox should scroll to newly selected items
83
virtual void setAutoScrollEnabled(bool scroll);
85
//! returns true if automatic scrolling is enabled, false if not.
86
virtual bool isAutoScrollEnabled() const;
88
//! Update the position and size of the listbox, and update the scrollbar
89
virtual void updateAbsolutePosition();
91
//! Writes attributes of the element.
92
virtual void serializeAttributes(io::IAttributes* out, io::SAttributeReadWriteOptions* options) const;
94
//! Reads attributes of the element
95
virtual void deserializeAttributes(io::IAttributes* in, io::SAttributeReadWriteOptions* options);
97
//! set all item colors at given index to color
98
virtual void setItemOverrideColor(u32 index, const video::SColor &color);
100
//! set all item colors of specified type at given index to color
101
virtual void setItemOverrideColor(u32 index, EGUI_LISTBOX_COLOR colorType, const video::SColor &color);
103
//! clear all item colors at index
104
virtual void clearItemOverrideColor(u32 index);
106
//! clear item color at index for given colortype
107
virtual void clearItemOverrideColor(u32 index, EGUI_LISTBOX_COLOR colorType);
109
//! has the item at index its color overwritten?
110
virtual bool hasItemOverrideColor(u32 index, EGUI_LISTBOX_COLOR colorType) const;
112
//! return the overwrite color at given item index.
113
virtual video::SColor getItemOverrideColor(u32 index, EGUI_LISTBOX_COLOR colorType) const;
115
//! return the default color which is used for the given colorType
116
virtual video::SColor getItemDefaultColor(EGUI_LISTBOX_COLOR colorType) const;
118
//! set the item at the given index
119
virtual void setItem(u32 index, const wchar_t* text, s32 icon);
121
//! Insert the item at the given index
122
//! Return the index on success or -1 on failure.
123
virtual s32 insertItem(u32 index, const wchar_t* text, s32 icon);
125
//! Swap the items at the given indices
126
virtual void swapItems(u32 index1, u32 index2);
128
//! set global itemHeight
129
virtual void setItemHeight( s32 height );
131
//! Sets whether to draw the background
132
virtual void setDrawBackground(bool draw);
139
ListItem() : icon(-1)
145
// A multicolor extension
146
struct ListItemOverrideColor
148
ListItemOverrideColor() : Use(false) {}
152
ListItemOverrideColor OverrideColors[EGUI_LBC_COUNT];
155
void recalculateItemHeight();
156
void selectNew(s32 ypos, bool onlyHover=false);
157
void recalculateScrollPos();
159
// extracted that function to avoid copy&paste code
160
void recalculateItemWidth(s32 icon);
162
// get labels used for serialization
163
bool getSerializationLabels(EGUI_LISTBOX_COLOR colorType, core::stringc & useColorLabel, core::stringc & colorLabel) const;
165
core::array< ListItem > Items;
168
s32 ItemHeightOverride;
172
gui::IGUISpriteBank* IconBank;
173
gui::IGUIScrollBar* ScrollBar;
176
core::stringw KeyBuffer;
181
bool HighlightWhenNotFocused;
185
} // end namespace gui
186
} // end namespace irr
188
#endif // _IRR_COMPILE_WITH_GUI_