Work around irrlicht list limitations with dark magic
git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@5345 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
@@ -22,6 +22,7 @@
|
||||
#include "guiengine/modaldialog.hpp"
|
||||
#include "guiengine/screen.hpp"
|
||||
#include "guiengine/widget.hpp"
|
||||
#include "guiengine/widgets/list_widget.hpp"
|
||||
#include "guiengine/widgets/ribbon_widget.hpp"
|
||||
#include "input/input_manager.hpp"
|
||||
#include "states_screens/state_manager.hpp"
|
||||
@@ -389,19 +390,18 @@ void EventHandler::navigateUp(const int playerID, Input::InputType type, const b
|
||||
// components
|
||||
if (w != NULL && w->m_type == WTYPE_LIST)
|
||||
{
|
||||
IGUIListBox* list = (IGUIListBox*)(w->m_element);
|
||||
assert(list != NULL);
|
||||
ListWidget* list = (ListWidget*)w;
|
||||
|
||||
const bool stay_within_list = list->getSelected() > 0;
|
||||
const bool stay_within_list = list->getSelectionID() > 0;
|
||||
|
||||
if (stay_within_list)
|
||||
{
|
||||
list->setSelected(list->getSelected()-1);
|
||||
list->setSelectionID(list->getSelectionID()-1);
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
list->setSelected(-1);
|
||||
list->setSelectionID(-1);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -496,19 +496,18 @@ void EventHandler::navigateDown(const int playerID, Input::InputType type, const
|
||||
// components
|
||||
if (w != NULL && w->m_type == WTYPE_LIST)
|
||||
{
|
||||
IGUIListBox* list = w->getIrrlichtElement<IGUIListBox>();
|
||||
assert(list != NULL);
|
||||
ListWidget* list = (ListWidget*)w;
|
||||
|
||||
const bool stay_within_list = list->getSelected() < (int)list->getItemCount()-1;
|
||||
const bool stay_within_list = list->getSelectionID() < list->getItemCount()-1;
|
||||
|
||||
if (stay_within_list)
|
||||
{
|
||||
list->setSelected(list->getSelected()+1);
|
||||
list->setSelectionID(list->getSelectionID()+1);
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
list->setSelected(-1);
|
||||
list->setSelectionID(-1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -39,6 +39,7 @@ void ListWidget::add()
|
||||
rect<s32> widget_size = rect<s32>(x, y, x + w, y + h);
|
||||
|
||||
IGUIListBox* list = GUIEngine::getGUIEnv()->addListBox (widget_size, m_parent, getNewID());
|
||||
list->setAutoScrollEnabled(false);
|
||||
|
||||
if (m_use_icons)
|
||||
{
|
||||
@@ -115,3 +116,37 @@ void ListWidget::unfocused(const int playerID)
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
int ListWidget::getSelectionID() const
|
||||
{
|
||||
return getIrrlichtElement<IGUIListBox>()->getSelected();
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
void ListWidget::setSelectionID(const int index)
|
||||
{
|
||||
IGUIListBox* irritem = getIrrlichtElement<IGUIListBox>();
|
||||
|
||||
// auto-scroll to item when selecting something, don't auto-scroll when selecting nothing
|
||||
if (index != -1)
|
||||
{
|
||||
irritem->setAutoScrollEnabled(true);
|
||||
}
|
||||
|
||||
irritem->setSelected(index);
|
||||
|
||||
if (index != -1)
|
||||
{
|
||||
irritem->setAutoScrollEnabled(false);
|
||||
}
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
int ListWidget::getItemCount() const
|
||||
{
|
||||
return getIrrlichtElement<IGUIListBox>()->getItemCount();
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
@@ -47,6 +47,18 @@ namespace GUIEngine
|
||||
int getSelection() const;
|
||||
std::string getSelectionName() const;
|
||||
void clear();
|
||||
|
||||
/** \return the number of items in the list */
|
||||
int getItemCount() const;
|
||||
|
||||
/** \return the index of the selected element within the list, or -1 if none */
|
||||
int getSelectionID() const;
|
||||
|
||||
/**
|
||||
* \brief change the selected item
|
||||
* \param index the index of the element to select within the list, or -1 to select nothing
|
||||
*/
|
||||
void setSelectionID(const int index);
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user