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. *
|
|
|
|
***************************************************************************/
|
|
|
|
|
2011-10-23 17:13:02 +03:00
|
|
|
#include "settingsdialog.h"
|
|
|
|
|
|
|
|
#include "gmenu2x.h"
|
|
|
|
#include "menusetting.h"
|
|
|
|
|
2010-02-04 13:33:47 +02:00
|
|
|
#include <SDL.h>
|
|
|
|
#include <SDL_gfxPrimitives.h>
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
2010-07-28 00:09:16 +03:00
|
|
|
SettingsDialog::SettingsDialog(
|
|
|
|
GMenu2X *gmenu2x_, InputManager &inputMgr_, Touchscreen &ts_,
|
|
|
|
const string &text_, const string &icon)
|
|
|
|
: Dialog(gmenu2x_)
|
|
|
|
, inputMgr(inputMgr_)
|
|
|
|
, ts(ts_)
|
|
|
|
, text(text_)
|
2010-05-05 15:35:52 +03:00
|
|
|
{
|
2012-04-10 23:07:43 +03:00
|
|
|
if (icon != "" && gmenu2x->sc[icon] != NULL) {
|
2010-02-04 13:33:47 +02:00
|
|
|
this->icon = icon;
|
2012-04-10 23:07:43 +03:00
|
|
|
} else {
|
2010-02-04 13:33:47 +02:00
|
|
|
this->icon = "icons/generic.png";
|
2012-04-10 23:07:43 +03:00
|
|
|
}
|
2010-02-04 13:33:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
SettingsDialog::~SettingsDialog() {
|
2012-04-10 23:07:43 +03:00
|
|
|
for (vector<MenuSetting *>::iterator it = voices.begin();
|
|
|
|
it != voices.end(); ++it) {
|
2011-07-20 14:43:25 +03:00
|
|
|
delete *it;
|
2012-04-10 23:07:43 +03:00
|
|
|
}
|
2010-02-04 13:33:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool SettingsDialog::exec() {
|
|
|
|
Surface bg(gmenu2x->bg);
|
2011-06-03 12:46:36 +03:00
|
|
|
bg.convertToDisplayFormat();
|
2010-02-04 13:33:47 +02:00
|
|
|
|
|
|
|
bool close = false, ts_pressed = false;
|
2012-04-10 23:07:43 +03:00
|
|
|
uint i, sel = 0, firstElement = 0;
|
2010-02-04 13:33:47 +02:00
|
|
|
|
2012-04-10 23:07:43 +03:00
|
|
|
const int topBarHeight = gmenu2x->skinConfInt["topBarHeight"];
|
2012-04-11 00:01:16 +03:00
|
|
|
SDL_Rect clipRect = {
|
|
|
|
0,
|
|
|
|
static_cast<Sint16>(topBarHeight + 1),
|
|
|
|
static_cast<Uint16>(gmenu2x->resX - 9),
|
|
|
|
static_cast<Uint16>(gmenu2x->resY - topBarHeight - 25)
|
|
|
|
};
|
|
|
|
SDL_Rect touchRect = {
|
|
|
|
2,
|
|
|
|
static_cast<Sint16>(topBarHeight + 4),
|
|
|
|
static_cast<Uint16>(gmenu2x->resX - 12),
|
|
|
|
static_cast<Uint16>(clipRect.h)
|
|
|
|
};
|
2012-04-10 23:07:43 +03:00
|
|
|
uint rowHeight = gmenu2x->font->getHeight() + 1; // gp2x=15+1 / pandora=19+1
|
|
|
|
uint numRows = (gmenu2x->resY - topBarHeight - 20) / rowHeight;
|
2010-02-04 13:33:47 +02:00
|
|
|
|
|
|
|
while (!close) {
|
2011-12-23 13:30:15 +02:00
|
|
|
if (ts.available()) ts.poll();
|
2010-02-04 13:33:47 +02:00
|
|
|
|
|
|
|
bg.blit(gmenu2x->s,0,0);
|
|
|
|
|
|
|
|
gmenu2x->drawTopBar(gmenu2x->s);
|
|
|
|
//link icon
|
2010-05-05 15:35:52 +03:00
|
|
|
drawTitleIcon(icon);
|
|
|
|
writeTitle(text);
|
|
|
|
|
2010-02-04 13:33:47 +02:00
|
|
|
gmenu2x->drawBottomBar(gmenu2x->s);
|
|
|
|
|
|
|
|
if (sel>firstElement+numRows-1) firstElement=sel-numRows+1;
|
|
|
|
if (sel<firstElement) firstElement=sel;
|
|
|
|
|
|
|
|
//selection
|
2012-04-10 23:07:43 +03:00
|
|
|
uint iY = topBarHeight + 2 + (sel - firstElement) * rowHeight;
|
2010-02-04 13:33:47 +02:00
|
|
|
gmenu2x->s->setClipRect(clipRect);
|
2012-04-10 23:07:43 +03:00
|
|
|
if (sel<voices.size()) {
|
|
|
|
gmenu2x->s->box(
|
|
|
|
1, iY, 148, rowHeight - 2,
|
|
|
|
gmenu2x->skinConfColors[COLOR_SELECTION_BG]
|
|
|
|
);
|
|
|
|
}
|
2010-02-04 13:33:47 +02:00
|
|
|
gmenu2x->s->clearClipRect();
|
|
|
|
|
|
|
|
//selected option
|
|
|
|
voices[sel]->drawSelected(iY);
|
|
|
|
|
|
|
|
gmenu2x->s->setClipRect(clipRect);
|
2012-04-10 23:07:43 +03:00
|
|
|
if (ts_pressed && !ts.pressed()) {
|
|
|
|
ts_pressed = false;
|
|
|
|
}
|
|
|
|
if (ts.available() && ts.pressed() && !ts.inRect(touchRect)) {
|
|
|
|
ts_pressed = false;
|
|
|
|
}
|
2010-02-04 13:33:47 +02:00
|
|
|
for (i=firstElement; i<voices.size() && i<firstElement+numRows; i++) {
|
|
|
|
iY = i-firstElement;
|
2012-04-10 23:07:43 +03:00
|
|
|
voices[i]->draw(iY * rowHeight + topBarHeight + 2);
|
|
|
|
if (ts.available() && ts.pressed() && ts.inRect(
|
|
|
|
touchRect.x, touchRect.y + (iY * rowHeight),
|
|
|
|
touchRect.w, rowHeight
|
|
|
|
)) {
|
2010-02-04 13:33:47 +02:00
|
|
|
ts_pressed = true;
|
|
|
|
sel = i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
gmenu2x->s->clearClipRect();
|
|
|
|
|
2013-08-14 11:49:09 +03:00
|
|
|
gmenu2x->drawScrollBar(numRows, voices.size(), firstElement);
|
2010-02-04 13:33:47 +02:00
|
|
|
|
|
|
|
//description
|
2010-07-27 22:01:52 +03:00
|
|
|
writeSubTitle(voices[sel]->getDescription());
|
2010-02-04 13:33:47 +02:00
|
|
|
|
|
|
|
gmenu2x->s->flip();
|
|
|
|
voices[sel]->handleTS();
|
|
|
|
|
2011-10-23 10:38:59 +03:00
|
|
|
InputManager::Button button = inputMgr.waitForPressedButton();
|
|
|
|
if (!voices[sel]->handleButtonPress(button)) {
|
|
|
|
switch (button) {
|
2011-10-23 09:57:52 +03:00
|
|
|
case InputManager::SETTINGS:
|
2011-09-15 21:20:35 +03:00
|
|
|
close = true;
|
|
|
|
break;
|
2011-10-23 09:57:52 +03:00
|
|
|
case InputManager::UP:
|
2012-04-10 23:07:43 +03:00
|
|
|
if (sel == 0) {
|
|
|
|
sel = voices.size() - 1;
|
|
|
|
} else {
|
2011-09-15 21:20:35 +03:00
|
|
|
sel -= 1;
|
2012-04-10 23:07:43 +03:00
|
|
|
}
|
2011-09-15 21:20:35 +03:00
|
|
|
gmenu2x->setInputSpeed();
|
|
|
|
break;
|
2011-10-23 09:57:52 +03:00
|
|
|
case InputManager::DOWN:
|
2011-09-15 21:20:35 +03:00
|
|
|
sel += 1;
|
|
|
|
if (sel>=voices.size()) sel = 0;
|
|
|
|
gmenu2x->setInputSpeed();
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2010-02-04 13:33:47 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
gmenu2x->setInputSpeed();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-04-10 23:07:43 +03:00
|
|
|
void SettingsDialog::addSetting(MenuSetting *set) {
|
2010-02-04 13:33:47 +02:00
|
|
|
voices.push_back(set);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool SettingsDialog::edited() {
|
2012-04-10 23:07:43 +03:00
|
|
|
for (uint i=0; i < voices.size(); i++) {
|
2010-02-04 13:33:47 +02:00
|
|
|
if (voices[i]->edited()) return true;
|
2012-04-10 23:07:43 +03:00
|
|
|
}
|
2010-02-04 13:33:47 +02:00
|
|
|
return false;
|
|
|
|
}
|