SuperTuxKart
|
The nearly-abstract base of all widgets (not fully abstract since a bare Widget can be created for the sole goal of containing children widgets in a group) More...
#include <widget.hpp>
Public Member Functions | |
Widget (WidgetType type, bool reserve_id=false) | |
virtual void | setEventCallbackActive (Input::InputType type, bool active) |
Allow (or not) an event callback for this widget based on input type. | |
virtual bool | isEventCallbackActive (Input::InputType type) const |
Return if there should be an event callback for this widget based on input type. | |
void | setParent (irr::gui::IGUIElement *parent) |
Set the irrlicht widget to be used as parent of this widget next time Widget::add() is invoked on this widget. | |
virtual void | setVisible (bool visible) |
Sets the widget (and its children, if any) visible or not. | |
virtual void | setCollapsed (bool collapsed, Screen *calling_screen=NULL) |
Sets the widget (and its children, if any) collapsed or not. | |
virtual void | setCollapsed (bool collapsed, int uncollapsed_height, Screen *calling_screen=NULL) |
Sets the widget (and its children, if any) collapsed or not. | |
bool | isVisible () const |
Returns if the element is visible. | |
bool | isCollapsed () const |
Returns whether the element is collapsed (through setCollapsed). | |
bool | isActivated () const |
virtual EventPropagation | onActivationInput (const int playerID) |
virtual void | move (const int x, const int y, const int w, const int h) |
Call to resize/move the widget. | |
bool | isSelected (const int playerID) const |
Get whether this widget is selected (only makes sense in some cases where a widget is part of a bigger widget, e.g. | |
void | setSelected (const int playerID, bool state) |
bool | isBottomBar () const |
bool | isTopBar () const |
bool | ok () const |
virtual EventPropagation | onClick () |
Gets called when the widget is active and got clicked. | |
virtual irr::core::dimension2di | getDimension () const |
Enabling or disabling widgets | |
virtual void | setActive (bool active=true) |
Sets an widget to be either activated or deactivated (i.e. | |
Accessing the underlying irrlicht element | |
template<typename T > | |
T * | getIrrlichtElement () |
Get the underlying irrLicht GUI element, casted to the right type. | |
template<typename T > | |
const T * | getIrrlichtElement () const |
Get the underlying irrLicht GUI element, casted to the right type; const version. | |
irr::gui::IGUIElement * | getIrrlichtElement () |
Get the underlying irrLicht GUI element. | |
void | moveIrrlichtElement () |
bool | isSameIrrlichtWidgetAs (const Widget *ref) const |
Get and set properties | |
Note that many properties are read only by the Widget::add method; so, while it will generally work to set the properties before add() is called, modifying the widget after it was added will require other widget-specific calls. | |
virtual void | setText (const irr::core::stringw &s) |
Sets the text of a widget from a wchar_t. | |
const irr::core::stringw & | getText () const |
Returns the text of a widget. | |
WidgetType | getType () const |
int | getID () const |
Get the irrlicht widget ID attributed to this widget. | |
bool | isFocusable () const |
Get whether this object is allowed to receive focus. | |
void | setFocusable (bool f) |
Focus management | |
void | setFocusForPlayer (const int playerID) |
Focus the widget for the given player. | |
bool | isFocusedForPlayer (const int playerID) |
Find whether this widget is focused by a given player. | |
void | unsetFocusForPlayer (const int playerID) |
Internal method, do not call it. | |
Handling children | |
If this widget is a container and has children. | |
const PtrVector< Widget > & | getChildren () const |
PtrVector< Widget > & | getChildren () |
bool | deleteChild (const char *id) |
removes and deletes the child with the given PROP_ID | |
Callbacks for subclasses | |
Classes that subclass Widget to provide actual implementations may override/implement these methods to change behaviour or be notified of some events. | |
virtual void | update (float delta) |
Override in children to possibly receive updates (you may need to register to them first) | |
virtual EventPropagation | transmitEvent (Widget *w, const std::string &originator, const int playerID) |
All widgets, including their parents (m_event_handler) will be notified on event through this call. | |
virtual void | add () |
Create and add the irrLicht widget(s) associated with this object. | |
virtual void | elementRemoved () |
Called when irrLicht widgets cleared. | |
bool | searchInsideMe () const |
virtual int | getWidthNeededAroundLabel () const |
When inferring widget size from its label length, this method will be called to if/how much space must be added to the raw label's size for the widget to be large enough. | |
virtual int | getHeightNeededAroundLabel () const |
When inferring widget size from its label length, this method will be called to if/how much space must be added to the raw label's size for the widget to be large enough. | |
Badge support | |
"Badges" are icons that can appear on top of some widgets. | |
void | setBadge (BadgeType badge_bit) |
adds a particular badge to this widget. | |
void | unsetBadge (BadgeType badge_bit) |
removes a particular bade from this widget, if it had it. | |
void | resetAllBadges () |
sets this widget to have no badge | |
int | getBadges () const |
Get which badges are currently on this widget. | |
Tooltip support | |
bool | hasTooltip () const |
irr::core::stringw | getTooltipText () const |
Only call if hasTooltip() returned true. | |
void | setTooltip (irr::core::stringw s) |
Static Public Member Functions | |
ID Counter Functions | |
Functions used to generate IDs for new widgets. The domain of each ID encodes whether the widget can receive focus or not (this was implemented this way because navigation in irrlicht happens between sequential IDs; so to prevent navigation to a widget, one needs to give an ID that is not sequential with focusable widgets in order not to break keyboard navigation). | |
static void | resetIDCounters () |
When switching to a new screen, this function will be called to reset ID counters (so we start again from ID 0, and don't grow to big numbers) | |
static int | getNewID () |
Provides a new unique ID on each call, for widgets that can be focused. | |
static int | getNewNoFocusID () |
Provides a new unique ID on each call, for widgets that can not be focused. | |
static bool | isFocusableId (const int id) |
get whether the given ID represents an ID of a widget that can be focused | |
Public Attributes | |
Widget * | m_event_handler |
This is set to NULL by default; set to something else in a widget to mean that events happening on this widget should also be passed to m_event_handler->transmitEvent, which is usually the parent analysing events from its children. | |
bool | m_supports_multiplayer |
Whether this widget supports multiplayer interaction (i.e. | |
int | m_tab_down_root |
Instead of searching for widget IDs smaller/greater than that of this object, navigation through widgets will start from these IDs (if they are set). | |
int | m_tab_up_root |
Instead of searching for widget IDs smaller/greater than that of this object, navigation through widgets will start from these IDs (if they are set). | |
int | m_x |
Coordinates of the widget once added (the difference between those x/h and PROP_WIDTH/PROP_HEIGHT is that the props are read in raw form from the XML file; PROP_WIDTH can then be e.g. | |
int | m_y |
int | m_w |
int | m_h |
bool | m_show_bounding_box |
Whether to show a bounding box around this widget (used for sections) | |
bool | m_is_bounding_box_round |
Only used if m_show_bounding_box is true. | |
int | m_reserved_id |
Used in two cases : 1) For 'placeholder' divisions; at the time the layout is created, there is nothing to place there yet, but we know there eventually will. | |
std::map< Property, std::string > | m_properties |
A map that holds values for all specified widget properties (in the XML file) | |
Public Attributes inherited from GUIEngine::SkinWidgetContainer | |
int | m_skin_x |
int | m_skin_y |
int | m_skin_w |
int | m_skin_h |
bool | m_skin_dest_areas_inited |
bool | m_skin_dest_areas_yflip_inited |
int | m_skin_dest_x |
int | m_skin_dest_y |
int | m_skin_dest_x2 |
int | m_skin_dest_y2 |
core::rect< s32 > | m_skin_dest_area_left |
core::rect< s32 > | m_skin_dest_area_center |
core::rect< s32 > | m_skin_dest_area_right |
core::rect< s32 > | m_skin_dest_area_top |
core::rect< s32 > | m_skin_dest_area_bottom |
core::rect< s32 > | m_skin_dest_area_top_left |
core::rect< s32 > | m_skin_dest_area_top_right |
core::rect< s32 > | m_skin_dest_area_bottom_left |
core::rect< s32 > | m_skin_dest_area_bottom_right |
core::rect< s32 > | m_skin_dest_area_left_yflip |
core::rect< s32 > | m_skin_dest_area_center_yflip |
core::rect< s32 > | m_skin_dest_area_right_yflip |
core::rect< s32 > | m_skin_dest_area_top_yflip |
core::rect< s32 > | m_skin_dest_area_bottom_yflip |
core::rect< s32 > | m_skin_dest_area_top_left_yflip |
core::rect< s32 > | m_skin_dest_area_top_right_yflip |
core::rect< s32 > | m_skin_dest_area_bottom_left_yflip |
core::rect< s32 > | m_skin_dest_area_bottom_right_yflip |
short | m_skin_r |
short | m_skin_g |
short | m_skin_b |
Protected Member Functions | |
virtual EventPropagation | rightPressed (const int playerID) |
called when right key is pressed and focus is on widget. | |
virtual EventPropagation | leftPressed (const int playerID) |
called when left key is pressed and focus is on widget. | |
virtual EventPropagation | upPressed (const int playerID) |
called when up key is pressed and focus is on widget. | |
virtual EventPropagation | downPressed (const int playerID) |
called when down key is pressed and focus is on widget. | |
virtual EventPropagation | mouseHovered (Widget *child, const int playerID) |
used when you set eventSupervisors - see m_event_handler explainations below called when one of a widget's children is hovered. | |
virtual EventPropagation | focused (const int playerID) |
override in children if you need to know when the widget is focused. | |
virtual void | unfocused (const int playerID, Widget *new_focus) |
override in children if you need to know when the widget is unfocused. | |
Protected Attributes | |
unsigned int | m_magic_number |
std::bitset< Input::IT_LAST+1 > | m_active_event_callback |
int | m_absolute_x |
Used during loading, by the layout engine. | |
int | m_absolute_y |
int | m_absolute_w |
int | m_absolute_h |
int | m_absolute_reverse_x |
int | m_absolute_reverse_y |
float | m_relative_x |
float | m_relative_y |
float | m_relative_w |
float | m_relative_h |
irr::core::stringw | m_text |
PROP_TEXT is a special case : since it can be translated it can't go in the map above, which uses narrow strings. | |
bool | m_title_font |
When true, this widget shall use a bigger and more colourful font. | |
bool | m_selected [MAX_PLAYER_COUNT] |
Can be used in children to indicate whether a widget is selected or not. | |
bool | m_check_inside_me |
Whether to descend in the children of this widget when searching a widget from its ID or name. | |
irr::gui::IGUIElement * | m_parent |
An irrlicht parent (most often used to put widgets in dialogs) | |
irr::gui::IGUIElement * | m_element |
IrrLicht widget created to represent this object. | |
int | m_id |
numerical ID used by irrLicht to identify this widget (not the same as the string identificator specified in the XML file) | |
bool | m_player_focus [MAX_PLAYER_COUNT] |
Usually, only one widget at a time can be focused. | |
bool | m_reserve_id |
Whether to reserve an ID in 'm_reserved_id' when widget is added. | |
WidgetType | m_type |
Type of this widget. | |
PtrVector< Widget > | m_children |
If this widget has any children, they go here. | |
int | m_badges |
A bitmask of which badges to show, if any; choices are *_BADGE, defined above. | |
bool | m_deactivated |
A simple flag that can be raised to deactivate this widget. | |
bool | m_is_visible |
A flag to indicate whether this widget should be visible or not. | |
bool | m_focusable |
Set to false if widget is something that should not receive focus. | |
bool | m_bottom_bar |
bool | m_top_bar |
int | m_badge_x_shift |
If a badge wouldn't look too pretty on the very side of the widget. | |
bool | m_has_tooltip |
irr::core::stringw | m_tooltip_text |
int | m_uncollapsed_height |
height of the widget before it was collapsed (only set if widget got collapsed) | |
bool | m_is_collapsed |
A flag to indicate whether this widget got collapsed. | |
The nearly-abstract base of all widgets (not fully abstract since a bare Widget can be created for the sole goal of containing children widgets in a group)
Provides basic common functionnality, as well as providing a few callbacks for children to override if they need to do something special on event.
Each widget may have an irrlicht parent (most often used to put widgets in dialogs) and also optionally one or many children.
Each widget also has a set of properties stored in a map (see enum above)
|
virtual |
Create and add the irrLicht widget(s) associated with this object.
Call after Widget was read from XML file and laid out.
Reimplemented in GUIEngine::BubbleWidget, GUIEngine::ButtonWidget, GUIEngine::CheckBoxWidget, GUIEngine::DynamicRibbonWidget, GUIEngine::KartStatsWidget, GUIEngine::LabelWidget, GUIEngine::ListWidget, GUIEngine::ModelViewWidget, GUIEngine::PlayerKartWidget, GUIEngine::ProgressBarWidget, GUIEngine::RatingBarWidget, GUIEngine::SkillLevelWidget, GUIEngine::SpinnerWidget, GUIEngine::TextBoxWidget, FocusDispatcher, GUIEngine::IconButtonWidget, and GUIEngine::RibbonWidget.
bool Widget::deleteChild | ( | const char * | id | ) |
removes and deletes the child with the given PROP_ID
id | PROP_ID property of the child to remove |
|
inlineprotectedvirtual |
called when down key is pressed and focus is on widget.
Returns 'EVENT_LET' if user's event handler should be notified of a change. Override in children to be notified of up/down events and/or make the event propagate to the user's event handler.
Reimplemented in GUIEngine::ListWidget, and GUIEngine::RibbonWidget.
|
virtual |
Called when irrLicht widgets cleared.
Forget all references to them, they're no more valid.
Reimplemented in GUIEngine::DynamicRibbonWidget, GUIEngine::ListWidget, GUIEngine::ModelViewWidget, GUIEngine::TextBoxWidget, and GUIEngine::IconButtonWidget.
|
inlineprotectedvirtual |
override in children if you need to know when the widget is focused.
Reimplemented in GUIEngine::BubbleWidget, GUIEngine::DynamicRibbonWidget, GUIEngine::TextBoxWidget, FocusDispatcher, GUIEngine::IconButtonWidget, and GUIEngine::RibbonWidget.
|
inline |
Get which badges are currently on this widget.
|
inlinevirtual |
When inferring widget size from its label length, this method will be called to if/how much space must be added to the raw label's size for the widget to be large enough.
Reimplemented in GUIEngine::BubbleWidget, GUIEngine::ButtonWidget, GUIEngine::CheckBoxWidget, GUIEngine::KartStatsWidget, GUIEngine::ProgressBarWidget, GUIEngine::SkillLevelWidget, GUIEngine::SpinnerWidget, and GUIEngine::TextBoxWidget.
|
inline |
Get the irrlicht widget ID attributed to this widget.
|
inline |
|
inlinevirtual |
When inferring widget size from its label length, this method will be called to if/how much space must be added to the raw label's size for the widget to be large enough.
Reimplemented in GUIEngine::ButtonWidget, GUIEngine::KartStatsWidget, GUIEngine::ProgressBarWidget, GUIEngine::SkillLevelWidget, GUIEngine::SpinnerWidget, and GUIEngine::TextBoxWidget.
|
static |
get whether the given ID represents an ID of a widget that can be focused
bool Widget::isFocusedForPlayer | ( | const int | playerID | ) |
Find whether this widget is focused by a given player.
playerID | ID of the player you want to set/unset focus for, starting from 0 |
playerID | ID of the player you want to set/unset focus for, starting from 0 |
|
inline |
Get whether this widget is selected (only makes sense in some cases where a widget is part of a bigger widget, e.g.
in ribbons, and a selected item is kept)
|
inlineprotectedvirtual |
called when left key is pressed and focus is on widget.
Returns 'EVENT_LET' if user's event handler should be notified of a change. Override in children to be notified of left/right events and/or make the event propagate to the user's event handler.
Reimplemented in GUIEngine::DynamicRibbonWidget, GUIEngine::ListWidget, GUIEngine::SpinnerWidget, GUIEngine::TextBoxWidget, and GUIEngine::RibbonWidget.
|
inlineprotectedvirtual |
used when you set eventSupervisors - see m_event_handler explainations below called when one of a widget's children is hovered.
Reimplemented in GUIEngine::DynamicRibbonWidget, and GUIEngine::RibbonWidget.
|
virtual |
Call to resize/move the widget.
Not all widgets can resize gracefully.
Reimplemented in GUIEngine::KartStatsWidget, GUIEngine::PlayerKartWidget, GUIEngine::SkillLevelWidget, and GUIEngine::SpinnerWidget.
|
inlinevirtual |
Gets called when the widget is active and got clicked.
(Only works for button widgets for now.)
Reimplemented in GUIEngine::RatingBarWidget, and GUIEngine::RibbonWidget.
|
inline |
sets this widget to have no badge
|
inlineprotectedvirtual |
called when right key is pressed and focus is on widget.
Returns 'EVENT_LET' if user's event handler should be notified of a change. Override in children to be notified of left/right events and/or make the event propagate to the user's event handler.
Reimplemented in GUIEngine::DynamicRibbonWidget, GUIEngine::ListWidget, GUIEngine::SpinnerWidget, GUIEngine::TextBoxWidget, and GUIEngine::RibbonWidget.
|
virtual |
Sets an widget to be either activated or deactivated (i.e.
greyed out)
active | Active (true) or deactive (false). Defaults to true. |
Reimplemented in GUIEngine::ListWidget, GUIEngine::SpinnerWidget, and GUIEngine::TextBoxWidget.
|
inline |
adds a particular badge to this widget.
The STK widget toolkit has support for "badges". Badges are icon overlays displayed on the corner of a widget; they are useful to convey information visually.
|
virtual |
Sets the widget (and its children, if any) collapsed or not.
!!! Note: this has to be called inside beforeAddingWidget() !!! Pass in the screen to get (the necessary) calculate Layout automatically called. This will also set the widget invisible depending of collapsed state. Note that setting a widget invisible implicitely calls setDeactivated(), and setting it visible implicitely calls setActive(true). If you mix visiblity and (de)activated calls, undefined behavior may ensue (like invisible but clickable buttons).
|
virtual |
Sets the widget (and its children, if any) collapsed or not.
!!! Note: this has to be called inside beforeAddingWidget() !!! Pass in the screen to get (the necessary) calculate Layout automatically called. This will also set the widget invisible depending of collapsed state. Note that setting a widget invisible implicitely calls setDeactivated(), and setting it visible implicitely calls setActive(true). If you mix visiblity and (de)activated calls, undefined behavior may ensue (like invisible but clickable buttons).
void Widget::setFocusForPlayer | ( | const int | playerID | ) |
Focus the widget for the given player.
playerID | ID of the player you want to set/unset focus for, starting from 0 |
playerID | ID of the player you want to set/unset focus for, starting from 0 Since the code tracks focus from main player, this will most likely be used only for additionnal players |
|
virtual |
Sets the text of a widget from a wchar_t.
Handy for many constant strings used in stk.
Reimplemented in GUIEngine::BubbleWidget, GUIEngine::LabelWidget, and GUIEngine::DynamicRibbonWidget.
|
virtual |
Sets the widget (and its children, if any) visible or not.
Note that setting a widget invisible implicitely calls setDeactivated(), and setting it visible implicitely calls setActive(true). If you mix visiblity and (de)activated calls, undefined behavior may ensue (like invisible but clickable buttons).
Reimplemented in GUIEngine::IconButtonWidget.
|
inlinevirtual |
All widgets, including their parents (m_event_handler) will be notified on event through this call.
Must return whether main (GUI engine user) event callback should be notified or not. Note that in the case of a hierarchy of widgets (with m_event_handler), only the topmost widget of the chain decides whether the main handler is notified; return value is not read for others.
Reimplemented in GUIEngine::PlayerKartWidget, GUIEngine::CheckBoxWidget, GUIEngine::DynamicRibbonWidget, GUIEngine::ListWidget, GUIEngine::SpinnerWidget, and GUIEngine::RibbonWidget.
|
inlineprotectedvirtual |
override in children if you need to know when the widget is unfocused.
Reimplemented in GUIEngine::ListWidget, GUIEngine::TextBoxWidget, GUIEngine::IconButtonWidget, and GUIEngine::RibbonWidget.
|
inline |
removes a particular bade from this widget, if it had it.
void Widget::unsetFocusForPlayer | ( | const int | playerID | ) |
Internal method, do not call it.
Call the functions in GUIEngine instead to unset focus.
|
inlinevirtual |
Override in children to possibly receive updates (you may need to register to them first)
Reimplemented in GUIEngine::DynamicRibbonWidget, GUIEngine::ModelViewWidget, GUIEngine::ProgressBarWidget, and GUIEngine::LabelWidget.
|
inlineprotectedvirtual |
called when up key is pressed and focus is on widget.
Returns 'EVENT_LET' if user's event handler should be notified of a change. Override in children to be notified of up/down events and/or make the event propagate to the user's event handler.
Reimplemented in GUIEngine::ListWidget, and GUIEngine::RibbonWidget.
|
protected |
Used during loading, by the layout engine.
After layout is done this is not read anymore.
|
protected |
Whether to descend in the children of this widget when searching a widget from its ID or name.
(children classes can override this value as they please)
If this widget has any children, they go here.
Children can be either specified in the XML file (e.g. Ribbon or Div children), or can also be created automatically for logical widgets built with more than one irrlicht widgets (e.g. Spinner)
Widget* GUIEngine::Widget::m_event_handler |
This is set to NULL by default; set to something else in a widget to mean that events happening on this widget should also be passed to m_event_handler->transmitEvent, which is usually the parent analysing events from its children.
This is especially useful with logical widgets built with more than one irrlicht widgets (e.g. Spinner, Ribbon)
|
protected |
Usually, only one widget at a time can be focused.
There is however a special case where all players can move through the screen. This variable will then be used as a bitmask to contain which players beyong player 1 have this widget focused.
std::map<Property, std::string> GUIEngine::Widget::m_properties |
A map that holds values for all specified widget properties (in the XML file)
int GUIEngine::Widget::m_reserved_id |
Used in two cases : 1) For 'placeholder' divisions; at the time the layout is created, there is nothing to place there yet, but we know there eventually will.
So in this case pass 'true' to the Widget constructor and it will reserve a widget ID and store it here. 2) Theorically, in 'add()', derived widgets should checked if this value is set, and use it instead of creating a new ID if it is. In practice, it's not widely implemented (FIXME)
|
protected |
Can be used in children to indicate whether a widget is selected or not.
bool GUIEngine::Widget::m_supports_multiplayer |
Whether this widget supports multiplayer interaction (i.e.
whether this widget can be used by players other than by the game master)
int GUIEngine::Widget::m_x |
Coordinates of the widget once added (the difference between those x/h and PROP_WIDTH/PROP_HEIGHT is that the props are read in raw form from the XML file; PROP_WIDTH can then be e.g.
"10%" and w, once the widget is added, will be e.g. 80.)