1
0
mirror of git://projects.qi-hardware.com/gmenu2x.git synced 2024-11-23 04:45:54 +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()) { if (ts.available()) {
ts.poll(); ts.poll();
btnContextMenu->handleTS(); btnContextMenu->handleTS();
const int topBarHeight = skinConfInt["topBarHeight"]; menu->handleTS();
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++;
}
} }
switch (input.waitForPressedButton()) { switch (input.waitForPressedButton()) {

View File

@ -85,10 +85,6 @@ Menu::~Menu() {
delete *it; delete *it;
} }
uint Menu::firstDispRow() {
return iFirstDispRow;
}
void Menu::readSections(std::string parentDir) void Menu::readSections(std::string parentDir)
{ {
DIR *dirp; 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 SECTION MANAGEMENT
====================================*/ ====================================*/
@ -222,10 +255,6 @@ void Menu::incSectionIndex() {
setSectionIndex(iSection+1); setSectionIndex(iSection+1);
} }
uint Menu::firstDispSection() {
return iFirstDispSection;
}
int Menu::selSectionIndex() { int Menu::selSectionIndex() {
return iSection; return iSection;
} }

View File

@ -46,6 +46,8 @@ private:
std::vector<std::string> sections; std::vector<std::string> sections;
std::vector< std::vector<Link*> > links; std::vector< std::vector<Link*> > links;
std::vector<Link*> *sectionLinks(int i = -1);
void readLinks(); void readLinks();
void freeLinks(); void freeLinks();
void orderLinks(); void orderLinks();
@ -76,15 +78,11 @@ public:
#endif #endif
#endif #endif
std::vector<Link*> *sectionLinks(int i = -1);
int selSectionIndex(); int selSectionIndex();
const std::string &selSection(); const std::string &selSection();
void decSectionIndex(); void decSectionIndex();
void incSectionIndex(); void incSectionIndex();
void setSectionIndex(int i); void setSectionIndex(int i);
uint firstDispSection();
uint firstDispRow();
bool addActionLink(uint section, const std::string &title, bool addActionLink(uint section, const std::string &title,
function_t action, const std::string &description="", function_t action, const std::string &description="",
@ -96,6 +94,7 @@ public:
void loadIcons(); void loadIcons();
void paint(Surface &s); void paint(Surface &s);
void handleTS();
bool linkChangeSection(uint linkIndex, uint oldSectionIndex, uint newSectionIndex); bool linkChangeSection(uint linkIndex, uint oldSectionIndex, uint newSectionIndex);
int selLinkIndex(); int selLinkIndex();