Date:2013-08-14 10:49:09 (10 years 7 months ago)
Author:Maarten ter Huurne
Commit:b18e3fa6a81f3f5be141b84f8b1f67d180477d48
Message: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.
Files: src/browsedialog.cpp (1 diff)
src/gmenu2x.cpp (1 diff)
src/gmenu2x.h (1 diff)
src/menu.cpp (1 diff)
src/selector.cpp (1 diff)
src/settingsdialog.cpp (1 diff)
src/textdialog.cpp (1 diff)
src/wallpaperdialog.cpp (1 diff)

Change Details

src/browsedialog.cpp
282282    }
283283    gmenu2x->s->clearClipRect();
284284
285    gmenu2x->drawScrollBar(
286            numRows,fl->size(), firstElement, clipRect.y, clipRect.h);
285    gmenu2x->drawScrollBar(numRows,fl->size(), firstElement);
287286    gmenu2x->s->flip();
288287}
src/gmenu2x.cpp
11881188    return x-6;
11891189}
11901190
1191void GMenu2X::drawScrollBar(uint pagesize, uint totalsize, uint pagepos, uint top, uint height) {
1192    if (totalsize<=pagesize) return;
1191void GMenu2X::drawScrollBar(uint pageSize, uint totalSize, uint pagePos) {
1192    if (totalSize <= pageSize) {
1193        // Everything fits on one screen, no scroll bar needed.
1194        return;
1195    }
11931196
1194    s->rectangle(resX-8, top, 7, height, skinConfColors[COLOR_SELECTION_BG]);
1197    const uint top = skinConfInt["topBarHeight"] + 1;
1198    const uint bottomBarHeight = 21;
1199    const uint height = resY - top - (bottomBarHeight + 1);
11951200
1196    //internal bar total height = height-2
1197    //bar size
1198    uint bs = (height-2) * pagesize / totalsize;
1199    //bar y position
1200    uint by = (height-2) * pagepos / totalsize;
1201    by = top+2+by;
1202    if (by+bs>top+height-2) by = top+height-2-bs;
1201    s->rectangle(resX - 8, top, 7, height, skinConfColors[COLOR_SELECTION_BG]);
12031202
1203    const uint barSize = (height - 4) * pageSize / totalSize;
1204    const uint barPos = (height - 4 - barSize) * pagePos / (totalSize - pageSize);
12041205
1205    s->box(resX-6, by, 3, bs, skinConfColors[COLOR_SELECTION_BG]);
1206    s->box(resX - 6, top + 2 + barPos, 3, barSize,
1207            skinConfColors[COLOR_SELECTION_BG]);
12061208}
12071209
12081210void GMenu2X::drawTopBar(Surface *s) {
src/gmenu2x.h
190190    int drawButton(IconButton *btn, int x=5, int y=-10);
191191    int drawButton(Surface *s, const std::string &btn, const std::string &text, int x=5, int y=-10);
192192    int drawButtonRight(Surface *s, const std::string &btn, const std::string &text, int x=5, int y=-10);
193    void drawScrollBar(uint pagesize, uint totalsize, uint pagepos, uint top, uint height);
193    void drawScrollBar(uint pageSize, uint totalSize, uint pagePos);
194194
195195    void drawTopBar(Surface *s=NULL);
196196    void drawBottomBar(Surface *s=NULL);
src/menu.cpp
231231    vector<Link*> &sectionLinks = links[iSection];
232232    const uint numLinks = sectionLinks.size();
233233    gmenu2x->drawScrollBar(
234            linkRows, (numLinks + linkColumns - 1) / linkColumns, iFirstDispRow,
235            topBarHeight + 1, height - topBarHeight - bottomBarHeight - 2);
234            linkRows, (numLinks + linkColumns - 1) / linkColumns, iFirstDispRow);
236235
237236    //Links
238237    const uint linksPerPage = linkColumns * linkRows;
src/selector.cpp
124124        }
125125        gmenu2x->s->clearClipRect();
126126
127        gmenu2x->drawScrollBar(SELECTOR_ELEMENTS,fl.size(),firstElement,42,175);
127        gmenu2x->drawScrollBar(SELECTOR_ELEMENTS, fl.size(), firstElement);
128128        gmenu2x->s->flip();
129129
130130        switch (gmenu2x->input.waitForPressedButton()) {
src/settingsdialog.cpp
122122        }
123123        gmenu2x->s->clearClipRect();
124124
125        gmenu2x->drawScrollBar(
126            numRows, voices.size(), firstElement, clipRect.y + 1, clipRect.h
127        );
125        gmenu2x->drawScrollBar(numRows, voices.size(), firstElement);
128126
129127        //description
130128        writeSubTitle(voices[sel]->getDescription());
src/textdialog.cpp
9494    }
9595
9696    gmenu2x->s->clearClipRect();
97    gmenu2x->drawScrollBar(rowsPerPage,text->size(),firstRow,42,gmenu2x->resY-65);
97    gmenu2x->drawScrollBar(rowsPerPage, text->size(), firstRow);
9898}
9999
100100void TextDialog::exec() {
src/wallpaperdialog.cpp
110110        }
111111        gmenu2x->s->clearClipRect();
112112
113        gmenu2x->drawScrollBar(10,wallpapers.size(),firstElement,44,170);
113        gmenu2x->drawScrollBar(10, wallpapers.size(), firstElement);
114114        gmenu2x->s->flip();
115115
116116        switch(gmenu2x->input.waitForPressedButton()) {

Archive Download the corresponding diff file



interactive