1
0
mirror of git://projects.qi-hardware.com/gmenu2x.git synced 2025-04-21 12:27:27 +03:00

Moved menu touch handling code into Menu class

This commit is contained in:
Maarten ter Huurne
2013-08-04 22:07:34 +02:00
parent 1eeba171dd
commit 41b0551595
3 changed files with 41 additions and 39 deletions

View File

@@ -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<Uint16>(screenWidth), static_cast<Uint16>(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;
}