SuperTuxKart
Loading...
Searching...
No Matches
list_widget.hpp
1// SuperTuxKart - a fun racing game with go-kart
2// Copyright (C) 2009-2015 Marianne Gagnon
3//
4// This program is free software; you can redistribute it and/or
5// modify it under the terms of the GNU General Public License
6// as published by the Free Software Foundation; either version 3
7// of the License, or (at your option) any later version.
8//
9// This program is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12// GNU General Public License for more details.
13//
14// You should have received a copy of the GNU General Public License
15// along with this program; if not, write to the Free Software
16// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17
18
19
20#ifndef HEADER_LISTWIDGET_HPP
21#define HEADER_LISTWIDGET_HPP
22
23#include <irrString.h>
24
25#include "guiengine/widgets/CGUISTKListBox.hpp"
26#include "guiengine/widget.hpp"
27#include "utils/leak_check.hpp"
28#include "utils/ptr_vector.hpp"
29#include "IGUIElement.h"
30
31
32namespace irr { namespace gui { class STKModifiedSpriteBank; } }
33
34namespace GUIEngine
35{
37 {
38 public:
40
41 virtual void onColumnClicked(int column_id, bool sort_desc, bool sort_default) = 0;
42 };
43
49 class ListWidget : public Widget
50 {
51 friend class Skin;
52
55
57 irr::gui::STKModifiedSpriteBank* m_icons;
58
59 PtrVector< Widget > m_header_elements;
60
61 Widget* m_selected_column;
62
65
68
71
72 bool m_choosing_header;
73
74 struct Column
75 {
76 irr::core::stringw m_text;
77 int m_proportion;
78 irr::video::ITexture* m_texture;
79 Column(irr::core::stringw text, int proportion)
80 {
81 m_text = text;
82 m_proportion = proportion;
83 m_texture = NULL;
84 }
85 Column(irr::video::ITexture* texture, int proportion)
86 {
87 m_proportion = proportion;
88 m_texture = texture;
89 }
90 };
91
93 std::vector< Column > m_header;
94
95 IListWidgetHeaderListener* m_listener;
96
97 bool m_sortable;
98
99 bool m_header_created;
100
101 void repairSortCol()
102 {
103 // Exclude scrollbar
104 int max_size = (int)m_header_elements.size() - 1;
105 if (m_sort_col < 0)
106 m_sort_col = max_size - 1;
107 else if (m_sort_col >= max_size)
108 m_sort_col = 0;
109 }
110
111 public:
112 typedef irr::gui::CGUISTKListBox::ListItem ListItem;
113 typedef ListItem::ListCell ListCell;
114
115 LEAK_CHECK()
116
117 ListWidget();
118
119 SkinWidgetContainer m_selection_skin_info;
120
122 virtual void add();
123
125 virtual void unfocused(const int playerID, Widget* new_focus);
126
128 virtual void elementRemoved();
129
139 void setIcons(irr::gui::STKModifiedSpriteBank* icons, int size=-1);
140
141
142 // ---- contents management
143
150 void addItem( const std::string& internal_name,
151 const irr::core::stringw &name,
152 const int icon=-1,
153 bool center = false);
154
155 void addItem( const std::string& internal_name,
156 const std::vector<ListCell>& contents);
157
162 void createHeader();
163
168 void clear();
169
174 void clearColumns();
175
180 int getItemCount() const;
181
186 int getSelectionID() const;
187
192 std::string getSelectionInternalName();
193
194 irr::core::stringw getSelectionLabel(const int cell = 0) const;
195
196 void selectItemWithLabel(const irr::core::stringw& name);
197
201 int getItemID(const std::string &internalName) const;
202
208 void setSelectionID(const int index);
209
214 void renameCell(const int row_num, const int col_num,
215 const irr::core::stringw &newName, const int icon=-1);
216
220 void renameItem(const int row_num,
221 const irr::core::stringw &newName, const int icon=-1);
222 void renameItem(const std::string & internal_name,
223 const irr::core::stringw &newName, const int icon=-1);
224
229 void renameCell(const std::string internalName, const int col_num,
230 const irr::core::stringw &newName, const int icon=-1)
231 {
232 const int id = getItemID(internalName);
233 assert(id != -1);
234 renameCell( id, col_num, newName, icon );
235 }
236
241 void markItemRed(const int id, bool red=true);
242 void markItemBlue(const int id, bool blue=true);
243 void emphasisItem(const int id, bool enable=true);
244
249 void markItemRed(const std::string &internalName, bool red=true)
250 {
251 const int id = getItemID(internalName);
252 assert(id != -1);
253 markItemRed( id, red );
254 }
255
256 void markItemBlue(const std::string &internalName, bool blue=true)
257 {
258 const int id = getItemID(internalName);
259 assert(id != -1);
260 markItemBlue( id, blue );
261 }
262
263 void emphasisItem(const std::string &internalName, bool enable=true)
264 {
265 const int id = getItemID(internalName);
266 assert(id != -1);
267 emphasisItem(id, enable);
268 }
269
271 virtual EventPropagation transmitEvent(Widget* w,
272 const std::string& originator,
273 const int playerID);
274
276 virtual EventPropagation upPressed(const int playerID);
277
279 virtual EventPropagation downPressed(const int playerID);
280
282 virtual EventPropagation leftPressed(const int playerID);
283
285 virtual EventPropagation rightPressed(const int playerID);
286
288 EventPropagation moveToNextItem(const bool down);
289
290 void setColumnListener(IListWidgetHeaderListener* listener)
291 {
292 if (m_listener) delete m_listener;
293 m_listener = listener;
294 }
295
299 void addColumn(irr::core::stringw col, int proportion=1) { m_header.push_back( Column(col, proportion) ); }
300 void addColumn(irr::video::ITexture* tex, int proportion=1) { m_header.push_back( Column(tex, proportion) ); }
301
302 void setSortable(bool sortable) { m_sortable = sortable; }
303 void focusHeader(const NavigationDirection nav);
304 virtual void setActive(bool active=true);
305 };
306}
307
308#endif
Definition: list_widget.hpp:37
A vertical list widget with text entries.
Definition: list_widget.hpp:50
virtual void add()
implement add method from base class GUIEngine::Widget
Definition: list_widget.cpp:98
virtual void unfocused(const int playerID, Widget *new_focus)
implement callback from base class GUIEngine::Widget
Definition: list_widget.cpp:374
int m_sort_col
index of column
Definition: list_widget.hpp:70
void renameItem(const int row_num, const irr::core::stringw &newName, const int icon=-1)
renames first cell only
Definition: list_widget.cpp:323
void markItemRed(const int id, bool red=true)
Make an item red to mark an error, for instance.
Definition: list_widget.cpp:450
bool m_use_icons
whether this list has icons
Definition: list_widget.hpp:54
int getItemCount() const
Definition: list_widget.cpp:421
bool m_sort_desc
whether this list is sorted in descending order
Definition: list_widget.hpp:64
virtual EventPropagation transmitEvent(Widget *w, const std::string &originator, const int playerID)
Override callback from Widget.
Definition: list_widget.cpp:513
std::vector< Column > m_header
Leave empty for no header.
Definition: list_widget.hpp:93
int getItemID(const std::string &internalName) const
Finds the ID of the item that has a given internal name.
Definition: list_widget.cpp:661
std::string getSelectionInternalName()
Definition: list_widget.cpp:340
EventPropagation moveToNextItem(const bool down)
implement common core parts of upPressed and downPressed
Definition: list_widget.cpp:621
virtual EventPropagation rightPressed(const int playerID)
implementing method from base class Widget
Definition: list_widget.cpp:588
int getSelectionID() const
Definition: list_widget.cpp:385
virtual EventPropagation upPressed(const int playerID)
implementing method from base class Widget
Definition: list_widget.cpp:558
virtual EventPropagation leftPressed(const int playerID)
implementing method from base class Widget
Definition: list_widget.cpp:572
virtual EventPropagation downPressed(const int playerID)
implementing method from base class Widget
Definition: list_widget.cpp:565
void addColumn(irr::core::stringw col, int proportion=1)
Columns are persistent across multiple "clear" add/remove cycles.
Definition: list_widget.hpp:299
bool m_sort_default
true when deault sorting is enabled
Definition: list_widget.hpp:67
virtual void setActive(bool active=true)
Sets an widget to be either activated or deactivated (i.e.
Definition: list_widget.cpp:669
void setIcons(irr::gui::STKModifiedSpriteBank *icons, int size=-1)
set the icon bank to use for list entries.
Definition: list_widget.cpp:55
irr::gui::STKModifiedSpriteBank * m_icons
if m_use_icons is true, this will contain the icon bank
Definition: list_widget.hpp:57
void clear()
erases all items in the list, don't clear header
Definition: list_widget.cpp:217
void addItem(const std::string &internal_name, const irr::core::stringw &name, const int icon=-1, bool center=false)
add an item to the list
Definition: list_widget.cpp:245
void markItemRed(const std::string &internalName, bool red=true)
Make an item red to mark an error, for instance.
Definition: list_widget.hpp:249
void renameCell(const int row_num, const int col_num, const irr::core::stringw &newName, const int icon=-1)
rename an item and/or change its icon based on its ID
Definition: list_widget.cpp:307
virtual void elementRemoved()
implement callback from base class GUIEngine::Widget
Definition: list_widget.cpp:433
void setSelectionID(const int index)
change the selected item
Definition: list_widget.cpp:395
void createHeader()
create a header based on m_header
Definition: list_widget.cpp:138
void clearColumns()
clear the header
Definition: list_widget.cpp:230
In order to avoid calculating render information every frame, it's stored in a SkinWidgetContainer fo...
Definition: skin.hpp:142
Object used to render the GUI widgets see Overview of GUI skin for more information about skinning in...
Definition: skin.hpp:269
The nearly-abstract base of all widgets (not fully abstract since a bare Widget can be created for th...
Definition: widget.hpp:143
Definition: ptr_vector.hpp:44
Contains all GUI engine related classes and functions.
Definition: abstract_state_manager.hpp:33
Definition: list_widget.hpp:75
Definition: CGUISTKListBox.hpp:31