diff --git a/RetroFE/Source/Control/UserInput.cpp b/RetroFE/Source/Control/UserInput.cpp index a260282..2803b1d 100644 --- a/RetroFE/Source/Control/UserInput.cpp +++ b/RetroFE/Source/Control/UserInput.cpp @@ -50,6 +50,8 @@ bool UserInput::Initialize() retVal = MapKey("pageDown", KeyCodePageDown) && retVal; retVal = MapKey("pageUp", KeyCodePageUp) && retVal; + retVal = MapKey("letterDown", KeyCodeLetterDown) && retVal; + retVal = MapKey("letterUp", KeyCodeLetterUp) && retVal; retVal = MapKey("select", KeyCodeSelect) && retVal; retVal = MapKey("back", KeyCodeBack) && retVal; retVal = MapKey("quit", KeyCodeQuit) && retVal; diff --git a/RetroFE/Source/Control/UserInput.h b/RetroFE/Source/Control/UserInput.h index db013db..0fe7840 100644 --- a/RetroFE/Source/Control/UserInput.h +++ b/RetroFE/Source/Control/UserInput.h @@ -34,6 +34,8 @@ public: KeyCodeBack, KeyCodePageDown, KeyCodePageUp, + KeyCodeLetterDown, + KeyCodeLetterUp, KeyCodeAdminMode, KeyCodeHideItem, KeyCodeQuit diff --git a/RetroFE/Source/Graphics/Component/ScrollingList.cpp b/RetroFE/Source/Graphics/Component/ScrollingList.cpp index 029a29d..e85c7ef 100644 --- a/RetroFE/Source/Graphics/Component/ScrollingList.cpp +++ b/RetroFE/Source/Graphics/Component/ScrollingList.cpp @@ -29,6 +29,7 @@ #include "Text.h" #include "../../Database/Configuration.h" // todo: decouple the GUI from the data #include "../../Collection/Item.h" +#include "../../Utility/Utils.h" #include "../../Utility/Log.h" #include "../../SDL.h" #include "../ViewInfo.h" @@ -377,10 +378,72 @@ void ScrollingList::PageDown() } AllocateSpritePoints(); -//todo: may want to handle this properly -// CurrentScrollState = ScrollStatePageChange; } + +void ScrollingList::LetterUp() +{ + NotifyAllRequested = true; + DeallocateSpritePoints(); + + if(SpriteList && ScrollPoints) + { + + + unsigned int i = 0; + + // Select the previous item in the list in case we are at the top of all the items + // for the currently selected letter. + CircularDecrement(FirstSpriteIndex, SpriteList); + std::string startname = GetSelectedCollectionItemSprite()->GetCollectionItem()->GetLCFullTitle(); + ++i; + + bool done = false; + + // traverse up through the list until we find the first item that starts with a different letter + while(!done && i < SpriteList->size()) + { + CircularDecrement(FirstSpriteIndex, SpriteList); + std::string endname = GetSelectedCollectionItemSprite()->GetCollectionItem()->GetLCFullTitle(); + ++i; + done = (startname[0] != endname[0]); + + if(done) + { + // our searching went too far, rewind to the first item in the list that matches the starting letter + CircularIncrement(FirstSpriteIndex, SpriteList); + } + } + } + + AllocateSpritePoints(); +} + +void ScrollingList::LetterDown() +{ + NotifyAllRequested = true; + DeallocateSpritePoints(); + + if(SpriteList && ScrollPoints) + { + + std::string startname = GetSelectedCollectionItemSprite()->GetCollectionItem()->GetLCFullTitle(); + std::string endname = startname; + + unsigned int i = 0; + + while(startname[0] == endname[0] && i < SpriteList->size()) + { + CircularIncrement(FirstSpriteIndex, SpriteList); + endname = GetSelectedCollectionItemSprite()->GetCollectionItem()->GetLCFullTitle(); + ++i; + } + } + + AllocateSpritePoints(); +} + + void ScrollingList::FreeGraphicsMemory() { Component::FreeGraphicsMemory(); diff --git a/RetroFE/Source/Graphics/Component/ScrollingList.h b/RetroFE/Source/Graphics/Component/ScrollingList.h index 0038599..748b4e9 100644 --- a/RetroFE/Source/Graphics/Component/ScrollingList.h +++ b/RetroFE/Source/Graphics/Component/ScrollingList.h @@ -65,6 +65,8 @@ public: bool IsHorizontalScroll(); void PageUp(); void PageDown(); + void LetterUp(); + void LetterDown(); bool IsIdle(); void SetSelectedIndex(int selectedIndex); ComponentItemBinding *GetSelectedCollectionItemSprite(); diff --git a/RetroFE/Source/Graphics/Page.cpp b/RetroFE/Source/Graphics/Page.cpp index c45cc46..54c0a1f 100644 --- a/RetroFE/Source/Graphics/Page.cpp +++ b/RetroFE/Source/Graphics/Page.cpp @@ -378,6 +378,22 @@ void Page::PageScroll(ScrollDirection direction) } } +void Page::LetterScroll(ScrollDirection direction) +{ + if(ActiveMenu) + { + if(direction == ScrollDirectionForward) + { + ActiveMenu->LetterDown(); + } + if(direction == ScrollDirectionBack) + { + ActiveMenu->LetterUp(); + } + } +} + + bool Page::PushCollection(CollectionInfo *collection) { Collections.push_back(collection); diff --git a/RetroFE/Source/Graphics/Page.h b/RetroFE/Source/Graphics/Page.h index 96d1ec7..729dd0c 100644 --- a/RetroFE/Source/Graphics/Page.h +++ b/RetroFE/Source/Graphics/Page.h @@ -54,6 +54,7 @@ public: void SetSelectSound(Sound *chunk); bool AddComponent(Component *c); void PageScroll(ScrollDirection direction); + void LetterScroll(ScrollDirection direction); void Start(); void StartComponents(); void Stop(); diff --git a/RetroFE/Source/RetroFE.cpp b/RetroFE/Source/RetroFE.cpp index 661c36a..c268c0b 100644 --- a/RetroFE/Source/RetroFE.cpp +++ b/RetroFE/Source/RetroFE.cpp @@ -430,6 +430,15 @@ RetroFE::RETROFE_STATE RetroFE::ProcessUserInput(Page *page) { page->PageScroll(Page::ScrollDirectionForward); } + if (Input.GetKeyState(UserInput::KeyCodeLetterUp)) + { + page->LetterScroll(Page::ScrollDirectionBack); + } + if (Input.GetKeyState(UserInput::KeyCodeLetterDown)) + { + page->LetterScroll(Page::ScrollDirectionForward); + } + if (Input.GetKeyState(UserInput::KeyCodeAdminMode)) { //todo: add admin mode support