SuperTuxKart
Loading...
Searching...
No Matches
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
19namespace 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
171 virtual void setDrawBackground(bool draw);
172
173 void setAlternatingDarkness(bool val) { m_alternating_darkness = val; }
174 gui::IGUIScrollBar* getScrollBar() const { return ScrollBar; }
175 void setDisactivated(bool val)
176 {
177 m_deactivated = val;
178 if (m_deactivated)
179 Selected = -1;
180 }
181 private:
182
183 void recalculateItemHeight();
184 void selectNew(s32 ypos, bool onlyHover=false);
185 void recalculateScrollPos();
186
187 // extracted that function to avoid copy&paste code
188 void recalculateIconWidth();
189
190 core::array< ListItem > Items;
191 s32 Selected;
192 s32 ItemHeight;
193 s32 ItemHeightOverride;
194 s32 TotalItemHeight;
195 s32 ItemsIconWidth;
196 s32 MousePosY;
197 gui::IGUIFont* Font;
198 gui::IGUISpriteBank* IconBank;
199 gui::IGUIScrollBar* ScrollBar;
200 u32 selectTime;
201 core::stringw KeyBuffer;
202 bool Selecting;
203 bool Moving;
204 bool DrawBack;
205 bool MoveOverSelect;
206 bool AutoScroll;
207 bool HighlightWhenNotFocused;
208 bool m_alternating_darkness;
209 bool m_deactivated;
210 };
211
212
213 } // end namespace gui
214} // end namespace irr
215
216#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:704
virtual video::SColor getItemOverrideColor(u32 index, EGUI_LISTBOX_COLOR colorType) const
return the overwrite color at given item index.
Definition: CGUISTKListBox.cpp:775
virtual void setItemHeight(s32 height)
set global itemHeight
Definition: CGUISTKListBox.cpp:806
virtual void draw()
draws the element and its children
Definition: CGUISTKListBox.cpp:472
virtual bool OnEvent(const SEvent &event)
called if an event happened.
Definition: CGUISTKListBox.cpp:257
virtual s32 getItemAt(s32 xpos, s32 ypos) const
get the the id of the item at the given absolute coordinates
Definition: CGUISTKListBox.cpp:134
virtual void setSelectedByCellText(const wchar_t *text)
sets the selected item. Set this to -1 if no item should be selected
Definition: CGUISTKListBox.cpp:238
virtual bool isAutoScrollEnabled() const
returns true if automatic scrolling is enabled, false if not.
Definition: CGUISTKListBox.cpp:677
virtual void setDrawBackground(bool draw)
Sets whether to draw the background.
Definition: CGUISTKListBox.cpp:814
virtual void swapItems(u32 index1, u32 index2)
Swap the items at the given indices.
Definition: CGUISTKListBox.cpp:717
virtual void removeItem(u32 id)
removes an item from the list
Definition: CGUISTKListBox.cpp:113
virtual video::SColor getItemDefaultColor(EGUI_LISTBOX_COLOR colorType) const
return the default color which is used for the given colorType
Definition: CGUISTKListBox.cpp:784
virtual u32 getItemCount() const
returns amount of list items
Definition: CGUISTKListBox.cpp:81
virtual void setSelected(s32 id)
sets the selected item. Set this to -1 if no item should be selected
Definition: CGUISTKListBox.cpp:208
virtual ~CGUISTKListBox()
destructor
Definition: CGUISTKListBox.cpp:67
virtual void clearItemOverrideColor(u32 index)
clear all item colors at index
Definition: CGUISTKListBox.cpp:748
virtual s32 getIcon(u32 row_num, u32 col_num) const
Returns the icon of an item.
Definition: CGUISTKListBox.cpp:104
virtual void setItemOverrideColor(u32 index, video::SColor color)
set all item colors at given index to color
Definition: CGUISTKListBox.cpp:728
virtual bool hasItemOverrideColor(u32 index, EGUI_LISTBOX_COLOR colorType) const
has the item at index its color overwritten?
Definition: CGUISTKListBox.cpp:766
virtual s32 getSelected() const
returns id of selected item. returns -1 if no item is selected.
Definition: CGUISTKListBox.cpp:201
virtual u32 addItem(const ListItem &item)
adds an list item with an icon
Definition: CGUISTKListBox.cpp:630
virtual void setSpriteBank(IGUISpriteBank *bank)
Sets the sprite bank which should be used to draw list icons.
Definition: CGUISTKListBox.cpp:639
virtual void updateAbsolutePosition()
Update the position and size of the listbox, and update the scrollbar.
Definition: CGUISTKListBox.cpp:463
virtual void clear()
clears the list
Definition: CGUISTKListBox.cpp:152
virtual void setAutoScrollEnabled(bool scroll)
set whether the listbox should scroll to newly selected items
Definition: CGUISTKListBox.cpp:671
Definition: spherical_harmonics.hpp:26
Definition: CGUISTKListBox.hpp:34
Definition: CGUISTKListBox.hpp:31