diff --git a/changelog.txt b/changelog.txt index 19f07afff..669ad0f45 100644 --- a/changelog.txt +++ b/changelog.txt @@ -1,3 +1,6 @@ +October 5 +-GuiFastSelect is working, but ugly. + September 30 -Began implementing GuiFastSelect, currently invoked by holding F2. Unfortunately, it doesn't do anything yet. -Added . diff --git a/src/components/GuiFastSelect.cpp b/src/components/GuiFastSelect.cpp index f8b8c9cb7..ac214c8de 100644 --- a/src/components/GuiFastSelect.cpp +++ b/src/components/GuiFastSelect.cpp @@ -3,10 +3,10 @@ #include const std::string GuiFastSelect::LETTERS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; -const int GuiFastSelect::SCROLLSPEED = 120; +const int GuiFastSelect::SCROLLSPEED = 100; const int GuiFastSelect::SCROLLDELAY = 507; -GuiFastSelect::GuiFastSelect(GuiComponent* parent, SystemData* system, char startLetter) +GuiFastSelect::GuiFastSelect(GuiComponent* parent, GuiList* list, char startLetter) { mLetterID = LETTERS.find(toupper(startLetter)); if(mLetterID == std::string::npos) @@ -16,7 +16,7 @@ GuiFastSelect::GuiFastSelect(GuiComponent* parent, SystemData* system, char star InputManager::registerComponent(this); mParent = parent; - mSystem = system; + mList = list; mScrolling = false; mScrollTimer = 0; @@ -64,6 +64,7 @@ void GuiFastSelect::onInput(InputManager::InputButton button, bool keyDown) if(button == InputManager::SELECT && !keyDown) { + setListPos(); delete this; return; } @@ -98,3 +99,33 @@ void GuiFastSelect::setLetterID(int id) mLetterID = (size_t)id; } + +void GuiFastSelect::setListPos() +{ + char letter = LETTERS[mLetterID]; + + int min = 0; + int max = mList->getObjectCount() - 1; + + int mid; + + while(max >= min) + { + mid = ((max - min) / 2) + min; + + char checkLetter = toupper(mList->getObject(mid)->getName()[0]); + + if(checkLetter < letter) + { + min = mid + 1; + }else if(checkLetter > letter) + { + max = mid - 1; + }else{ + //exact match found + break; + } + } + + mList->setSelection(mid); +} diff --git a/src/components/GuiFastSelect.h b/src/components/GuiFastSelect.h index d5457dde8..e0064fd94 100644 --- a/src/components/GuiFastSelect.h +++ b/src/components/GuiFastSelect.h @@ -3,11 +3,13 @@ #include "../GuiComponent.h" #include "../SystemData.h" +#include "../FolderData.h" +#include "GuiList.h" class GuiFastSelect : GuiComponent { public: - GuiFastSelect(GuiComponent* parent, SystemData* system, char startLetter); + GuiFastSelect(GuiComponent* parent, GuiList* list, char startLetter); ~GuiFastSelect(); void onRender(); @@ -18,11 +20,15 @@ private: static const int SCROLLSPEED; static const int SCROLLDELAY; + void setListPos(); + void setLetterID(int id); - SystemData* mSystem; + GuiList* mList; + size_t mLetterID; GuiComponent* mParent; + int mScrollTimer, mScrollOffset; bool mScrolling; }; diff --git a/src/components/GuiGameList.cpp b/src/components/GuiGameList.cpp index af7a018c0..fc2868487 100644 --- a/src/components/GuiGameList.cpp +++ b/src/components/GuiGameList.cpp @@ -154,8 +154,7 @@ void GuiGameList::onInput(InputManager::InputButton button, bool keyDown) if(button == InputManager::SELECT && keyDown) { - std::cout << "Creating GuiFastSelect\n"; - new GuiFastSelect(this, mSystem, mList->getSelectedObject()->getName()[0]); + new GuiFastSelect(this, mList, mList->getSelectedObject()->getName()[0]); } if(mDetailed) diff --git a/src/components/GuiInputConfig.cpp b/src/components/GuiInputConfig.cpp index 1f7d7a0eb..cb3947e9c 100644 --- a/src/components/GuiInputConfig.cpp +++ b/src/components/GuiInputConfig.cpp @@ -5,7 +5,7 @@ std::string GuiInputConfig::sConfigPath = "./input.cfg"; std::string GuiInputConfig::sInputs[] = { "UNKNOWN", "UP", "DOWN", "LEFT", "RIGHT", "BUTTON1 (Accept)", "BUTTON2 (Back)", "START (Menu)", "SELECT (Jump-to-letter)" }; //must be same order as InputManager::InputButton enum -int GuiInputConfig::sInputCount = 8; //set to 9 after fast select is in +int GuiInputConfig::sInputCount = 9; GuiInputConfig::GuiInputConfig() { diff --git a/src/components/GuiList.cpp b/src/components/GuiList.cpp index 5ebc94cbf..266013137 100644 --- a/src/components/GuiList.cpp +++ b/src/components/GuiList.cpp @@ -231,3 +231,21 @@ void GuiList::setTextOffsetX(int textoffsetx) { mTextOffsetX = textoffsetx; } + +template +int GuiList::getObjectCount() +{ + return mRowVector.size(); +} + +template +listType GuiList::getObject(int i) +{ + return mRowVector.at(i).object; +} + +template +void GuiList::setSelection(int i) +{ + mSelection = i; +} diff --git a/src/components/GuiList.h b/src/components/GuiList.h index 94ef62604..b1bd179e0 100644 --- a/src/components/GuiList.h +++ b/src/components/GuiList.h @@ -37,6 +37,10 @@ public: void setTextOffsetX(int textoffsetx); + int getObjectCount(); + listType getObject(int i); + void setSelection(int i); + private: static const int SCROLLDELAY = 507; static const int SCROLLTIME = 200; diff --git a/src/components/GuiTheme.cpp b/src/components/GuiTheme.cpp index 964162e00..299d2cd27 100644 --- a/src/components/GuiTheme.cpp +++ b/src/components/GuiTheme.cpp @@ -77,7 +77,7 @@ void GuiTheme::readXML(std::string path) if(path.empty()) return; - std::cout << "Loading theme \"" << path << "\"...\n"; + //std::cout << "Loading theme \"" << path << "\"...\n"; pugi::xml_document doc; pugi::xml_parse_result result = doc.load_file(path.c_str()); @@ -108,7 +108,7 @@ void GuiTheme::readXML(std::string path) //recursively create children for all with proper parenting createComponentChildren(root, this); - std::cout << "Finished parsing theme.\n"; + //std::cout << "Finished parsing theme.\n"; } void GuiTheme::createComponentChildren(pugi::xml_node node, GuiComponent* parent) @@ -152,7 +152,7 @@ GuiComponent* GuiTheme::createElement(pugi::xml_node data, GuiComponent* parent) std::string originX, originY; splitString(origin, ' ', &originX, &originY); - std::cout << "image, x: " << posX << " y: " << posY << " w: " << dimW << " h: " << dimH << " ox: " << originX << " oy: " << originY << " tiled: " << tiled << "\n"; + //std::cout << "image, x: " << posX << " y: " << posY << " w: " << dimW << " h: " << dimH << " ox: " << originX << " oy: " << originY << " tiled: " << tiled << "\n"; //resolve to pixels from percentages/variables int x = resolveExp(posX) * Renderer::getScreenWidth();