SuperTuxKart
Loading...
Searching...
No Matches
ribbon_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_RIBBON_HPP
21#define HEADER_RIBBON_HPP
22
23#include <irrString.h>
24
25#include "guiengine/widget.hpp"
26#include "guiengine/widgets/icon_button_widget.hpp"
27#include "utils/cpp2011.hpp"
28#include "utils/leak_check.hpp"
29#include "utils/ptr_vector.hpp"
30
31#include <IGUIStaticText.h>
32
33namespace GUIEngine
34{
37 {
42 };
43
46 {
47 FLIP_NO, // For non-tab ribbons
48 FLIP_UP_LEFT, // For horizontal tabs it goes up vertical ones it goes left
49 FLIP_DOWN_RIGHT // For horizontal tabs it goes down vertical ones it goes right
50 };
51
59 class RibbonWidget : public Widget
60 {
61 public:
63 {
64 public:
65 virtual ~IRibbonListener(){}
66 virtual void onRibbonWidgetScroll(const int delta_x) = 0;
67 virtual void onRibbonWidgetFocus(RibbonWidget* emitter,
68 const int playerID) = 0;
69 virtual void onSelectionChange() = 0;
70 };
71
72 private:
73 friend class DynamicRibbonWidget;
74 friend class EventHandler;
75
76 int m_selection[MAX_PLAYER_COUNT];
77
80
83
87 void updateSelection();
88
90 virtual EventPropagation rightPressed(const int playerID=0) OVERRIDE;
91 virtual EventPropagation leftPressed (const int playerID=0) OVERRIDE;
92 virtual EventPropagation upPressed (const int playerID=0) OVERRIDE;
93 virtual EventPropagation downPressed (const int playerID=0) OVERRIDE;
94 EventPropagation moveToNextItem(const bool horizontally, const bool reverse, const int playerID);
95 EventPropagation propagationType(const bool horizontally);
96 void selectNextActiveWidget(const bool horizontally, const bool reverse,
97 const int playerID, const int old_selection);
98 virtual EventPropagation mouseHovered(Widget* child,
99 const int playerID) OVERRIDE;
100 virtual EventPropagation transmitEvent(Widget* w,
101 const std::string& originator,
102 const int playerID=0) OVERRIDE;
103 virtual EventPropagation focused(const int playerID) OVERRIDE;
104 virtual void unfocused(const int playerID, Widget* new_focus) OVERRIDE;
105
106 virtual EventPropagation onClick() OVERRIDE;
107
108 PtrVector<irr::gui::IGUIStaticText, REF> m_labels;
109
110 IRibbonListener* m_listener;
111 PtrVector<Widget> m_active_children;
112
113 public:
114
115 LEAK_CHECK()
116
122 static const char NO_ITEM_ID[];
123
128
130 virtual ~RibbonWidget();
131
132 virtual void add() OVERRIDE;
133
138 void setListener(IRibbonListener* listener) { m_listener = listener; }
139 // --------------------------------------------------------------------
143 // --------------------------------------------------------------------
146 // --------------------------------------------------------------------
148 int getActiveChildrenNumber(const int playerID) const
149 { return m_active_children.size(); }
150 // --------------------------------------------------------------------
152 int getSelection(const int playerID) const
153 { return m_selection[playerID]; }
154 // --------------------------------------------------------------------
156 const std::string& getSelectionIDString(const int playerID);
157 // --------------------------------------------------------------------
159 irr::core::stringw getSelectionText(const int playerID)
160 {
161 const int selection = m_selection[playerID];
162 if (selection < 0 || selection >= int(m_children.size())) return "";
163 return m_children[selection].m_text;
164 }
165 // --------------------------------------------------------------------
166
168 void setSelection(const int i, const int playerID)
169 { m_selection[playerID] = i; updateSelection(); }
170
172 void select(std::string item, const int playerID);
173
181 void setLabel(const unsigned int id, irr::core::stringw new_name);
182
183 void setItemVisible(const unsigned int id, bool visible);
184
185 void setFlip(RibbonFlip direction);
186
188 int findItemNamed(const char* internalName);
189
191 GUIEngine::Widget * findWidgetNamed(const char* interalName);
192
199 void addTextChild(const core::stringw& text, const std::string &id);
200
201
207 void addIconChild(const core::stringw& text, const std::string &id,
208 const int w, const int h, const std::string &icon,
209 const IconButtonWidget::IconPathType iconPathType=
211
216 void clearAllChildren();
217
222 void removeChildNamed(const char* name);
223
224 PtrVector<Widget>& getRibbonChildren() { return m_children; }
225
226 virtual EventPropagation onActivationInput(const int playerID) OVERRIDE;
227 };
228
229}
230
231#endif
An extended version of RibbonWidget, with more capabilities.
Definition: dynamic_ribbon_widget.hpp:82
Class to handle irrLicht events (GUI and input as well)
Definition: event_handler.hpp:66
IconPathType
Definition: icon_button_widget.hpp:64
@ ICON_PATH_TYPE_RELATIVE
relative to the data dir
Definition: icon_button_widget.hpp:67
Definition: ribbon_widget.hpp:63
A static text/icons/tabs bar widget.
Definition: ribbon_widget.hpp:60
virtual EventPropagation rightPressed(const int playerID=0) OVERRIDE
Callbacks.
Definition: ribbon_widget.cpp:611
int getSelection(const int playerID) const
Returns the numerical ID of the selected item within the ribbon.
Definition: ribbon_widget.hpp:152
static const char NO_ITEM_ID[]
Internal identifier of filler items that are added in a ribbon widget to filllines when the number of...
Definition: ribbon_widget.hpp:122
virtual EventPropagation onClick() OVERRIDE
Gets called when the widget is active and got clicked.
Definition: ribbon_widget.cpp:831
virtual EventPropagation downPressed(const int playerID=0) OVERRIDE
called when down key is pressed and focus is on widget.
Definition: ribbon_widget.cpp:623
const std::string & getSelectionIDString(const int playerID)
Returns the string ID (internal name) of the selection.
Definition: ribbon_widget.cpp:840
void setSelection(const int i, const int playerID)
Sets the ID of the selected item within the ribbon.
Definition: ribbon_widget.hpp:168
void setLabel(const unsigned int id, irr::core::stringw new_name)
This method can be used to rename an item.
Definition: ribbon_widget.cpp:943
virtual EventPropagation transmitEvent(Widget *w, const std::string &originator, const int playerID=0) OVERRIDE
All widgets, including their parents (m_event_handler) will be notified on event through this call.
Definition: ribbon_widget.cpp:901
int findItemNamed(const char *internalName)
Returns the ID of the item, or -1 if not found.
Definition: ribbon_widget.cpp:987
GUIEngine::Widget * findWidgetNamed(const char *interalName)
Returns the the widget, or NULL if not found.
Definition: ribbon_widget.cpp:999
Widget * m_mouse_focus
Contains which element within the ribbon is currently focused by player 0 (used by the skin to show m...
Definition: ribbon_widget.hpp:127
virtual EventPropagation focused(const int playerID) OVERRIDE
override in children if you need to know when the widget is focused.
Definition: ribbon_widget.cpp:744
void updateSelection()
Each item within the ribbon holds a flag saying whether it is selected or not.
Definition: ribbon_widget.cpp:856
virtual void add() OVERRIDE
Create and add the irrLicht widget(s) associated with this object.
Definition: ribbon_widget.cpp:75
RibbonType m_ribbon_type
The type of this ribbon (toolbar, combo, tabs, vertical tabs)
Definition: ribbon_widget.hpp:79
RibbonFlip getRibbonFlip() const
Returns the flip direction of thin ribbon.
Definition: ribbon_widget.hpp:145
virtual void unfocused(const int playerID, Widget *new_focus) OVERRIDE
override in children if you need to know when the widget is unfocused.
Definition: ribbon_widget.cpp:782
void addTextChild(const core::stringw &text, const std::string &id)
Dynamically (at runtime) add a text item to this ribbon.
Definition: ribbon_widget.cpp:530
RibbonType getRibbonType() const
Returns the type of this ribbon (see the GUI module overview page for detailed descriptions)
Definition: ribbon_widget.hpp:142
virtual EventPropagation upPressed(const int playerID=0) OVERRIDE
called when up key is pressed and focus is on widget.
Definition: ribbon_widget.cpp:629
RibbonFlip m_ribbon_flip
The flip direction of this ribbon.
Definition: ribbon_widget.hpp:82
irr::core::stringw getSelectionText(const int playerID)
Returns the user-visible text of the selection.
Definition: ribbon_widget.hpp:159
void addIconChild(const core::stringw &text, const std::string &id, const int w, const int h, const std::string &icon, const IconButtonWidget::IconPathType iconPathType=IconButtonWidget::ICON_PATH_TYPE_RELATIVE)
Dynamically (at runtime) add an icon item to this ribbon.
Definition: ribbon_widget.cpp:544
virtual EventPropagation mouseHovered(Widget *child, const int playerID) OVERRIDE
used when you set eventSupervisors - see m_event_handler explainations below called when one of a wid...
Definition: ribbon_widget.cpp:796
void removeChildNamed(const char *name)
clear one child from this ribbon
Definition: ribbon_widget.cpp:577
virtual EventPropagation leftPressed(const int playerID=0) OVERRIDE
called when left key is pressed and focus is on widget.
Definition: ribbon_widget.cpp:617
int getActiveChildrenNumber(const int playerID) const
Returns the number of active items within the ribbon.
Definition: ribbon_widget.hpp:148
void setListener(IRibbonListener *listener)
Sets a listener that will be notified of changes on this ribbon.
Definition: ribbon_widget.hpp:138
void clearAllChildren()
clear all children of this ribbon (likely because new ones will be added soon after)
Definition: ribbon_widget.cpp:567
void select(std::string item, const int playerID)
Select an item in the ribbon by its internal name.
Definition: ribbon_widget.cpp:594
void selectNextActiveWidget(const bool horizontally, const bool reverse, const int playerID, const int old_selection)
Move to the next child widget in the requested direction.
Definition: ribbon_widget.cpp:700
The nearly-abstract base of all widgets (not fully abstract since a bare Widget can be created for th...
Definition: widget.hpp:143
PtrVector< Widget > m_children
If this widget has any children, they go here.
Definition: widget.hpp:265
Definition: ptr_vector.hpp:44
Contains all GUI engine related classes and functions.
Definition: abstract_state_manager.hpp:33
RibbonFlip
Filp directions of ribbons.
Definition: ribbon_widget.hpp:46
RibbonType
Types of ribbons.
Definition: ribbon_widget.hpp:37
@ RIBBON_VERTICAL_TABS
a vertical tab bar
Definition: ribbon_widget.hpp:41
@ RIBBON_TOOLBAR
a row of individual buttons
Definition: ribbon_widget.hpp:39
@ RIBBON_TABS
a tab bar
Definition: ribbon_widget.hpp:40
@ RIBBON_COMBO
select one item out of many, like in a combo box
Definition: ribbon_widget.hpp:38