From b18e3fa6a81f3f5be141b84f8b1f67d180477d48 Mon Sep 17 00:00:00 2001 From: Maarten ter Huurne Date: Wed, 14 Aug 2013 10:49:09 +0200 Subject: [PATCH] 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. --- src/browsedialog.cpp | 3 +-- src/gmenu2x.cpp | 24 +++++++++++++----------- src/gmenu2x.h | 2 +- src/menu.cpp | 3 +-- src/selector.cpp | 2 +- src/settingsdialog.cpp | 4 +--- src/textdialog.cpp | 2 +- src/wallpaperdialog.cpp | 2 +- 8 files changed, 20 insertions(+), 22 deletions(-) diff --git a/src/browsedialog.cpp b/src/browsedialog.cpp index 829dec3..d5e7d76 100644 --- a/src/browsedialog.cpp +++ b/src/browsedialog.cpp @@ -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(); } diff --git a/src/gmenu2x.cpp b/src/gmenu2x.cpp index 2be87ad..31e1da0 100644 --- a/src/gmenu2x.cpp +++ b/src/gmenu2x.cpp @@ -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) { diff --git a/src/gmenu2x.h b/src/gmenu2x.h index de9cf88..aa4e50c 100644 --- a/src/gmenu2x.h +++ b/src/gmenu2x.h @@ -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); diff --git a/src/menu.cpp b/src/menu.cpp index 4ed63e5..21b2c69 100644 --- a/src/menu.cpp +++ b/src/menu.cpp @@ -231,8 +231,7 @@ void Menu::paint(Surface &s) { vector §ionLinks = 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; diff --git a/src/selector.cpp b/src/selector.cpp index 5aac770..c289338 100644 --- a/src/selector.cpp +++ b/src/selector.cpp @@ -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()) { diff --git a/src/settingsdialog.cpp b/src/settingsdialog.cpp index e9d9b50..28759c9 100644 --- a/src/settingsdialog.cpp +++ b/src/settingsdialog.cpp @@ -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()); diff --git a/src/textdialog.cpp b/src/textdialog.cpp index 1859c04..46a45a3 100644 --- a/src/textdialog.cpp +++ b/src/textdialog.cpp @@ -94,7 +94,7 @@ void TextDialog::drawText(vector *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() { diff --git a/src/wallpaperdialog.cpp b/src/wallpaperdialog.cpp index e2c2d66..96cfc5b 100644 --- a/src/wallpaperdialog.cpp +++ b/src/wallpaperdialog.cpp @@ -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()) {