1
0
mirror of git://projects.qi-hardware.com/gmenu2x.git synced 2024-11-16 17:17:32 +02:00

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.
This commit is contained in:
Maarten ter Huurne 2014-08-16 07:31:33 +02:00
parent 9b583f9b38
commit 88a4d1d911
3 changed files with 36 additions and 37 deletions

View File

@ -535,7 +535,7 @@ void LinkApp::showManual() {
void LinkApp::selector(int startSelection, const string &selectorDir) { void LinkApp::selector(int startSelection, const string &selectorDir) {
//Run selector interface //Run selector interface
Selector sel(gmenu2x, this, selectorDir); Selector sel(gmenu2x, *this, selectorDir);
int selection = sel.exec(startSelection); int selection = sel.exec(startSelection);
if (selection!=-1) { if (selection!=-1) {
const string &selectedDir = sel.getDir(); const string &selectedDir = sel.getDir();

View File

@ -39,32 +39,30 @@
using namespace std; using namespace std;
Selector::Selector(GMenu2X *gmenu2x, LinkApp *link, const string &selectorDir) : Selector::Selector(GMenu2X *gmenu2x, LinkApp& link, const string &selectorDir)
Dialog(gmenu2x) : Dialog(gmenu2x)
, link(link)
{ {
this->link = link; dir = selectorDir.empty() ? link.getSelectorDir() : selectorDir;
selRow = 0;
if (selectorDir.empty())
dir = link->getSelectorDir();
else
dir = selectorDir;
if (dir[dir.length()-1]!='/') dir += "/"; if (dir[dir.length()-1]!='/') dir += "/";
} }
int Selector::exec(int startSelection) { int Selector::exec(int startSelection) {
const bool showDirectories = link.getSelectorBrowser();
FileLister fl; FileLister fl;
fl.setShowDirectories(link->getSelectorBrowser()); fl.setShowDirectories(showDirectories);
fl.setFilter(link->getSelectorFilter()); fl.setFilter(link.getSelectorFilter());
prepare(fl); prepare(fl);
OffscreenSurface bg(*gmenu2x->bg); OffscreenSurface bg(*gmenu2x->bg);
drawTitleIcon(bg, link->getIconPath(), true); drawTitleIcon(bg, link.getIconPath(), true);
writeTitle(bg, link->getTitle()); writeTitle(bg, link.getTitle());
writeSubTitle(bg, link->getDescription()); writeSubTitle(bg, link.getDescription());
int x = 5; int x = 5;
x = gmenu2x->drawButton(bg, "accept", gmenu2x->tr["Select"], x); x = gmenu2x->drawButton(bg, "accept", gmenu2x->tr["Select"], x);
if (link->getSelectorBrowser()) { if (showDirectories) {
x = gmenu2x->drawButton(bg, "left", "", x); x = gmenu2x->drawButton(bg, "left", "", x);
x = gmenu2x->drawButton(bg, "cancel", gmenu2x->tr["Up one folder"], x); x = gmenu2x->drawButton(bg, "cancel", gmenu2x->tr["Up one folder"], x);
} else { } else {
@ -75,10 +73,11 @@ int Selector::exec(int startSelection) {
unsigned int top, height; unsigned int top, height;
tie(top, height) = gmenu2x->getContentArea(); tie(top, height) = gmenu2x->getContentArea();
int fontheight = gmenu2x->font->getLineSpacing(); int fontHeight = gmenu2x->font->getLineSpacing();
if (link->getSelectorBrowser()) if (showDirectories) {
fontheight = constrain(fontheight, 20, 40); fontHeight = constrain(fontHeight, 20, 40);
unsigned int nb_elements = height / fontheight; }
unsigned int nb_elements = height / fontHeight;
bg.convertToDisplayFormat(); bg.convertToDisplayFormat();
@ -111,24 +110,25 @@ int Selector::exec(int startSelection) {
} }
//Selection //Selection
unsigned int iY = top + (selected - firstElement) * fontheight; unsigned int iY = top + (selected - firstElement) * fontHeight;
if (selected<fl.size()) if (selected<fl.size())
s.box(1, iY, 309, fontheight, gmenu2x->skinConfColors[COLOR_SELECTION_BG]); s.box(1, iY, 309, fontHeight, gmenu2x->skinConfColors[COLOR_SELECTION_BG]);
//Files & Dirs //Files & Dirs
s.setClipRect(0, top, 311, height); s.setClipRect(0, top, 311, height);
for (unsigned int i = firstElement; i < fl.size() for (unsigned int i = firstElement;
&& i < firstElement + nb_elements; i++) { i < fl.size() && i < firstElement + nb_elements; i++) {
iY = i-firstElement; iY = top + (i - firstElement) * fontHeight;
if (fl.isDirectory(i)) { if (fl.isDirectory(i)) {
folderIcon->blit(s, 4, top + (iY * fontheight)); folderIcon->blit(s, 4, top + iY);
gmenu2x->font->write(s, fl[i], 21, gmenu2x->font->write(s, fl[i],
top + (iY * fontheight) + (fontheight / 2), 21, iY + (fontHeight / 2),
Font::HAlignLeft, Font::VAlignMiddle); Font::HAlignLeft, Font::VAlignMiddle);
} else } else {
gmenu2x->font->write(s, trimExtension(fl[i]), 4, gmenu2x->font->write(s, trimExtension(fl[i]),
top + (iY * fontheight) + (fontheight / 2), 4, iY + (fontHeight / 2),
Font::HAlignLeft, Font::VAlignMiddle); Font::HAlignLeft, Font::VAlignMiddle);
}
} }
s.clearClipRect(); s.clearClipRect();
@ -166,14 +166,14 @@ int Selector::exec(int startSelection) {
break; break;
case InputManager::CANCEL: case InputManager::CANCEL:
if (!link->getSelectorBrowser()) { if (!showDirectories) {
close = true; close = true;
result = false; result = false;
break; break;
} }
case InputManager::LEFT: case InputManager::LEFT:
if (link->getSelectorBrowser()) { if (showDirectories) {
string::size_type p = dir.rfind("/", dir.size()-2); string::size_type p = dir.rfind("/", dir.size()-2);
if (p==string::npos || dir.length() < 2 || dir[0] != '/') { if (p==string::npos || dir.length() < 2 || dir[0] != '/') {
close = true; close = true;

View File

@ -32,14 +32,13 @@ class FileLister;
class Selector : protected Dialog { class Selector : protected Dialog {
private: private:
int selRow; LinkApp& link;
LinkApp *link;
std::string file, dir, screendir; std::string file, dir, screendir;
void prepare(FileLister& fl); void prepare(FileLister& fl);
public: public:
Selector(GMenu2X *gmenu2x, LinkApp *link, Selector(GMenu2X *gmenu2x, LinkApp& link,
const std::string &selectorDir = ""); const std::string &selectorDir = "");
int exec(int startSelection = 0); int exec(int startSelection = 0);