Date:2014-08-16 15:10:11 (9 years 7 months ago)
Author:Maarten ter Huurne
Commit:d16cb902b3b51ea3a676ae0f42c9483ce8976493
Message:Improved Selector's handling of the folder icon

Renamed fontHeight to lineHeight, since it is computed using both the
font's line spacing and the height of the folder icon. For the latter,
use the actual icon height plus two pixels spacing instead of the
hardcoded value of 20 (16 height + 4 pixels spacing).

Fixed recently introduced bug where "top" is added to the folder icon
y-coordinate twice. Also center the icon vertically when a large font
is used.

Don't crash if the folder icon is missing. This could only happen on
broken installations though. Also don't search for the icon twice:
SurfaceCollection::skinRes already calls addSkinRes internally when
there is no cached surface for the key.
Files: src/selector.cpp (2 diffs)

Change Details

src/selector.cpp
7373    unsigned int top, height;
7474    tie(top, height) = gmenu2x->getContentArea();
7575
76    int fontHeight = gmenu2x->font->getLineSpacing();
77    if (showDirectories) {
78        fontHeight = constrain(fontHeight, 20, 40);
76    auto folderIcon = gmenu2x->sc.skinRes("imgs/folder.png");
77
78    int lineHeight = gmenu2x->font->getLineSpacing();
79    if (showDirectories && folderIcon) {
80        lineHeight = max(lineHeight, folderIcon->height() + 2);
7981    }
80    unsigned int nb_elements = height / fontHeight;
82    unsigned int nb_elements = max(height / lineHeight, 1u);
8183
8284    bg.convertToDisplayFormat();
8385
8486    unsigned int firstElement = 0;
8587    unsigned int selected = constrain(startSelection, 0, fl.size() - 1);
8688
87    auto folderIcon = gmenu2x->sc.skinRes("imgs/folder.png");
88    if (!folderIcon) {
89        folderIcon = gmenu2x->sc.addSkinRes("imgs/folder.png");
90    }
91
9289    bool close = false, result = true;
9390    while (!close) {
9491        OutputSurface& s = *gmenu2x->s;
...... 
110107        }
111108
112109        //Selection
113        unsigned int iY = top + (selected - firstElement) * fontHeight;
110        int iY = top + (selected - firstElement) * lineHeight;
114111        if (selected<fl.size())
115            s.box(1, iY, 309, fontHeight, gmenu2x->skinConfColors[COLOR_SELECTION_BG]);
112            s.box(1, iY, 309, lineHeight, gmenu2x->skinConfColors[COLOR_SELECTION_BG]);
116113
117114        //Files & Dirs
118115        s.setClipRect(0, top, 311, height);
119116        for (unsigned int i = firstElement;
120117                i < fl.size() && i < firstElement + nb_elements; i++) {
121            iY = top + (i - firstElement) * fontHeight;
118            iY = top + (i - firstElement) * lineHeight;
119            x = 4;
122120            if (fl.isDirectory(i)) {
123                folderIcon->blit(s, 4, top + iY);
121                if (folderIcon) {
122                    folderIcon->blit(s,
123                            x, iY + (lineHeight - folderIcon->height()) / 2);
124                    x += folderIcon->width() + 2;
125                }
124126                gmenu2x->font->write(s, fl[i],
125                        21, iY + (fontHeight / 2),
127                        x, iY + lineHeight / 2,
126128                        Font::HAlignLeft, Font::VAlignMiddle);
127129            } else {
128130                gmenu2x->font->write(s, trimExtension(fl[i]),
129                        4, iY + (fontHeight / 2),
131                        x, iY + lineHeight / 2,
130132                        Font::HAlignLeft, Font::VAlignMiddle);
131133            }
132134        }

Archive Download the corresponding diff file



interactive