From 0dabaca7dff12aabee6e2560f12a4a7b3e345141 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sat, 23 Jan 2016 21:23:02 +0100 Subject: [PATCH] - added some range checks to PgUp(PgDown code for option menus. --- src/menu/optionmenu.cpp | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/menu/optionmenu.cpp b/src/menu/optionmenu.cpp index 57e69cfaba..a1d7660bba 100644 --- a/src/menu/optionmenu.cpp +++ b/src/menu/optionmenu.cpp @@ -274,7 +274,14 @@ bool DOptionMenu::MenuEvent (int mkey, bool fromcontroller) mDesc->mSelectedItem = mDesc->mScrollTop + mDesc->mScrollPos + 1; while (!mDesc->mItems[mDesc->mSelectedItem]->Selectable()) { - ++mDesc->mSelectedItem; + if (++mDesc->mSelectedItem >= (int)mDesc->mItems.Size()) + { + mDesc->mSelectedItem = 0; + } + } + if (mDesc->mScrollPos > mDesc->mSelectedItem) + { + mDesc->mScrollPos = mDesc->mSelectedItem; } } } @@ -294,7 +301,14 @@ bool DOptionMenu::MenuEvent (int mkey, bool fromcontroller) mDesc->mSelectedItem = mDesc->mScrollTop + mDesc->mScrollPos; while (!mDesc->mItems[mDesc->mSelectedItem]->Selectable()) { - ++mDesc->mSelectedItem; + if (++mDesc->mSelectedItem >= (int)mDesc->mItems.Size()) + { + mDesc->mSelectedItem = 0; + } + } + if (mDesc->mScrollPos > mDesc->mSelectedItem) + { + mDesc->mScrollPos = mDesc->mSelectedItem; } } }