src/gmenu2x.cpp |
683 | 683 | if (ts.available()) { |
684 | 684 | ts.poll(); |
685 | 685 | btnContextMenu->handleTS(); |
686 | | const int topBarHeight = skinConfInt["topBarHeight"]; |
687 | | SDL_Rect re = { |
688 | | 0, 0, |
689 | | static_cast<Uint16>(resX), static_cast<Uint16>(topBarHeight) |
690 | | }; |
691 | | if (ts.pressed() && ts.inRect(re)) { |
692 | | re.w = skinConfInt["linkWidth"]; |
693 | | uint sectionsCoordX = halfX - (constrain((uint)menu->getSections().size(), 0 , linkColumns) * skinConfInt["linkWidth"]) / 2; |
694 | | for (uint i=menu->firstDispSection(); !ts.handled() && i<menu->getSections().size() && i<menu->firstDispSection()+linkColumns; i++) { |
695 | | re.x = (i-menu->firstDispSection())*re.w+sectionsCoordX; |
696 | | |
697 | | if (ts.inRect(re)) { |
698 | | menu->setSectionIndex(i); |
699 | | ts.setHandled(); |
700 | | } |
701 | | } |
702 | | } |
703 | | |
704 | | uint linksPerPage = linkColumns*linkRows; |
705 | | uint i=menu->firstDispRow()*linkColumns; |
706 | | while ( i<(menu->firstDispRow()*linkColumns)+linksPerPage && i<menu->sectionLinks()->size()) { |
707 | | if (menu->sectionLinks()->at(i)->isPressed()) |
708 | | menu->setLinkIndex(i); |
709 | | if (menu->sectionLinks()->at(i)->handleTS()) |
710 | | i = menu->sectionLinks()->size(); |
711 | | i++; |
712 | | } |
| 686 | menu->handleTS(); |
713 | 687 | } |
714 | 688 | |
715 | 689 | switch (input.waitForPressedButton()) { |
src/menu.cpp |
85 | 85 | delete *it; |
86 | 86 | } |
87 | 87 | |
88 | | uint Menu::firstDispRow() { |
89 | | return iFirstDispRow; |
90 | | } |
91 | | |
92 | 88 | void Menu::readSections(std::string parentDir) |
93 | 89 | { |
94 | 90 | DIR *dirp; |
... | ... | |
195 | 191 | } |
196 | 192 | } |
197 | 193 | |
| 194 | void Menu::handleTS() { |
| 195 | ConfIntHash &skinConfInt = gmenu2x->skinConfInt; |
| 196 | const int topBarHeight = skinConfInt["topBarHeight"]; |
| 197 | const int linkWidth = skinConfInt["linkWidth"]; |
| 198 | const int screenWidth = gmenu2x->resX; |
| 199 | const uint linkColumns = gmenu2x->linkColumns, linkRows = gmenu2x->linkRows; |
| 200 | |
| 201 | SDL_Rect re = { |
| 202 | 0, 0, |
| 203 | static_cast<Uint16>(screenWidth), static_cast<Uint16>(topBarHeight) |
| 204 | }; |
| 205 | if (ts.pressed() && ts.inRect(re)) { |
| 206 | re.w = linkWidth; |
| 207 | uint sectionsCoordX = (screenWidth - constrain((uint)sections.size(), 0, linkColumns) * linkWidth) / 2; |
| 208 | for (uint i = iFirstDispSection; !ts.handled() && i < sections.size() && i < iFirstDispSection + linkColumns; i++) { |
| 209 | re.x = (i - iFirstDispSection) * re.w + sectionsCoordX; |
| 210 | |
| 211 | if (ts.inRect(re)) { |
| 212 | setSectionIndex(i); |
| 213 | ts.setHandled(); |
| 214 | } |
| 215 | } |
| 216 | } |
| 217 | |
| 218 | const uint linksPerPage = linkColumns * linkRows; |
| 219 | uint i = iFirstDispRow * linkColumns; |
| 220 | while (i < (iFirstDispRow * linkColumns) + linksPerPage && i < sectionLinks()->size()) { |
| 221 | if (sectionLinks()->at(i)->isPressed()) { |
| 222 | setLinkIndex(i); |
| 223 | } |
| 224 | if (sectionLinks()->at(i)->handleTS()) { |
| 225 | i = sectionLinks()->size(); |
| 226 | } |
| 227 | i++; |
| 228 | } |
| 229 | } |
| 230 | |
198 | 231 | /*==================================== |
199 | 232 | SECTION MANAGEMENT |
200 | 233 | ====================================*/ |
... | ... | |
222 | 255 | setSectionIndex(iSection+1); |
223 | 256 | } |
224 | 257 | |
225 | | uint Menu::firstDispSection() { |
226 | | return iFirstDispSection; |
227 | | } |
228 | | |
229 | 258 | int Menu::selSectionIndex() { |
230 | 259 | return iSection; |
231 | 260 | } |
src/menu.h |
46 | 46 | std::vector<std::string> sections; |
47 | 47 | std::vector< std::vector<Link*> > links; |
48 | 48 | |
| 49 | std::vector<Link*> *sectionLinks(int i = -1); |
| 50 | |
49 | 51 | void readLinks(); |
50 | 52 | void freeLinks(); |
51 | 53 | void orderLinks(); |
... | ... | |
76 | 78 | #endif |
77 | 79 | #endif |
78 | 80 | |
79 | | std::vector<Link*> *sectionLinks(int i = -1); |
80 | | |
81 | 81 | int selSectionIndex(); |
82 | 82 | const std::string &selSection(); |
83 | 83 | void decSectionIndex(); |
84 | 84 | void incSectionIndex(); |
85 | 85 | void setSectionIndex(int i); |
86 | | uint firstDispSection(); |
87 | | uint firstDispRow(); |
88 | 86 | |
89 | 87 | bool addActionLink(uint section, const std::string &title, |
90 | 88 | function_t action, const std::string &description="", |
... | ... | |
96 | 94 | |
97 | 95 | void loadIcons(); |
98 | 96 | void paint(Surface &s); |
| 97 | void handleTS(); |
99 | 98 | bool linkChangeSection(uint linkIndex, uint oldSectionIndex, uint newSectionIndex); |
100 | 99 | |
101 | 100 | int selLinkIndex(); |