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

Remove hardcoded sizes and positions in WallpaperDialog

This commit is contained in:
Paul Cercueil 2014-01-16 15:49:51 +01:00
parent ae6f52a0a3
commit 408a991a9d

View File

@ -81,9 +81,17 @@ bool WallpaperDialog::exec()
buttonbox.add(new IconButton(gmenu2x, ts, "skin:imgs/buttons/accept.png", gmenu2x->tr["Select wallpaper"])); buttonbox.add(new IconButton(gmenu2x, ts, "skin:imgs/buttons/accept.png", gmenu2x->tr["Select wallpaper"]));
buttonbox.add(new IconButton(gmenu2x, ts, "skin:imgs/buttons/cancel.png", gmenu2x->tr["Exit"])); buttonbox.add(new IconButton(gmenu2x, ts, "skin:imgs/buttons/cancel.png", gmenu2x->tr["Exit"]));
unsigned int top, height;
tie(top, height) = gmenu2x->getContentArea();
int fontheight = gmenu2x->font->getHeight();
unsigned int nb_elements = height / fontheight;
while (!close) { while (!close) {
if (selected>firstElement+9) firstElement=selected-9; if (selected > firstElement + nb_elements - 1)
if (selected<firstElement) firstElement=selected; firstElement = selected - nb_elements + 1;
if (selected < firstElement)
firstElement = selected;
//Wallpaper //Wallpaper
gmenu2x->sc[((string)"skin:wallpapers/" + wallpapers[selected]).c_str()]->blit(gmenu2x->s, 0, 0); gmenu2x->sc[((string)"skin:wallpapers/" + wallpapers[selected]).c_str()]->blit(gmenu2x->s, 0, 0);
@ -98,19 +106,22 @@ bool WallpaperDialog::exec()
buttonbox.paint(gmenu2x->s, 5); buttonbox.paint(gmenu2x->s, 5);
//Selection //Selection
iY = selected-firstElement; iY = selected - firstElement;
iY = 44+(iY*17); iY = top + (iY * fontheight);
gmenu2x->s->box(2, iY, 308, 16, gmenu2x->skinConfColors[COLOR_SELECTION_BG]); gmenu2x->s->box(2, iY, 308, fontheight, gmenu2x->skinConfColors[COLOR_SELECTION_BG]);
//Files & Directories //Files & Directories
gmenu2x->s->setClipRect(0,41,311,179); gmenu2x->s->setClipRect(0, top, 311, height);
for (i=firstElement; i<wallpapers.size() && i<firstElement+10; i++) { for (i = firstElement; i < wallpapers.size()
&& i < firstElement + nb_elements; i++) {
iY = i-firstElement; iY = i-firstElement;
gmenu2x->s->write(gmenu2x->font, wallpapers[i], 5, 52+(iY*17), Font::HAlignLeft, Font::VAlignMiddle); gmenu2x->s->write(gmenu2x->font, wallpapers[i], 5,
top + (iY * fontheight),
Font::HAlignLeft, Font::VAlignTop);
} }
gmenu2x->s->clearClipRect(); gmenu2x->s->clearClipRect();
gmenu2x->drawScrollBar(10, wallpapers.size(), firstElement); gmenu2x->drawScrollBar(nb_elements, wallpapers.size(), firstElement);
gmenu2x->s->flip(); gmenu2x->s->flip();
switch(gmenu2x->input.waitForPressedButton()) { switch(gmenu2x->input.waitForPressedButton()) {
@ -123,16 +134,20 @@ bool WallpaperDialog::exec()
else selected -= 1; else selected -= 1;
break; break;
case InputManager::ALTLEFT: case InputManager::ALTLEFT:
if ((int)(selected-9) < 0) selected = 0; if ((int)(selected - nb_elements + 1) < 0)
else selected -= 9; selected = 0;
else
selected -= nb_elements - 1;
break; break;
case InputManager::DOWN: case InputManager::DOWN:
if (selected+1 >= wallpapers.size()) selected = 0; if (selected+1 >= wallpapers.size()) selected = 0;
else selected += 1; else selected += 1;
break; break;
case InputManager::ALTRIGHT: case InputManager::ALTRIGHT:
if (selected+9 >= wallpapers.size()) selected = wallpapers.size()-1; if (selected + nb_elements - 1 >= wallpapers.size())
else selected += 9; selected = wallpapers.size() - 1;
else
selected += nb_elements - 1;
break; break;
case InputManager::ACCEPT: case InputManager::ACCEPT:
close = true; close = true;