1
0
mirror of git://projects.qi-hardware.com/gmenu2x.git synced 2024-12-26 21:35:10 +02:00

Don't pass screen coordinates to drawScrollBar()

The scroll bar always spans the content area of the screen: the
position and height depend only on the theme and not on who is
drawing it.

Note that the coordinates passed were wrong in most cases, so this
commit fixes the scroll bar positioning for several dialogs.
This commit is contained in:
Maarten ter Huurne 2013-08-14 10:49:09 +02:00
parent ea85b10d31
commit b18e3fa6a8
8 changed files with 20 additions and 22 deletions

View File

@ -282,7 +282,6 @@ void BrowseDialog::paint()
}
gmenu2x->s->clearClipRect();
gmenu2x->drawScrollBar(
numRows,fl->size(), firstElement, clipRect.y, clipRect.h);
gmenu2x->drawScrollBar(numRows,fl->size(), firstElement);
gmenu2x->s->flip();
}

View File

@ -1188,21 +1188,23 @@ int GMenu2X::drawButtonRight(Surface *s, const string &btn, const string &text,
return x-6;
}
void GMenu2X::drawScrollBar(uint pagesize, uint totalsize, uint pagepos, uint top, uint height) {
if (totalsize<=pagesize) return;
void GMenu2X::drawScrollBar(uint pageSize, uint totalSize, uint pagePos) {
if (totalSize <= pageSize) {
// Everything fits on one screen, no scroll bar needed.
return;
}
s->rectangle(resX-8, top, 7, height, skinConfColors[COLOR_SELECTION_BG]);
const uint top = skinConfInt["topBarHeight"] + 1;
const uint bottomBarHeight = 21;
const uint height = resY - top - (bottomBarHeight + 1);
//internal bar total height = height-2
//bar size
uint bs = (height-2) * pagesize / totalsize;
//bar y position
uint by = (height-2) * pagepos / totalsize;
by = top+2+by;
if (by+bs>top+height-2) by = top+height-2-bs;
s->rectangle(resX - 8, top, 7, height, skinConfColors[COLOR_SELECTION_BG]);
const uint barSize = (height - 4) * pageSize / totalSize;
const uint barPos = (height - 4 - barSize) * pagePos / (totalSize - pageSize);
s->box(resX-6, by, 3, bs, skinConfColors[COLOR_SELECTION_BG]);
s->box(resX - 6, top + 2 + barPos, 3, barSize,
skinConfColors[COLOR_SELECTION_BG]);
}
void GMenu2X::drawTopBar(Surface *s) {

View File

@ -190,7 +190,7 @@ public:
int drawButton(IconButton *btn, int x=5, int y=-10);
int drawButton(Surface *s, const std::string &btn, const std::string &text, int x=5, int y=-10);
int drawButtonRight(Surface *s, const std::string &btn, const std::string &text, int x=5, int y=-10);
void drawScrollBar(uint pagesize, uint totalsize, uint pagepos, uint top, uint height);
void drawScrollBar(uint pageSize, uint totalSize, uint pagePos);
void drawTopBar(Surface *s=NULL);
void drawBottomBar(Surface *s=NULL);

View File

@ -231,8 +231,7 @@ void Menu::paint(Surface &s) {
vector<Link*> &sectionLinks = links[iSection];
const uint numLinks = sectionLinks.size();
gmenu2x->drawScrollBar(
linkRows, (numLinks + linkColumns - 1) / linkColumns, iFirstDispRow,
topBarHeight + 1, height - topBarHeight - bottomBarHeight - 2);
linkRows, (numLinks + linkColumns - 1) / linkColumns, iFirstDispRow);
//Links
const uint linksPerPage = linkColumns * linkRows;

View File

@ -124,7 +124,7 @@ int Selector::exec(int startSelection) {
}
gmenu2x->s->clearClipRect();
gmenu2x->drawScrollBar(SELECTOR_ELEMENTS,fl.size(),firstElement,42,175);
gmenu2x->drawScrollBar(SELECTOR_ELEMENTS, fl.size(), firstElement);
gmenu2x->s->flip();
switch (gmenu2x->input.waitForPressedButton()) {

View File

@ -122,9 +122,7 @@ bool SettingsDialog::exec() {
}
gmenu2x->s->clearClipRect();
gmenu2x->drawScrollBar(
numRows, voices.size(), firstElement, clipRect.y + 1, clipRect.h
);
gmenu2x->drawScrollBar(numRows, voices.size(), firstElement);
//description
writeSubTitle(voices[sel]->getDescription());

View File

@ -94,7 +94,7 @@ void TextDialog::drawText(vector<string> *text, unsigned firstRow,
}
gmenu2x->s->clearClipRect();
gmenu2x->drawScrollBar(rowsPerPage,text->size(),firstRow,42,gmenu2x->resY-65);
gmenu2x->drawScrollBar(rowsPerPage, text->size(), firstRow);
}
void TextDialog::exec() {

View File

@ -110,7 +110,7 @@ bool WallpaperDialog::exec()
}
gmenu2x->s->clearClipRect();
gmenu2x->drawScrollBar(10,wallpapers.size(),firstElement,44,170);
gmenu2x->drawScrollBar(10, wallpapers.size(), firstElement);
gmenu2x->s->flip();
switch(gmenu2x->input.waitForPressedButton()) {