From 2b152135daad58ccc4711fb21d5421db993e2976 Mon Sep 17 00:00:00 2001 From: auria Date: Wed, 30 Dec 2009 17:43:06 +0000 Subject: [PATCH] Fixed rare focus issue in modal dialogs, and generally improved code git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@4365 178a84e3-b1eb-0310-8ba1-8eac791a3b58 --- src/guiengine/modaldialog.cpp | 14 ++-- src/guiengine/screen.cpp | 24 +++++-- .../dialogs/track_info_dialog.cpp | 72 +++++++++---------- 3 files changed, 64 insertions(+), 46 deletions(-) diff --git a/src/guiengine/modaldialog.cpp b/src/guiengine/modaldialog.cpp index b95bb3f82..1032b3dca 100644 --- a/src/guiengine/modaldialog.cpp +++ b/src/guiengine/modaldialog.cpp @@ -117,12 +117,15 @@ void ModalDialog::onEnterPressedInternal() Widget* ModalDialog::getLastWidget() { + // FIXME: don't duplicate this code from 'Screen.cpp' const int childrenCount = m_children.size(); for (int i=childrenCount-1; i>=0; i--) { - if (m_children[i].getIrrlichtElement() == NULL || m_children[i].getIrrlichtElement()->getTabOrder() == -1 || - m_children[i].getIrrlichtElement()->getTabOrder() >= 1000 /* non-tabbing items are given such IDs */) + if (m_children[i].getIrrlichtElement() == NULL || + m_children[i].getIrrlichtElement()->getTabOrder() == -1 || + m_children[i].getIrrlichtElement()->getTabOrder() >= 1000 /* non-tabbing items are given such IDs */ || + !m_children[i].m_focusable) { continue; } @@ -133,12 +136,15 @@ Widget* ModalDialog::getLastWidget() } Widget* ModalDialog::getFirstWidget() { + // FIXME: don't duplicate this code from 'Screen.cpp' const int childrenCount = m_children.size(); for (int i=0; igetTabOrder() == -1 || - m_children[i].getIrrlichtElement()->getTabOrder() >= 1000 /* non-tabbing items are given such IDs */) + if (m_children[i].getIrrlichtElement() == NULL || + m_children[i].getIrrlichtElement()->getTabOrder() == -1 || + m_children[i].getIrrlichtElement()->getTabOrder() >= 1000 /* non-tabbing items are given such IDs */ || + !m_children[i].m_focusable) { continue; } diff --git a/src/guiengine/screen.cpp b/src/guiengine/screen.cpp index 9f0cd9f0b..917ab5618 100644 --- a/src/guiengine/screen.cpp +++ b/src/guiengine/screen.cpp @@ -406,10 +406,16 @@ Widget* Screen::getFirstWidget(ptr_vector* within_vector) if (w != NULL) return w; } - if (within_vector->get(i)->m_element == NULL || within_vector->get(i)->m_element->getTabOrder() == -1 || - within_vector->get(i)->m_element->getTabOrder() >= 1000 /* non-tabbing items are given such IDs */) continue; + Widget* item = within_vector->get(i); + if (item->m_element == NULL || + item->m_element->getTabOrder() == -1 || + item->m_element->getTabOrder() >= 1000 /* non-tabbing items are given such IDs */ || + !item->m_focusable) + { + continue; + } - return within_vector->get(i); + return item; } return NULL; } @@ -431,10 +437,16 @@ Widget* Screen::getLastWidget(ptr_vector* within_vector) if (w != NULL) return w; } - if (within_vector->get(i)->m_element == NULL || within_vector->get(i)->m_element->getTabOrder() == -1 || - within_vector->get(i)->m_element->getTabOrder() >= 1000 /* non-tabbing items are given such IDs */) continue; + Widget* item = within_vector->get(i); + if (item->m_element == NULL || + item->m_element->getTabOrder() == -1 || + item->m_element->getTabOrder() >= 1000 /* non-tabbing items are given such IDs */ || + !item->m_focusable) + { + continue; + } - return within_vector->get(i); + return item; } return NULL; } diff --git a/src/states_screens/dialogs/track_info_dialog.cpp b/src/states_screens/dialogs/track_info_dialog.cpp index ebf143333..1f11ca4dc 100644 --- a/src/states_screens/dialogs/track_info_dialog.cpp +++ b/src/states_screens/dialogs/track_info_dialog.cpp @@ -50,42 +50,6 @@ TrackInfoDialog::TrackInfoDialog(const std::string& trackIdent, const irr::core: m_track_ident = trackIdent; - // ---- Lap count m_spinner - m_spinner = new SpinnerWidget(); - m_spinner->x = m_area.getWidth()/2 - 200; - m_spinner->y = y2; - m_spinner->w = 400; - m_spinner->h = y3 - y2 - 15; - m_spinner->setParent(m_irrlicht_window); - - m_spinner->m_properties[PROP_MIN_VALUE] = "1"; - m_spinner->m_properties[PROP_MAX_VALUE] = "99"; - - //I18N: In the track setup screen (number of laps choice, where %i is the number) - m_spinner->m_text = _("%i laps"); - - m_children.push_back(m_spinner); - m_spinner->add(); - m_spinner->setValue(3); - m_spinner->getIrrlichtElement()->setTabStop(true); - m_spinner->getIrrlichtElement()->setTabGroup(false); - - // ---- Start button - ButtonWidget* okBtn = new ButtonWidget(); - okBtn->m_properties[PROP_ID] = "start"; - okBtn->m_text = _("Start Race"); - okBtn->x = m_area.getWidth()/2 - 200; - okBtn->y = y3; - okBtn->w = 400; - okBtn->h = m_area.getHeight() - y3 - 15; - okBtn->setParent(m_irrlicht_window); - m_children.push_back(okBtn); - okBtn->add(); - okBtn->getIrrlichtElement()->setTabStop(true); - okBtn->getIrrlichtElement()->setTabGroup(false); - - okBtn->setFocusForPlayer( GUI_PLAYER_ID ); - // ---- Track title core::rect< s32 > area_top(0, 0, m_area.getWidth(), y1); IGUIStaticText* a = GUIEngine::getGUIEnv()->addStaticText( trackName.c_str(), @@ -206,6 +170,42 @@ TrackInfoDialog::TrackInfoDialog(const std::string& trackIdent, const irr::core: a->setTextAlignment(EGUIA_CENTER, EGUIA_CENTER); b->setTextAlignment(EGUIA_CENTER, EGUIA_CENTER); + // ---- Lap count m_spinner + m_spinner = new SpinnerWidget(); + m_spinner->x = m_area.getWidth()/2 - 200; + m_spinner->y = y2; + m_spinner->w = 400; + m_spinner->h = y3 - y2 - 15; + m_spinner->setParent(m_irrlicht_window); + + m_spinner->m_properties[PROP_MIN_VALUE] = "1"; + m_spinner->m_properties[PROP_MAX_VALUE] = "99"; + + //I18N: In the track setup screen (number of laps choice, where %i is the number) + m_spinner->m_text = _("%i laps"); + + m_children.push_back(m_spinner); + m_spinner->add(); + m_spinner->setValue(3); + m_spinner->getIrrlichtElement()->setTabStop(true); + m_spinner->getIrrlichtElement()->setTabGroup(false); + + // ---- Start button + ButtonWidget* okBtn = new ButtonWidget(); + okBtn->m_properties[PROP_ID] = "start"; + okBtn->m_text = _("Start Race"); + okBtn->x = m_area.getWidth()/2 - 200; + okBtn->y = y3; + okBtn->w = 400; + okBtn->h = m_area.getHeight() - y3 - 15; + okBtn->setParent(m_irrlicht_window); + m_children.push_back(okBtn); + okBtn->add(); + okBtn->getIrrlichtElement()->setTabStop(true); + okBtn->getIrrlichtElement()->setTabGroup(false); + + okBtn->setFocusForPlayer( GUI_PLAYER_ID ); + } TrackInfoDialog::~TrackInfoDialog()