2010-02-04 13:33:47 +02:00
|
|
|
/***************************************************************************
|
2011-10-23 17:13:02 +03:00
|
|
|
* Copyright (C) 2006 by Massimiliano Torromeo *
|
|
|
|
* massimiliano.torromeo@gmail.com *
|
2010-02-04 13:33:47 +02:00
|
|
|
* *
|
|
|
|
* This program is free software; you can redistribute it and/or modify *
|
|
|
|
* it under the terms of the GNU General Public License as published by *
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or *
|
|
|
|
* (at your option) any later version. *
|
|
|
|
* *
|
|
|
|
* This program is distributed in the hope that it will be useful, *
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
|
|
* GNU General Public License for more details. *
|
|
|
|
* *
|
|
|
|
* You should have received a copy of the GNU General Public License *
|
|
|
|
* along with this program; if not, write to the *
|
|
|
|
* Free Software Foundation, Inc., *
|
|
|
|
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
|
|
|
***************************************************************************/
|
|
|
|
|
|
|
|
#include "wallpaperdialog.h"
|
2011-10-23 17:13:02 +03:00
|
|
|
|
2010-09-17 23:31:09 +03:00
|
|
|
#include "debug.h"
|
2011-10-23 17:13:02 +03:00
|
|
|
#include "buttonbox.h"
|
|
|
|
#include "filelister.h"
|
|
|
|
#include "gmenu2x.h"
|
2011-10-23 18:27:29 +03:00
|
|
|
#include "iconbutton.h"
|
2013-08-03 23:30:12 +03:00
|
|
|
#include "surface.h"
|
2011-10-23 18:27:29 +03:00
|
|
|
#include "utilities.h"
|
2011-10-23 17:13:02 +03:00
|
|
|
|
|
|
|
#include <iostream>
|
2010-02-04 13:33:47 +02:00
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
2011-12-23 15:03:05 +02:00
|
|
|
WallpaperDialog::WallpaperDialog(GMenu2X *gmenu2x, Touchscreen &ts_)
|
2010-07-26 04:36:55 +03:00
|
|
|
: Dialog(gmenu2x)
|
2011-12-23 15:03:05 +02:00
|
|
|
, ts(ts_)
|
2010-05-05 15:35:52 +03:00
|
|
|
{
|
2010-02-04 13:33:47 +02:00
|
|
|
}
|
|
|
|
|
2010-05-05 15:35:52 +03:00
|
|
|
bool WallpaperDialog::exec()
|
|
|
|
{
|
2010-02-04 13:33:47 +02:00
|
|
|
bool close = false, result = true;
|
|
|
|
|
2011-04-12 11:18:10 +03:00
|
|
|
FileLister fl;
|
2013-07-06 00:08:09 +03:00
|
|
|
fl.setFilter("png");
|
2011-04-12 11:18:10 +03:00
|
|
|
|
2011-04-14 12:16:16 +03:00
|
|
|
string filepath = GMenu2X::getHome() + "/skins/"
|
2011-04-12 11:18:10 +03:00
|
|
|
+ gmenu2x->confStr["skin"] + "/wallpapers";
|
|
|
|
if (fileExists(filepath))
|
|
|
|
fl.setPath(filepath, true);
|
|
|
|
|
2011-04-14 12:16:16 +03:00
|
|
|
filepath = GMENU2X_SYSTEM_DIR "/skins/"
|
2011-04-12 11:18:10 +03:00
|
|
|
+ gmenu2x->confStr["skin"] + "/wallpapers";
|
|
|
|
if (fileExists(filepath)) {
|
|
|
|
fl.setPath(filepath, false);
|
|
|
|
fl.browse(false);
|
2010-02-04 13:33:47 +02:00
|
|
|
}
|
2011-04-12 11:18:10 +03:00
|
|
|
|
2010-02-04 13:33:47 +02:00
|
|
|
if (gmenu2x->confStr["skin"] != "Default") {
|
2011-04-14 12:16:16 +03:00
|
|
|
filepath = GMenu2X::getHome() + "/skins/Default/wallpapers";
|
2011-04-12 11:18:10 +03:00
|
|
|
if (fileExists(filepath)) {
|
|
|
|
fl.setPath(filepath, false);
|
|
|
|
fl.browse(false);
|
|
|
|
}
|
|
|
|
|
2011-04-14 12:16:16 +03:00
|
|
|
filepath = GMENU2X_SYSTEM_DIR "/skins/Default/wallpapers";
|
2011-04-12 11:18:10 +03:00
|
|
|
if (fileExists(filepath)) {
|
|
|
|
fl.setPath(filepath, false);
|
|
|
|
fl.browse(false);
|
|
|
|
}
|
2010-02-04 13:33:47 +02:00
|
|
|
}
|
2010-09-17 23:31:09 +03:00
|
|
|
|
2011-04-12 11:18:10 +03:00
|
|
|
vector<string> wallpapers = fl.getFiles();
|
|
|
|
|
2010-09-17 23:31:09 +03:00
|
|
|
DEBUG("Wallpapers: %i\n", wallpapers.size());
|
2010-02-04 13:33:47 +02:00
|
|
|
|
|
|
|
uint i, selected = 0, firstElement = 0, iY;
|
2010-09-17 23:34:26 +03:00
|
|
|
|
2011-09-15 22:15:20 +03:00
|
|
|
ButtonBox buttonbox(gmenu2x);
|
2014-06-12 23:37:08 +03:00
|
|
|
buttonbox.add(new IconButton(gmenu2x, ts, "skin:imgs/buttons/accept.png", gmenu2x->tr["Select"]));
|
2011-12-23 15:03:05 +02:00
|
|
|
buttonbox.add(new IconButton(gmenu2x, ts, "skin:imgs/buttons/cancel.png", gmenu2x->tr["Exit"]));
|
2011-09-15 22:15:20 +03:00
|
|
|
|
2014-01-16 16:49:51 +02:00
|
|
|
unsigned int top, height;
|
|
|
|
tie(top, height) = gmenu2x->getContentArea();
|
|
|
|
|
2014-06-18 23:07:09 +03:00
|
|
|
int fontheight = gmenu2x->font->getLineSpacing();
|
2014-01-16 16:49:51 +02:00
|
|
|
unsigned int nb_elements = height / fontheight;
|
|
|
|
|
2010-02-04 13:33:47 +02:00
|
|
|
while (!close) {
|
2014-01-16 16:49:51 +02:00
|
|
|
if (selected > firstElement + nb_elements - 1)
|
|
|
|
firstElement = selected - nb_elements + 1;
|
|
|
|
if (selected < firstElement)
|
|
|
|
firstElement = selected;
|
2010-02-04 13:33:47 +02:00
|
|
|
|
|
|
|
//Wallpaper
|
2011-04-12 11:18:10 +03:00
|
|
|
gmenu2x->sc[((string)"skin:wallpapers/" + wallpapers[selected]).c_str()]->blit(gmenu2x->s, 0, 0);
|
2010-02-04 13:33:47 +02:00
|
|
|
|
|
|
|
gmenu2x->drawTopBar(gmenu2x->s);
|
|
|
|
gmenu2x->drawBottomBar(gmenu2x->s);
|
|
|
|
|
2010-05-05 15:35:52 +03:00
|
|
|
drawTitleIcon("icons/wallpaper.png",true);
|
2014-06-12 23:37:08 +03:00
|
|
|
writeTitle(gmenu2x->tr["Wallpaper selection"]);
|
|
|
|
writeSubTitle(gmenu2x->tr["Select a wallpaper from the list"]);
|
2010-02-04 13:33:47 +02:00
|
|
|
|
2014-01-16 02:03:15 +02:00
|
|
|
buttonbox.paint(gmenu2x->s, 5);
|
2010-02-04 13:33:47 +02:00
|
|
|
|
|
|
|
//Selection
|
2014-01-16 16:49:51 +02:00
|
|
|
iY = selected - firstElement;
|
|
|
|
iY = top + (iY * fontheight);
|
|
|
|
gmenu2x->s->box(2, iY, 308, fontheight, gmenu2x->skinConfColors[COLOR_SELECTION_BG]);
|
2010-02-04 13:33:47 +02:00
|
|
|
|
|
|
|
//Files & Directories
|
2014-01-16 16:49:51 +02:00
|
|
|
gmenu2x->s->setClipRect(0, top, 311, height);
|
|
|
|
for (i = firstElement; i < wallpapers.size()
|
|
|
|
&& i < firstElement + nb_elements; i++) {
|
2010-02-04 13:33:47 +02:00
|
|
|
iY = i-firstElement;
|
2014-01-16 16:49:51 +02:00
|
|
|
gmenu2x->s->write(gmenu2x->font, wallpapers[i], 5,
|
|
|
|
top + (iY * fontheight),
|
|
|
|
Font::HAlignLeft, Font::VAlignTop);
|
2010-02-04 13:33:47 +02:00
|
|
|
}
|
|
|
|
gmenu2x->s->clearClipRect();
|
|
|
|
|
2014-01-16 16:49:51 +02:00
|
|
|
gmenu2x->drawScrollBar(nb_elements, wallpapers.size(), firstElement);
|
2010-02-04 13:33:47 +02:00
|
|
|
gmenu2x->s->flip();
|
|
|
|
|
2010-09-17 23:34:26 +03:00
|
|
|
switch(gmenu2x->input.waitForPressedButton()) {
|
2011-10-23 09:57:52 +03:00
|
|
|
case InputManager::CANCEL:
|
2010-09-17 23:34:26 +03:00
|
|
|
close = true;
|
|
|
|
result = false;
|
|
|
|
break;
|
2011-10-23 09:57:52 +03:00
|
|
|
case InputManager::UP:
|
2010-09-17 23:34:26 +03:00
|
|
|
if (selected == 0) selected = wallpapers.size()-1;
|
|
|
|
else selected -= 1;
|
|
|
|
break;
|
2011-10-23 09:57:52 +03:00
|
|
|
case InputManager::ALTLEFT:
|
2014-01-16 16:49:51 +02:00
|
|
|
if ((int)(selected - nb_elements + 1) < 0)
|
|
|
|
selected = 0;
|
|
|
|
else
|
|
|
|
selected -= nb_elements - 1;
|
2010-09-17 23:34:26 +03:00
|
|
|
break;
|
2011-10-23 09:57:52 +03:00
|
|
|
case InputManager::DOWN:
|
2010-09-17 23:34:26 +03:00
|
|
|
if (selected+1 >= wallpapers.size()) selected = 0;
|
|
|
|
else selected += 1;
|
|
|
|
break;
|
2011-10-23 09:57:52 +03:00
|
|
|
case InputManager::ALTRIGHT:
|
2014-01-16 16:49:51 +02:00
|
|
|
if (selected + nb_elements - 1 >= wallpapers.size())
|
|
|
|
selected = wallpapers.size() - 1;
|
|
|
|
else
|
|
|
|
selected += nb_elements - 1;
|
2010-09-17 23:34:26 +03:00
|
|
|
break;
|
2011-10-23 09:57:52 +03:00
|
|
|
case InputManager::ACCEPT:
|
2010-09-17 23:34:26 +03:00
|
|
|
close = true;
|
2011-04-12 11:18:10 +03:00
|
|
|
if (wallpapers.size() > 0)
|
|
|
|
wallpaper = gmenu2x->sc.getSkinFilePath("wallpapers/" + wallpapers[selected]);
|
|
|
|
else result = false;
|
2010-09-17 23:34:26 +03:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2010-02-04 13:33:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
for (uint i=0; i<wallpapers.size(); i++)
|
2011-04-12 11:18:10 +03:00
|
|
|
gmenu2x->sc.del("skin:wallpapers/" + wallpapers[i]);
|
2010-02-04 13:33:47 +02:00
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|