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

SettingsDialog: Code layout cleanup.

No functional changes, except for fetching "topBarHeight" only once.
This commit is contained in:
Maarten ter Huurne 2012-04-10 22:07:43 +02:00
parent ed8b0c38ba
commit fd642ffe9a

View File

@ -36,15 +36,18 @@ SettingsDialog::SettingsDialog(
, ts(ts_) , ts(ts_)
, text(text_) , text(text_)
{ {
if (icon!="" && gmenu2x->sc[icon] != NULL) if (icon != "" && gmenu2x->sc[icon] != NULL) {
this->icon = icon; this->icon = icon;
else } else {
this->icon = "icons/generic.png"; this->icon = "icons/generic.png";
}
} }
SettingsDialog::~SettingsDialog() { SettingsDialog::~SettingsDialog() {
for (vector<MenuSetting *>::iterator it = voices.begin(); it != voices.end(); ++it) for (vector<MenuSetting *>::iterator it = voices.begin();
it != voices.end(); ++it) {
delete *it; delete *it;
}
} }
bool SettingsDialog::exec() { bool SettingsDialog::exec() {
@ -52,13 +55,14 @@ bool SettingsDialog::exec() {
bg.convertToDisplayFormat(); bg.convertToDisplayFormat();
bool close = false, ts_pressed = false; bool close = false, ts_pressed = false;
uint i, sel = 0, iY, firstElement = 0; uint i, sel = 0, firstElement = 0;
voices[sel]->adjustInput(); voices[sel]->adjustInput();
SDL_Rect clipRect = {0, gmenu2x->skinConfInt["topBarHeight"]+1, gmenu2x->resX-9, gmenu2x->resY-gmenu2x->skinConfInt["topBarHeight"]-25}; const int topBarHeight = gmenu2x->skinConfInt["topBarHeight"];
SDL_Rect touchRect = {2, gmenu2x->skinConfInt["topBarHeight"]+4, gmenu2x->resX-12, clipRect.h}; SDL_Rect clipRect = { 0, topBarHeight + 1, gmenu2x->resX - 9, gmenu2x->resY - topBarHeight - 25 };
uint rowHeight = gmenu2x->font->getHeight()+1; // gp2x=15+1 / pandora=19+1 SDL_Rect touchRect = { 2, topBarHeight + 4, gmenu2x->resX - 12, clipRect.h };
uint numRows = (gmenu2x->resY-gmenu2x->skinConfInt["topBarHeight"]-20)/rowHeight; uint rowHeight = gmenu2x->font->getHeight() + 1; // gp2x=15+1 / pandora=19+1
uint numRows = (gmenu2x->resY - topBarHeight - 20) / rowHeight;
while (!close) { while (!close) {
if (ts.available()) ts.poll(); if (ts.available()) ts.poll();
@ -76,30 +80,42 @@ bool SettingsDialog::exec() {
if (sel<firstElement) firstElement=sel; if (sel<firstElement) firstElement=sel;
//selection //selection
iY = sel-firstElement; uint iY = topBarHeight + 2 + (sel - firstElement) * rowHeight;
iY = gmenu2x->skinConfInt["topBarHeight"]+2+(iY*rowHeight);
gmenu2x->s->setClipRect(clipRect); gmenu2x->s->setClipRect(clipRect);
if (sel<voices.size()) if (sel<voices.size()) {
gmenu2x->s->box(1, iY, 148, rowHeight-2, gmenu2x->skinConfColors[COLOR_SELECTION_BG]); gmenu2x->s->box(
1, iY, 148, rowHeight - 2,
gmenu2x->skinConfColors[COLOR_SELECTION_BG]
);
}
gmenu2x->s->clearClipRect(); gmenu2x->s->clearClipRect();
//selected option //selected option
voices[sel]->drawSelected(iY); voices[sel]->drawSelected(iY);
gmenu2x->s->setClipRect(clipRect); gmenu2x->s->setClipRect(clipRect);
if (ts_pressed && !ts.pressed()) ts_pressed = false; if (ts_pressed && !ts.pressed()) {
if (ts.available() && ts.pressed() && !ts.inRect(touchRect)) ts_pressed = false; ts_pressed = false;
}
if (ts.available() && ts.pressed() && !ts.inRect(touchRect)) {
ts_pressed = false;
}
for (i=firstElement; i<voices.size() && i<firstElement+numRows; i++) { for (i=firstElement; i<voices.size() && i<firstElement+numRows; i++) {
iY = i-firstElement; iY = i-firstElement;
voices[i]->draw(iY*rowHeight+gmenu2x->skinConfInt["topBarHeight"]+2); voices[i]->draw(iY * rowHeight + topBarHeight + 2);
if (ts.available() && ts.pressed() && ts.inRect(touchRect.x, touchRect.y+(iY*rowHeight), touchRect.w, rowHeight)) { if (ts.available() && ts.pressed() && ts.inRect(
touchRect.x, touchRect.y + (iY * rowHeight),
touchRect.w, rowHeight
)) {
ts_pressed = true; ts_pressed = true;
sel = i; sel = i;
} }
} }
gmenu2x->s->clearClipRect(); gmenu2x->s->clearClipRect();
gmenu2x->drawScrollBar(numRows,voices.size(),firstElement,clipRect.y+1,clipRect.h); gmenu2x->drawScrollBar(
numRows, voices.size(), firstElement, clipRect.y + 1, clipRect.h
);
//description //description
writeSubTitle(voices[sel]->getDescription()); writeSubTitle(voices[sel]->getDescription());
@ -114,10 +130,11 @@ bool SettingsDialog::exec() {
close = true; close = true;
break; break;
case InputManager::UP: case InputManager::UP:
if (sel==0) if (sel == 0) {
sel = voices.size()-1; sel = voices.size() - 1;
else } else {
sel -= 1; sel -= 1;
}
gmenu2x->setInputSpeed(); gmenu2x->setInputSpeed();
voices[sel]->adjustInput(); voices[sel]->adjustInput();
break; break;
@ -136,12 +153,13 @@ bool SettingsDialog::exec() {
return true; return true;
} }
void SettingsDialog::addSetting(MenuSetting* set) { void SettingsDialog::addSetting(MenuSetting *set) {
voices.push_back(set); voices.push_back(set);
} }
bool SettingsDialog::edited() { bool SettingsDialog::edited() {
for (uint i=0; i<voices.size(); i++) for (uint i=0; i < voices.size(); i++) {
if (voices[i]->edited()) return true; if (voices[i]->edited()) return true;
}
return false; return false;
} }