1
0
mirror of git://projects.qi-hardware.com/gmenu2x.git synced 2024-11-22 13:29:42 +02: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

@ -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<Uint16>(resX), static_cast<Uint16>(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() && i<menu->getSections().size() && i<menu->firstDispSection()+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 && i<menu->sectionLinks()->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()) {

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;
}

View File

@ -46,6 +46,8 @@ private:
std::vector<std::string> sections;
std::vector< std::vector<Link*> > links;
std::vector<Link*> *sectionLinks(int i = -1);
void readLinks();
void freeLinks();
void orderLinks();
@ -76,15 +78,11 @@ public:
#endif
#endif
std::vector<Link*> *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();