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

Remove hardcoded sizes and positions in Selector

This commit is contained in:
Paul Cercueil 2014-01-16 00:44:57 +01:00
parent 67ac54e970
commit ca3df65daa

View File

@ -40,8 +40,6 @@
using namespace std; using namespace std;
#define SELECTOR_ELEMENTS 11
Selector::Selector(GMenu2X *gmenu2x, LinkApp *link, const string &selectorDir) : Selector::Selector(GMenu2X *gmenu2x, LinkApp *link, const string &selectorDir) :
Dialog(gmenu2x) Dialog(gmenu2x)
{ {
@ -79,6 +77,12 @@ int Selector::exec(int startSelection) {
gmenu2x->drawButton(&bg, "accept", gmenu2x->tr["Select a file"], 5)) - 10); gmenu2x->drawButton(&bg, "accept", gmenu2x->tr["Select a file"], 5)) - 10);
} }
unsigned int top, height;
tie(top, height) = gmenu2x->getContentArea();
int fontheight = gmenu2x->font->getHeight();
unsigned int nb_elements = height / fontheight;
bg.convertToDisplayFormat(); bg.convertToDisplayFormat();
Uint32 selTick = SDL_GetTicks(), curTick; Uint32 selTick = SDL_GetTicks(), curTick;
@ -94,14 +98,15 @@ int Selector::exec(int startSelection) {
while (!close) { while (!close) {
bg.blit(gmenu2x->s,0,0); bg.blit(gmenu2x->s,0,0);
if (selected>=firstElement+SELECTOR_ELEMENTS) firstElement=selected-SELECTOR_ELEMENTS+1; if (selected >= firstElement + nb_elements)
if (selected<firstElement) firstElement=selected; firstElement = selected - nb_elements + 1;
if (selected < firstElement)
firstElement = selected;
//Selection //Selection
iY = selected-firstElement; iY = top + (selected - firstElement) * fontheight;
iY = 42+(iY*16);
if (selected<fl.size()) if (selected<fl.size())
gmenu2x->s->box(1, iY, 309, 14, gmenu2x->skinConfColors[COLOR_SELECTION_BG]); gmenu2x->s->box(1, iY, 309, fontheight, gmenu2x->skinConfColors[COLOR_SELECTION_BG]);
//Screenshot //Screenshot
if (selected-fl.dirCount()<screens.size() if (selected-fl.dirCount()<screens.size()
@ -115,18 +120,21 @@ int Selector::exec(int startSelection) {
} }
//Files & Dirs //Files & Dirs
gmenu2x->s->setClipRect(0,41,311,179); gmenu2x->s->setClipRect(0, top, 311, height);
for (i=firstElement; i<fl.size() && i<firstElement+SELECTOR_ELEMENTS; i++) { for (i = firstElement; i < fl.size()
&& i < firstElement + nb_elements; i++) {
iY = i-firstElement; iY = i-firstElement;
if (fl.isDirectory(i)) { if (fl.isDirectory(i)) {
gmenu2x->sc["imgs/folder.png"]->blit(gmenu2x->s, 4, 42+(iY*16)); gmenu2x->sc["imgs/folder.png"]->blit(gmenu2x->s, 4, top + (iY * fontheight));
gmenu2x->s->write(gmenu2x->font, fl[i], 21, 49+(iY*16), Font::HAlignLeft, Font::VAlignMiddle); gmenu2x->s->write(gmenu2x->font, fl[i], 21, top+(iY * fontheight), Font::HAlignLeft, Font::VAlignMiddle);
} else } else
gmenu2x->s->write(gmenu2x->font, titles[i-fl.dirCount()], 4, 49+(iY*16), Font::HAlignLeft, Font::VAlignMiddle); gmenu2x->s->write(gmenu2x->font, titles[i - fl.dirCount()], 4,
top + (iY * fontheight),
Font::HAlignLeft, Font::VAlignTop);
} }
gmenu2x->s->clearClipRect(); gmenu2x->s->clearClipRect();
gmenu2x->drawScrollBar(SELECTOR_ELEMENTS, fl.size(), firstElement); gmenu2x->drawScrollBar(nb_elements, fl.size(), firstElement);
gmenu2x->s->flip(); gmenu2x->s->flip();
switch (gmenu2x->input.waitForPressedButton()) { switch (gmenu2x->input.waitForPressedButton()) {
@ -142,8 +150,10 @@ int Selector::exec(int startSelection) {
break; break;
case InputManager::ALTLEFT: case InputManager::ALTLEFT:
if ((int)(selected-SELECTOR_ELEMENTS+1)<0) selected = 0; if ((int)(selected - nb_elements + 1) < 0)
else selected -= SELECTOR_ELEMENTS-1; selected = 0;
else
selected -= nb_elements - 1;
selTick = SDL_GetTicks(); selTick = SDL_GetTicks();
break; break;
@ -154,8 +164,10 @@ int Selector::exec(int startSelection) {
break; break;
case InputManager::ALTRIGHT: case InputManager::ALTRIGHT:
if (selected+SELECTOR_ELEMENTS-1>=fl.size()) selected = fl.size()-1; if (selected + nb_elements - 1 >= fl.size())
else selected += SELECTOR_ELEMENTS-1; selected = fl.size() - 1;
else
selected += nb_elements - 1;
selTick = SDL_GetTicks(); selTick = SDL_GetTicks();
break; break;