mirror of
git://projects.qi-hardware.com/gmenu2x.git
synced 2024-11-22 13:05:20 +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:
parent
9b583f9b38
commit
88a4d1d911
@ -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();
|
||||
|
@ -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,25 +110,26 @@ int Selector::exec(int startSelection) {
|
||||
}
|
||||
|
||||
//Selection
|
||||
unsigned int iY = top + (selected - firstElement) * fontheight;
|
||||
unsigned int iY = top + (selected - firstElement) * fontHeight;
|
||||
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
|
||||
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),
|
||||
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,
|
||||
top + (iY * fontheight) + (fontheight / 2),
|
||||
} else {
|
||||
gmenu2x->font->write(s, trimExtension(fl[i]),
|
||||
4, iY + (fontHeight / 2),
|
||||
Font::HAlignLeft, Font::VAlignMiddle);
|
||||
}
|
||||
}
|
||||
s.clearClipRect();
|
||||
|
||||
gmenu2x->drawScrollBar(nb_elements, fl.size(), firstElement);
|
||||
@ -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;
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user