SuperTuxKart
CGUISTKListBox.hpp
1 // Copyright (C) 2002-2015 Nikolaus Gebhardt
2 // 2013 Glenn De Jonghe
3 // This file is part of the "Irrlicht Engine".
4 // For conditions of distribution and use, see copyright notice in irrlicht.h
5 
6 #ifndef HEADER_CGUISTKListBox_HPP
7 #define HEADER_CGUISTKListBox_HPP
8 
9 #include "IrrCompileConfig.h"
10 
11 #include "IGUIListBox.h"
12 #include "IGUIElement.h"
13 #include "irrArray.h"
14 #include <string>
15 #include <vector>
16 
17 #include "GlyphLayout.h"
18 
19 namespace irr
20 {
21  namespace gui
22  {
23  class IGUIFont;
24  class IGUIScrollBar;
25 
26  class CGUISTKListBox : public IGUIElement
27  {
28  public:
29 
30  struct ListItem
31  {
32 
33  struct ListCell
34  {
35  irr::core::stringw m_text;
36  int m_proportion;
37  s32 m_icon;
38  std::vector<GlyphLayout> m_glyph_layouts;
39  bool m_center;
40 
41  ListCell(irr::core::stringw text, s32 icon = -1, int proportion = 1, bool center = false)
42  {
43  m_text = text;
44  m_proportion = proportion;
45  m_icon = icon;
46  m_center = center;
47  }
48  };
49 
50  core::array< ListCell > m_contents;
51 
52  // Actually only used in list_widget -- still refactoring FIXME
53  std::string m_internal_name;
54  int m_current_id;
55 
56  bool m_word_wrap = false;
57  float m_line_height_scale = 0.0f;
58 
59  // A multicolor extension
61  {
62  ListItemOverrideColor() : Use(false) {}
63  bool Use;
64  video::SColor Color;
65  };
66 
67  ListItemOverrideColor OverrideColors[EGUI_LBC_COUNT];
68  };
69 
71  CGUISTKListBox(IGUIEnvironment* environment, IGUIElement* parent,
72  s32 id, core::rect<s32> rectangle, bool clip=true,
73  bool drawBack=false, bool moveOverSelect=false);
74 
76  virtual ~CGUISTKListBox();
77 
79  virtual u32 getItemCount() const;
80 
81  virtual const wchar_t* getCellText(u32 row_num, u32 col_num) const;
82 
83  virtual ListItem getItem(u32 id) const;
84 
86  virtual void clear();
87 
89  virtual s32 getSelected() const;
90 
92  virtual void setSelected(s32 id);
93 
94  virtual s32 getRowByCellText(const wchar_t * text);
95 
97  virtual void setSelectedByCellText(const wchar_t * text);
98 
99  virtual s32 getRowByInternalName(const std::string & text) const;
100 
102  virtual bool OnEvent(const SEvent& event);
103 
105  virtual void draw();
106 
112  //virtual u32 addItem(const wchar_t* text, s32 icon);
113 
114  virtual u32 addItem(const ListItem & item);
115 
117  virtual s32 getIcon(u32 row_num, u32 col_num) const;
118 
120  virtual void removeItem(u32 id);
121 
123  virtual s32 getItemAt(s32 xpos, s32 ypos) const;
124 
129  virtual void setSpriteBank(IGUISpriteBank* bank);
130 
132  virtual void setAutoScrollEnabled(bool scroll);
133 
135  virtual bool isAutoScrollEnabled() const;
136 
138  virtual void updateAbsolutePosition();
139 
141  virtual void setItemOverrideColor(u32 index, video::SColor color);
142 
144  virtual void setItemOverrideColor(u32 index, EGUI_LISTBOX_COLOR colorType, video::SColor color);
145 
147  virtual void clearItemOverrideColor(u32 index);
148 
150  virtual void clearItemOverrideColor(u32 index, EGUI_LISTBOX_COLOR colorType);
151 
153  virtual bool hasItemOverrideColor(u32 index, EGUI_LISTBOX_COLOR colorType) const;
154 
156  virtual video::SColor getItemOverrideColor(u32 index, EGUI_LISTBOX_COLOR colorType) const;
157 
159  virtual video::SColor getItemDefaultColor(EGUI_LISTBOX_COLOR colorType) const;
160 
162  virtual void setCell(u32 row_num, u32 col_num, const wchar_t* text, s32 icon);
163 
165  virtual void swapItems(u32 index1, u32 index2);
166 
168  virtual void setItemHeight( s32 height );
169 
170  /* return item height */
171  int getItemHeight() { return (int) m_item_height; }
172 
174  virtual void setDrawBackground(bool draw);
175 
176  void setAlternatingDarkness(bool val) { m_alternating_darkness = val; }
177  gui::IGUIScrollBar* getScrollBar() const { return ScrollBar; }
178  void setDisactivated(bool val)
179  {
180  m_deactivated = val;
181  if (m_deactivated)
182  Selected = -1;
183  }
184  private:
185 
186  void recalculateItemHeight();
187  void updateDefaultItemHeight();
188  void selectNew(s32 ypos, bool onlyHover=false);
189  void recalculateScrollPos();
190  void updateScrollBarSize(s32 size);
191 
192  // extracted that function to avoid copy&paste code
193  void recalculateIconWidth();
194 
195  core::array< ListItem > Items;
196  s32 Selected;
197  s32 m_item_height;
198  s32 ItemHeightOverride;
199  s32 TotalItemHeight;
200  s32 ItemsIconWidth;
201  s32 MousePosY;
202  gui::IGUIFont* Font;
203  gui::IGUISpriteBank* IconBank;
204  gui::IGUIScrollBar* ScrollBar;
205  u32 selectTime;
206  core::stringw KeyBuffer;
207  bool Selecting;
208  bool Moving;
209  bool DrawBack;
210  bool MoveOverSelect;
211  bool AutoScroll;
212  bool HighlightWhenNotFocused;
213  bool m_alternating_darkness;
214  bool m_deactivated;
215  };
216 
217 
218  } // end namespace gui
219 } // end namespace irr
220 
221 #endif
Definition: CGUISTKListBox.hpp:27
virtual void setCell(u32 row_num, u32 col_num, const wchar_t *text, s32 icon)
set the item at the given index
Definition: CGUISTKListBox.cpp:646
virtual video::SColor getItemOverrideColor(u32 index, EGUI_LISTBOX_COLOR colorType) const
return the overwrite color at given item index.
Definition: CGUISTKListBox.cpp:717
virtual void setItemHeight(s32 height)
set global itemHeight
Definition: CGUISTKListBox.cpp:748
virtual void draw()
draws the element and its children
Definition: CGUISTKListBox.cpp:413
virtual bool OnEvent(const SEvent &event)
called if an event happened.
Definition: CGUISTKListBox.cpp:261
virtual s32 getItemAt(s32 xpos, s32 ypos) const
get the the id of the item at the given absolute coordinates
Definition: CGUISTKListBox.cpp:133
virtual void setSelectedByCellText(const wchar_t *text)
sets the selected item. Set this to -1 if no item should be selected
Definition: CGUISTKListBox.cpp:242
virtual bool isAutoScrollEnabled() const
returns true if automatic scrolling is enabled, false if not.
Definition: CGUISTKListBox.cpp:619
virtual void setDrawBackground(bool draw)
Sets whether to draw the background.
Definition: CGUISTKListBox.cpp:756
virtual void swapItems(u32 index1, u32 index2)
Swap the items at the given indices.
Definition: CGUISTKListBox.cpp:659
virtual void removeItem(u32 id)
removes an item from the list
Definition: CGUISTKListBox.cpp:112
virtual video::SColor getItemDefaultColor(EGUI_LISTBOX_COLOR colorType) const
return the default color which is used for the given colorType
Definition: CGUISTKListBox.cpp:726
virtual u32 getItemCount() const
returns amount of list items
Definition: CGUISTKListBox.cpp:80
virtual void setSelected(s32 id)
sets the selected item. Set this to -1 if no item should be selected
Definition: CGUISTKListBox.cpp:212
virtual ~CGUISTKListBox()
destructor
Definition: CGUISTKListBox.cpp:66
virtual void clearItemOverrideColor(u32 index)
clear all item colors at index
Definition: CGUISTKListBox.cpp:690
virtual s32 getIcon(u32 row_num, u32 col_num) const
Returns the icon of an item.
Definition: CGUISTKListBox.cpp:103
CGUISTKListBox(IGUIEnvironment *environment, IGUIElement *parent, s32 id, core::rect< s32 > rectangle, bool clip=true, bool drawBack=false, bool moveOverSelect=false)
constructor
Definition: CGUISTKListBox.cpp:27
virtual void setItemOverrideColor(u32 index, video::SColor color)
set all item colors at given index to color
Definition: CGUISTKListBox.cpp:670
virtual bool hasItemOverrideColor(u32 index, EGUI_LISTBOX_COLOR colorType) const
has the item at index its color overwritten?
Definition: CGUISTKListBox.cpp:708
virtual s32 getSelected() const
returns id of selected item. returns -1 if no item is selected.
Definition: CGUISTKListBox.cpp:205
virtual u32 addItem(const ListItem &item)
adds an list item with an icon
Definition: CGUISTKListBox.cpp:572
virtual void setSpriteBank(IGUISpriteBank *bank)
Sets the sprite bank which should be used to draw list icons.
Definition: CGUISTKListBox.cpp:581
virtual void updateAbsolutePosition()
Update the position and size of the listbox, and update the scrollbar.
Definition: CGUISTKListBox.cpp:393
virtual void clear()
clears the list
Definition: CGUISTKListBox.cpp:151
virtual void setAutoScrollEnabled(bool scroll)
set whether the listbox should scroll to newly selected items
Definition: CGUISTKListBox.cpp:613
Definition: spherical_harmonics.hpp:26
Definition: CGUISTKListBox.hpp:34
Definition: CGUISTKListBox.hpp:31