Date:2013-08-04 22:07:34 (10 years 7 months ago)
Author:Maarten ter Huurne
Commit:41b0551595cc24ea5b6dd01a4df2be84d42cb44f
Message:Moved menu touch handling code into Menu class

Files: src/gmenu2x.cpp (1 diff)
src/menu.cpp (3 diffs)
src/menu.h (3 diffs)

Change Details

src/gmenu2x.cpp
683683        if (ts.available()) {
684684            ts.poll();
685685            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();
713687        }
714688
715689        switch (input.waitForPressedButton()) {
src/menu.cpp
8585        delete *it;
8686}
8787
88uint Menu::firstDispRow() {
89    return iFirstDispRow;
90}
91
9288void Menu::readSections(std::string parentDir)
9389{
9490    DIR *dirp;
...... 
195191    }
196192}
197193
194void 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
198231/*====================================
199232   SECTION MANAGEMENT
200233  ====================================*/
...... 
222255    setSectionIndex(iSection+1);
223256}
224257
225uint Menu::firstDispSection() {
226    return iFirstDispSection;
227}
228
229258int Menu::selSectionIndex() {
230259    return iSection;
231260}
src/menu.h
4646    std::vector<std::string> sections;
4747    std::vector< std::vector<Link*> > links;
4848
49    std::vector<Link*> *sectionLinks(int i = -1);
50
4951    void readLinks();
5052    void freeLinks();
5153    void orderLinks();
...... 
7678#endif
7779#endif
7880
79    std::vector<Link*> *sectionLinks(int i = -1);
80
8181    int selSectionIndex();
8282    const std::string &selSection();
8383    void decSectionIndex();
8484    void incSectionIndex();
8585    void setSectionIndex(int i);
86    uint firstDispSection();
87    uint firstDispRow();
8886
8987    bool addActionLink(uint section, const std::string &title,
9088            function_t action, const std::string &description="",
...... 
9694
9795    void loadIcons();
9896    void paint(Surface &s);
97    void handleTS();
9998    bool linkChangeSection(uint linkIndex, uint oldSectionIndex, uint newSectionIndex);
10099
101100    int selLinkIndex();

Archive Download the corresponding diff file



interactive