1
0
mirror of git://projects.qi-hardware.com/gmenu2x.git synced 2024-12-28 00:32:04 +02:00

Moved menu painting code into Menu class

This commit is contained in:
Maarten ter Huurne 2013-08-04 21:14:29 +02:00
parent cbe7735f73
commit 1eeba171dd
3 changed files with 75 additions and 51 deletions

View File

@ -603,60 +603,16 @@ void GMenu2X::paint() {
//Background
sc["bgmain"]->blit(s,0,0);
//Sections
uint sectionLinkPadding = (skinConfInt["topBarHeight"] - 32 - font->getHeight()) / 3;
uint sectionsCoordX = halfX - (constrain((uint)menu->getSections().size(), 0 , linkColumns) * skinConfInt["linkWidth"]) / 2;
if (menu->firstDispSection()>0)
sc.skinRes("imgs/l_enabled.png")->blit(s,0,0);
else
sc.skinRes("imgs/l_disabled.png")->blit(s,0,0);
if (menu->firstDispSection()+linkColumns<menu->getSections().size())
sc.skinRes("imgs/r_enabled.png")->blit(s,resX-10,0);
else
sc.skinRes("imgs/r_disabled.png")->blit(s,resX-10,0);
for (uint i = menu->firstDispSection(); i < menu->getSections().size() && i < menu->firstDispSection() + linkColumns; i++) {
string sectionIcon = "skin:sections/"+menu->getSections()[i]+".png";
int x = (i-menu->firstDispSection())*skinConfInt["linkWidth"]+sectionsCoordX;
if (menu->selSectionIndex()==(int)i)
s->box(x, 0, skinConfInt["linkWidth"],
skinConfInt["topBarHeight"], skinConfColors[COLOR_SELECTION_BG]);
x += skinConfInt["linkWidth"]/2;
if (sc.exists(sectionIcon))
sc[sectionIcon]->blit(s,x-16,sectionLinkPadding,32,32);
else
sc.skinRes("icons/section.png")->blit(s,x-16,sectionLinkPadding);
s->write( font, menu->getSections()[i], x, skinConfInt["topBarHeight"]-sectionLinkPadding, Font::HAlignCenter, Font::VAlignBottom );
}
menu->paint(*s);
//Links
uint linksPerPage = linkColumns * linkRows;
int linkSpacingX = (resX-10 - linkColumns*skinConfInt["linkWidth"])/linkColumns;
int linkSpacingY = (resY-35 - skinConfInt["topBarHeight"] - linkRows*skinConfInt["linkHeight"])/linkRows;
for (uint i = menu->firstDispRow() * linkColumns; i < menu->firstDispRow() * linkColumns + linksPerPage && i < menu->sectionLinks()->size(); i++) {
int ir = i-menu->firstDispRow()*linkColumns;
int x = (ir%linkColumns)*(skinConfInt["linkWidth"]+linkSpacingX)+6;
int y = ir/linkColumns*(skinConfInt["linkHeight"]+linkSpacingY)+skinConfInt["topBarHeight"]+2;
menu->sectionLinks()->at(i)->setPosition(x,y);
if (i == (uint)menu->selLinkIndex())
menu->sectionLinks()->at(i)->paintHover();
menu->sectionLinks()->at(i)->paint();
}
s->clearClipRect();
drawScrollBar(linkRows,menu->sectionLinks()->size()/linkColumns + ((menu->sectionLinks()->size()%linkColumns==0) ? 0 : 1),menu->firstDispRow(),43,resY-81);
if (menu->selLink()!=NULL) {
s->write ( font, menu->selLink()->getDescription(), halfX, resY-19, Font::HAlignCenter, Font::VAlignBottom );
if (menu->selLinkApp()!=NULL) {
LinkApp *linkApp = menu->selLinkApp();
if (linkApp) {
#ifdef ENABLE_CPUFREQ
s->write ( font, menu->selLinkApp()->clockStr(confInt["maxClock"]), cpuX, bottomBarTextY, Font::HAlignLeft, Font::VAlignMiddle );
s->write(font, linkApp->clockStr(confInt["maxClock"]), cpuX, bottomBarTextY, Font::HAlignLeft, Font::VAlignMiddle);
#endif
//Manual indicator
if (!menu->selLinkApp()->getManual().empty())
sc.skinRes("imgs/manual.png")->blit(s,manualX,bottomBarIconY);
}
//Manual indicator
if (!linkApp->getManual().empty())
sc.skinRes("imgs/manual.png")->blit(s, manualX, bottomBarIconY);
}
if (ts.available()) {

View File

@ -129,6 +129,72 @@ void Menu::loadIcons() {
}
}
void Menu::paint(Surface &s) {
const uint width = s.width(), height = s.height();
const uint linkColumns = gmenu2x->linkColumns, linkRows = gmenu2x->linkRows;
Font &font = *gmenu2x->font;
SurfaceCollection sc = gmenu2x->sc;
ConfIntHash &skinConfInt = gmenu2x->skinConfInt;
const int topBarHeight = skinConfInt["topBarHeight"];
const int linkWidth = skinConfInt["linkWidth"];
const int linkHeight = skinConfInt["linkHeight"];
RGBAColor &selectionBgColor = gmenu2x->skinConfColors[COLOR_SELECTION_BG];
//Sections
const uint sectionLinkPadding = (topBarHeight - 32 - font.getHeight()) / 3;
const uint sectionsCoordX =
(width - constrain((uint)sections.size(), 0 , linkColumns) * linkWidth) / 2;
if (iFirstDispSection > 0) {
sc.skinRes("imgs/l_enabled.png")->blit(&s, 0, 0);
} else {
sc.skinRes("imgs/l_disabled.png")->blit(&s, 0, 0);
}
if (iFirstDispSection + linkColumns < sections.size()) {
sc.skinRes("imgs/r_enabled.png")->blit(&s, width - 10, 0);
} else {
sc.skinRes("imgs/r_disabled.png")->blit(&s, width - 10, 0);
}
for (uint i = iFirstDispSection; i < sections.size() && i < iFirstDispSection + linkColumns; i++) {
string sectionIcon = "skin:sections/" + sections[i] + ".png";
int x = (i - iFirstDispSection) * linkWidth + sectionsCoordX;
if (i == (uint)iSection) {
s.box(x, 0, linkWidth, topBarHeight, selectionBgColor);
}
x += linkWidth / 2;
if (sc.exists(sectionIcon)) {
sc[sectionIcon]->blit(&s, x - 16, sectionLinkPadding, 32, 32);
} else {
sc.skinRes("icons/section.png")->blit(&s, x - 16, sectionLinkPadding);
}
s.write(&font, sections[i], x, topBarHeight - sectionLinkPadding, Font::HAlignCenter, Font::VAlignBottom);
}
//Links
const uint linksPerPage = linkColumns * linkRows;
const int linkSpacingX = (width - 10 - linkColumns * linkWidth) / linkColumns;
const int linkSpacingY = (height - 35 - topBarHeight - linkRows * linkHeight) / linkRows;
for (uint i = iFirstDispRow * linkColumns; i < iFirstDispRow * linkColumns + linksPerPage && i < sectionLinks()->size(); i++) {
const int ir = i - iFirstDispRow * linkColumns;
const int x = (ir % linkColumns) * (linkWidth + linkSpacingX) + 6;
const int y = ir / linkColumns * (linkHeight + linkSpacingY) + topBarHeight + 2;
sectionLinks()->at(i)->setPosition(x, y);
if (i == (uint)iLink) {
sectionLinks()->at(i)->paintHover();
}
sectionLinks()->at(i)->paint();
}
s.clearClipRect();
gmenu2x->drawScrollBar(linkRows, sectionLinks()->size() / linkColumns + ((sectionLinks()->size() % linkColumns == 0) ? 0 : 1), iFirstDispRow, 43, height - 81);
if (selLink()) {
s.write(&font, selLink()->getDescription(), width / 2, height - 19, Font::HAlignCenter, Font::VAlignBottom);
}
}
/*====================================
SECTION MANAGEMENT
====================================*/

View File

@ -30,6 +30,7 @@
class LinkApp;
class GMenu2X;
class Monitor;
class Surface;
/**
Handles the menu structure
@ -94,6 +95,7 @@ public:
void deleteSelectedSection();
void loadIcons();
void paint(Surface &s);
bool linkChangeSection(uint linkIndex, uint oldSectionIndex, uint newSectionIndex);
int selLinkIndex();