From 88a4d1d9116564c1e5b5e94a3af6f6556c3f20cd Mon Sep 17 00:00:00 2001 From: Maarten ter Huurne Date: Sat, 16 Aug 2014 07:31:33 +0200 Subject: [PATCH] Minor cleanups in Selector Removed unused data member selRow. Keep reference to LinkApp instead of pointer. Call LinkApp::getSelectorBrowser once and store result. Renamed fontheight to fontHeight. Use iY consistently: store the item's y-coordinate in it. --- src/linkapp.cpp | 2 +- src/selector.cpp | 66 ++++++++++++++++++++++++------------------------ src/selector.h | 5 ++-- 3 files changed, 36 insertions(+), 37 deletions(-) diff --git a/src/linkapp.cpp b/src/linkapp.cpp index 59ee82f..e9e270f 100644 --- a/src/linkapp.cpp +++ b/src/linkapp.cpp @@ -535,7 +535,7 @@ void LinkApp::showManual() { void LinkApp::selector(int startSelection, const string &selectorDir) { //Run selector interface - Selector sel(gmenu2x, this, selectorDir); + Selector sel(gmenu2x, *this, selectorDir); int selection = sel.exec(startSelection); if (selection!=-1) { const string &selectedDir = sel.getDir(); diff --git a/src/selector.cpp b/src/selector.cpp index af4d6bd..2f37063 100644 --- a/src/selector.cpp +++ b/src/selector.cpp @@ -39,32 +39,30 @@ using namespace std; -Selector::Selector(GMenu2X *gmenu2x, LinkApp *link, const string &selectorDir) : - Dialog(gmenu2x) +Selector::Selector(GMenu2X *gmenu2x, LinkApp& link, const string &selectorDir) + : Dialog(gmenu2x) + , link(link) { - this->link = link; - selRow = 0; - if (selectorDir.empty()) - dir = link->getSelectorDir(); - else - dir = selectorDir; + dir = selectorDir.empty() ? link.getSelectorDir() : selectorDir; if (dir[dir.length()-1]!='/') dir += "/"; } int Selector::exec(int startSelection) { + const bool showDirectories = link.getSelectorBrowser(); + FileLister fl; - fl.setShowDirectories(link->getSelectorBrowser()); - fl.setFilter(link->getSelectorFilter()); + fl.setShowDirectories(showDirectories); + fl.setFilter(link.getSelectorFilter()); prepare(fl); OffscreenSurface bg(*gmenu2x->bg); - drawTitleIcon(bg, link->getIconPath(), true); - writeTitle(bg, link->getTitle()); - writeSubTitle(bg, link->getDescription()); + drawTitleIcon(bg, link.getIconPath(), true); + writeTitle(bg, link.getTitle()); + writeSubTitle(bg, link.getDescription()); int x = 5; x = gmenu2x->drawButton(bg, "accept", gmenu2x->tr["Select"], x); - if (link->getSelectorBrowser()) { + if (showDirectories) { x = gmenu2x->drawButton(bg, "left", "", x); x = gmenu2x->drawButton(bg, "cancel", gmenu2x->tr["Up one folder"], x); } else { @@ -75,10 +73,11 @@ int Selector::exec(int startSelection) { unsigned int top, height; tie(top, height) = gmenu2x->getContentArea(); - int fontheight = gmenu2x->font->getLineSpacing(); - if (link->getSelectorBrowser()) - fontheight = constrain(fontheight, 20, 40); - unsigned int nb_elements = height / fontheight; + int fontHeight = gmenu2x->font->getLineSpacing(); + if (showDirectories) { + fontHeight = constrain(fontHeight, 20, 40); + } + unsigned int nb_elements = height / fontHeight; bg.convertToDisplayFormat(); @@ -111,24 +110,25 @@ int Selector::exec(int startSelection) { } //Selection - unsigned int iY = top + (selected - firstElement) * fontheight; + unsigned int iY = top + (selected - firstElement) * fontHeight; if (selectedskinConfColors[COLOR_SELECTION_BG]); + s.box(1, iY, 309, fontHeight, gmenu2x->skinConfColors[COLOR_SELECTION_BG]); //Files & Dirs s.setClipRect(0, top, 311, height); - for (unsigned int i = firstElement; i < fl.size() - && i < firstElement + nb_elements; i++) { - iY = i-firstElement; + for (unsigned int i = firstElement; + i < fl.size() && i < firstElement + nb_elements; i++) { + iY = top + (i - firstElement) * fontHeight; if (fl.isDirectory(i)) { - folderIcon->blit(s, 4, top + (iY * fontheight)); - gmenu2x->font->write(s, fl[i], 21, - top + (iY * fontheight) + (fontheight / 2), - Font::HAlignLeft, Font::VAlignMiddle); - } else - gmenu2x->font->write(s, trimExtension(fl[i]), 4, - top + (iY * fontheight) + (fontheight / 2), - Font::HAlignLeft, Font::VAlignMiddle); + folderIcon->blit(s, 4, top + iY); + gmenu2x->font->write(s, fl[i], + 21, iY + (fontHeight / 2), + Font::HAlignLeft, Font::VAlignMiddle); + } else { + gmenu2x->font->write(s, trimExtension(fl[i]), + 4, iY + (fontHeight / 2), + Font::HAlignLeft, Font::VAlignMiddle); + } } s.clearClipRect(); @@ -166,14 +166,14 @@ int Selector::exec(int startSelection) { break; case InputManager::CANCEL: - if (!link->getSelectorBrowser()) { + if (!showDirectories) { close = true; result = false; break; } case InputManager::LEFT: - if (link->getSelectorBrowser()) { + if (showDirectories) { string::size_type p = dir.rfind("/", dir.size()-2); if (p==string::npos || dir.length() < 2 || dir[0] != '/') { close = true; diff --git a/src/selector.h b/src/selector.h index 5ed07a6..8c5f667 100644 --- a/src/selector.h +++ b/src/selector.h @@ -32,14 +32,13 @@ class FileLister; class Selector : protected Dialog { private: - int selRow; - LinkApp *link; + LinkApp& link; std::string file, dir, screendir; void prepare(FileLister& fl); public: - Selector(GMenu2X *gmenu2x, LinkApp *link, + Selector(GMenu2X *gmenu2x, LinkApp& link, const std::string &selectorDir = ""); int exec(int startSelection = 0);