diff --git a/src/gmenu2x.cpp b/src/gmenu2x.cpp index 92295a4..503c2a9 100644 --- a/src/gmenu2x.cpp +++ b/src/gmenu2x.cpp @@ -683,33 +683,7 @@ void GMenu2X::main() { if (ts.available()) { ts.poll(); btnContextMenu->handleTS(); - const int topBarHeight = skinConfInt["topBarHeight"]; - SDL_Rect re = { - 0, 0, - static_cast(resX), static_cast(topBarHeight) - }; - if (ts.pressed() && ts.inRect(re)) { - re.w = skinConfInt["linkWidth"]; - uint sectionsCoordX = halfX - (constrain((uint)menu->getSections().size(), 0 , linkColumns) * skinConfInt["linkWidth"]) / 2; - for (uint i=menu->firstDispSection(); !ts.handled() && igetSections().size() && ifirstDispSection()+linkColumns; i++) { - re.x = (i-menu->firstDispSection())*re.w+sectionsCoordX; - - if (ts.inRect(re)) { - menu->setSectionIndex(i); - ts.setHandled(); - } - } - } - - uint linksPerPage = linkColumns*linkRows; - uint i=menu->firstDispRow()*linkColumns; - while ( i<(menu->firstDispRow()*linkColumns)+linksPerPage && isectionLinks()->size()) { - if (menu->sectionLinks()->at(i)->isPressed()) - menu->setLinkIndex(i); - if (menu->sectionLinks()->at(i)->handleTS()) - i = menu->sectionLinks()->size(); - i++; - } + menu->handleTS(); } switch (input.waitForPressedButton()) { diff --git a/src/menu.cpp b/src/menu.cpp index e43b173..b52acd4 100644 --- a/src/menu.cpp +++ b/src/menu.cpp @@ -85,10 +85,6 @@ Menu::~Menu() { delete *it; } -uint Menu::firstDispRow() { - return iFirstDispRow; -} - void Menu::readSections(std::string parentDir) { DIR *dirp; @@ -195,6 +191,43 @@ void Menu::paint(Surface &s) { } } +void Menu::handleTS() { + ConfIntHash &skinConfInt = gmenu2x->skinConfInt; + const int topBarHeight = skinConfInt["topBarHeight"]; + const int linkWidth = skinConfInt["linkWidth"]; + const int screenWidth = gmenu2x->resX; + const uint linkColumns = gmenu2x->linkColumns, linkRows = gmenu2x->linkRows; + + SDL_Rect re = { + 0, 0, + static_cast(screenWidth), static_cast(topBarHeight) + }; + if (ts.pressed() && ts.inRect(re)) { + re.w = linkWidth; + uint sectionsCoordX = (screenWidth - constrain((uint)sections.size(), 0, linkColumns) * linkWidth) / 2; + for (uint i = iFirstDispSection; !ts.handled() && i < sections.size() && i < iFirstDispSection + linkColumns; i++) { + re.x = (i - iFirstDispSection) * re.w + sectionsCoordX; + + if (ts.inRect(re)) { + setSectionIndex(i); + ts.setHandled(); + } + } + } + + const uint linksPerPage = linkColumns * linkRows; + uint i = iFirstDispRow * linkColumns; + while (i < (iFirstDispRow * linkColumns) + linksPerPage && i < sectionLinks()->size()) { + if (sectionLinks()->at(i)->isPressed()) { + setLinkIndex(i); + } + if (sectionLinks()->at(i)->handleTS()) { + i = sectionLinks()->size(); + } + i++; + } +} + /*==================================== SECTION MANAGEMENT ====================================*/ @@ -222,10 +255,6 @@ void Menu::incSectionIndex() { setSectionIndex(iSection+1); } -uint Menu::firstDispSection() { - return iFirstDispSection; -} - int Menu::selSectionIndex() { return iSection; } diff --git a/src/menu.h b/src/menu.h index aca3bc7..f707407 100644 --- a/src/menu.h +++ b/src/menu.h @@ -46,6 +46,8 @@ private: std::vector sections; std::vector< std::vector > links; + std::vector *sectionLinks(int i = -1); + void readLinks(); void freeLinks(); void orderLinks(); @@ -76,15 +78,11 @@ public: #endif #endif - std::vector *sectionLinks(int i = -1); - int selSectionIndex(); const std::string &selSection(); void decSectionIndex(); void incSectionIndex(); void setSectionIndex(int i); - uint firstDispSection(); - uint firstDispRow(); bool addActionLink(uint section, const std::string &title, function_t action, const std::string &description="", @@ -96,6 +94,7 @@ public: void loadIcons(); void paint(Surface &s); + void handleTS(); bool linkChangeSection(uint linkIndex, uint oldSectionIndex, uint newSectionIndex); int selLinkIndex();