2020-01-03 20:05:16 +01:00
// Copyright (C) 2002-2012 Nikolaus Gebhardt
// This file is part of the "Irrlicht Engine".
// For conditions of distribution and use, see copyright notice in irrlicht.h
# ifndef __C_GUI_LIST_BOX_H_INCLUDED__
# define __C_GUI_LIST_BOX_H_INCLUDED__
# include "IGUIListBox.h"
# include "irrArray.h"
namespace irr
{
namespace gui
{
class IGUIFont ;
class IGUIScrollBar ;
class CGUIListBox : public IGUIListBox
{
public :
//! constructor
CGUIListBox ( IGUIEnvironment * environment , IGUIElement * parent ,
s32 id , core : : rect < s32 > rectangle , bool clip = true ,
bool drawBack = false , bool moveOverSelect = false ) ;
//! destructor
virtual ~ CGUIListBox ( ) ;
//! returns amount of list items
2022-10-09 20:57:28 +02:00
u32 getItemCount ( ) const override ;
2020-01-03 20:05:16 +01:00
//! returns string of a list item. the id may be a value from 0 to itemCount-1
2022-10-09 20:57:28 +02:00
const wchar_t * getListItem ( u32 id ) const override ;
2020-01-03 20:05:16 +01:00
//! adds an list item, returns id of item
2022-10-09 20:57:28 +02:00
u32 addItem ( const wchar_t * text ) override ;
2020-01-03 20:05:16 +01:00
//! clears the list
2022-10-09 20:57:28 +02:00
void clear ( ) override ;
2020-01-03 20:05:16 +01:00
//! returns id of selected item. returns -1 if no item is selected.
2022-10-09 20:57:28 +02:00
s32 getSelected ( ) const override ;
2020-01-03 20:05:16 +01:00
//! sets the selected item. Set this to -1 if no item should be selected
2022-10-09 20:57:28 +02:00
void setSelected ( s32 id ) override ;
2020-01-03 20:05:16 +01:00
//! sets the selected item. Set this to -1 if no item should be selected
2022-10-09 20:57:28 +02:00
void setSelected ( const wchar_t * item ) override ;
2020-01-03 20:05:16 +01:00
//! called if an event happened.
2022-10-09 20:57:28 +02:00
bool OnEvent ( const SEvent & event ) override ;
2020-01-03 20:05:16 +01:00
//! draws the element and its children
2022-10-09 20:57:28 +02:00
void draw ( ) override ;
2020-01-03 20:05:16 +01:00
//! adds an list item with an icon
//! \param text Text of list entry
//! \param icon Sprite index of the Icon within the current sprite bank. Set it to -1 if you want no icon
//! \return
//! returns the id of the new created item
2022-10-09 20:57:28 +02:00
u32 addItem ( const wchar_t * text , s32 icon ) override ;
2020-01-03 20:05:16 +01:00
//! Returns the icon of an item
2022-10-09 20:57:28 +02:00
s32 getIcon ( u32 id ) const override ;
2020-01-03 20:05:16 +01:00
//! removes an item from the list
2022-10-09 20:57:28 +02:00
void removeItem ( u32 id ) override ;
2020-01-03 20:05:16 +01:00
//! get the the id of the item at the given absolute coordinates
2022-10-09 20:57:28 +02:00
s32 getItemAt ( s32 xpos , s32 ypos ) const override ;
2020-01-03 20:05:16 +01:00
//! Sets the sprite bank which should be used to draw list icons. This font is set to the sprite bank of
//! the built-in-font by default. A sprite can be displayed in front of every list item.
//! An icon is an index within the icon sprite bank. Several default icons are available in the
//! skin through getIcon
2022-10-09 20:57:28 +02:00
void setSpriteBank ( IGUISpriteBank * bank ) override ;
2020-01-03 20:05:16 +01:00
//! set whether the listbox should scroll to newly selected items
2022-10-09 20:57:28 +02:00
void setAutoScrollEnabled ( bool scroll ) override ;
2020-01-03 20:05:16 +01:00
//! returns true if automatic scrolling is enabled, false if not.
2022-10-09 20:57:28 +02:00
bool isAutoScrollEnabled ( ) const override ;
2020-01-03 20:05:16 +01:00
//! Update the position and size of the listbox, and update the scrollbar
2022-10-09 20:57:28 +02:00
void updateAbsolutePosition ( ) override ;
2020-01-03 20:05:16 +01:00
//! set all item colors at given index to color
2022-10-09 20:57:28 +02:00
void setItemOverrideColor ( u32 index , video : : SColor color ) override ;
2020-01-03 20:05:16 +01:00
//! set all item colors of specified type at given index to color
2022-10-09 20:57:28 +02:00
void setItemOverrideColor ( u32 index , EGUI_LISTBOX_COLOR colorType , video : : SColor color ) override ;
2020-01-03 20:05:16 +01:00
//! clear all item colors at index
2022-10-09 20:57:28 +02:00
void clearItemOverrideColor ( u32 index ) override ;
2020-01-03 20:05:16 +01:00
//! clear item color at index for given colortype
2022-10-09 20:57:28 +02:00
void clearItemOverrideColor ( u32 index , EGUI_LISTBOX_COLOR colorType ) override ;
2020-01-03 20:05:16 +01:00
//! has the item at index its color overwritten?
2022-10-09 20:57:28 +02:00
bool hasItemOverrideColor ( u32 index , EGUI_LISTBOX_COLOR colorType ) const override ;
2020-01-03 20:05:16 +01:00
//! return the overwrite color at given item index.
2022-10-09 20:57:28 +02:00
video : : SColor getItemOverrideColor ( u32 index , EGUI_LISTBOX_COLOR colorType ) const override ;
2020-01-03 20:05:16 +01:00
//! return the default color which is used for the given colorType
2022-10-09 20:57:28 +02:00
video : : SColor getItemDefaultColor ( EGUI_LISTBOX_COLOR colorType ) const override ;
2020-01-03 20:05:16 +01:00
//! set the item at the given index
2022-10-09 20:57:28 +02:00
void setItem ( u32 index , const wchar_t * text , s32 icon ) override ;
2020-01-03 20:05:16 +01:00
//! Insert the item at the given index
//! Return the index on success or -1 on failure.
2022-10-09 20:57:28 +02:00
s32 insertItem ( u32 index , const wchar_t * text , s32 icon ) override ;
2020-01-03 20:05:16 +01:00
//! Swap the items at the given indices
2022-10-09 20:57:28 +02:00
void swapItems ( u32 index1 , u32 index2 ) override ;
2020-01-03 20:05:16 +01:00
//! set global itemHeight
2022-10-09 20:57:28 +02:00
void setItemHeight ( s32 height ) override ;
2020-01-03 20:05:16 +01:00
//! Sets whether to draw the background
2022-10-09 20:57:28 +02:00
void setDrawBackground ( bool draw ) override ;
2020-01-03 20:05:16 +01:00
//! Access the vertical scrollbar
2022-10-09 20:57:28 +02:00
IGUIScrollBar * getVerticalScrollBar ( ) const override ;
2020-01-03 20:05:16 +01:00
private :
struct ListItem
{
core : : stringw Text ;
2022-07-07 21:44:15 +02:00
s32 Icon = - 1 ;
2020-01-03 20:05:16 +01:00
// A multicolor extension
struct ListItemOverrideColor
{
2022-07-07 21:44:15 +02:00
bool Use = false ;
2020-01-03 20:05:16 +01:00
video : : SColor Color ;
} ;
2022-07-07 21:44:15 +02:00
ListItemOverrideColor OverrideColors [ EGUI_LBC_COUNT ] { } ;
2020-01-03 20:05:16 +01:00
} ;
void recalculateItemHeight ( ) ;
void selectNew ( s32 ypos , bool onlyHover = false ) ;
void recalculateScrollPos ( ) ;
void updateScrollBarSize ( s32 size ) ;
// extracted that function to avoid copy&paste code
void recalculateItemWidth ( s32 icon ) ;
// get labels used for serialization
bool getSerializationLabels ( EGUI_LISTBOX_COLOR colorType , core : : stringc & useColorLabel , core : : stringc & colorLabel ) const ;
core : : array < ListItem > Items ;
s32 Selected ;
2023-03-06 15:34:16 +01:00
s32 HoverSelected ; // When >= 0 we're in the middle of changing selection while mouse is pressed. We need to know so selected again isn't called too often.
2020-01-03 20:05:16 +01:00
s32 ItemHeight ;
s32 ItemHeightOverride ;
s32 TotalItemHeight ;
s32 ItemsIconWidth ;
gui : : IGUIFont * Font ;
gui : : IGUISpriteBank * IconBank ;
gui : : IGUIScrollBar * ScrollBar ;
2023-03-06 15:34:16 +01:00
u32 SelectTime ;
2020-01-03 20:05:16 +01:00
u32 LastKeyTime ;
core : : stringw KeyBuffer ;
bool Selecting ;
bool DrawBack ;
bool MoveOverSelect ;
bool AutoScroll ;
bool HighlightWhenNotFocused ;
} ;
} // end namespace gui
} // end namespace irr
# endif