2010-02-04 13:33:47 +02:00
|
|
|
/***************************************************************************
|
2011-10-23 18:00:23 +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 "textdialog.h"
|
|
|
|
|
2011-10-23 17:13:02 +03:00
|
|
|
#include "gmenu2x.h"
|
2011-10-23 18:27:29 +03:00
|
|
|
#include "utilities.h"
|
2011-10-23 17:13:02 +03:00
|
|
|
|
2014-08-10 11:09:42 +03:00
|
|
|
#include <algorithm>
|
|
|
|
|
2010-02-04 13:33:47 +02:00
|
|
|
using namespace std;
|
|
|
|
|
2014-07-24 04:36:01 +03:00
|
|
|
TextDialog::TextDialog(GMenu2X *gmenu2x, const string &title, const string &description, const string &icon, const string &text)
|
2010-05-05 15:35:52 +03:00
|
|
|
: Dialog(gmenu2x)
|
|
|
|
{
|
2014-07-24 04:36:01 +03:00
|
|
|
split(this->text, gmenu2x->font->wordWrap(text, (int) gmenu2x->resX - 15), "\n");
|
2010-02-04 13:33:47 +02:00
|
|
|
this->title = title;
|
|
|
|
this->description = description;
|
|
|
|
this->icon = icon;
|
|
|
|
}
|
|
|
|
|
2014-07-24 04:36:01 +03:00
|
|
|
void TextDialog::drawText(const vector<string> &text, unsigned int y,
|
2013-08-14 14:25:07 +03:00
|
|
|
unsigned int firstRow, unsigned int rowsPerPage)
|
|
|
|
{
|
2014-08-10 05:26:59 +03:00
|
|
|
Surface& s = *gmenu2x->s;
|
2014-06-18 23:07:09 +03:00
|
|
|
const int fontHeight = gmenu2x->font->getLineSpacing();
|
2013-08-14 14:25:07 +03:00
|
|
|
|
2014-07-24 04:36:01 +03:00
|
|
|
for (unsigned i = firstRow; i < firstRow + rowsPerPage && i < text.size(); i++) {
|
|
|
|
const string &line = text.at(i);
|
2013-08-14 14:25:07 +03:00
|
|
|
int rowY = y + (i - firstRow) * fontHeight;
|
|
|
|
if (line == "----") { // horizontal ruler
|
|
|
|
rowY += fontHeight / 2;
|
2014-08-10 05:26:59 +03:00
|
|
|
s.box(5, rowY, gmenu2x->resX - 16, 1, 255, 255, 255, 130);
|
|
|
|
s.box(5, rowY+1, gmenu2x->resX - 16, 1, 0, 0, 0, 130);
|
2010-02-04 13:33:47 +02:00
|
|
|
} else {
|
2014-08-10 05:26:59 +03:00
|
|
|
gmenu2x->font->write(s, line, 5, rowY);
|
2010-02-04 13:33:47 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-24 04:36:01 +03:00
|
|
|
gmenu2x->drawScrollBar(rowsPerPage, text.size(), firstRow);
|
2010-02-04 13:33:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void TextDialog::exec() {
|
|
|
|
bool close = false;
|
|
|
|
|
2014-08-10 15:21:14 +03:00
|
|
|
OffscreenSurface bg(*gmenu2x->bg);
|
2010-02-04 13:33:47 +02:00
|
|
|
|
|
|
|
//link icon
|
|
|
|
if (!fileExists(icon))
|
2014-08-10 05:26:59 +03:00
|
|
|
drawTitleIcon(bg, "icons/ebook.png", true);
|
2010-02-04 13:33:47 +02:00
|
|
|
else
|
2014-08-10 05:26:59 +03:00
|
|
|
drawTitleIcon(bg, icon, false);
|
|
|
|
writeTitle(bg, title);
|
|
|
|
writeSubTitle(bg, description);
|
2010-02-04 13:33:47 +02:00
|
|
|
|
2014-08-16 01:23:57 +03:00
|
|
|
int x = 5;
|
|
|
|
x = gmenu2x->drawButton(bg, "up", "", x);
|
|
|
|
x = gmenu2x->drawButton(bg, "down", gmenu2x->tr["Scroll"], x);
|
|
|
|
x = gmenu2x->drawButton(bg, "cancel", "", x);
|
|
|
|
x = gmenu2x->drawButton(bg, "start", gmenu2x->tr["Exit"], x);
|
2010-02-04 13:33:47 +02:00
|
|
|
|
2011-06-03 12:46:36 +03:00
|
|
|
bg.convertToDisplayFormat();
|
|
|
|
|
2014-06-18 23:07:09 +03:00
|
|
|
const int fontHeight = gmenu2x->font->getLineSpacing();
|
2013-08-14 14:25:07 +03:00
|
|
|
unsigned int contentY, contentHeight;
|
|
|
|
tie(contentY, contentHeight) = gmenu2x->getContentArea();
|
2014-08-10 11:17:01 +03:00
|
|
|
const unsigned rowsPerPage = max(contentHeight / fontHeight, 1u);
|
2014-08-10 11:09:42 +03:00
|
|
|
const unsigned maxFirstRow =
|
|
|
|
text.size() < rowsPerPage ? 0 : text.size() - rowsPerPage;
|
2013-08-14 14:25:07 +03:00
|
|
|
contentY += (contentHeight % fontHeight) / 2;
|
|
|
|
|
2011-10-23 17:13:02 +03:00
|
|
|
unsigned firstRow = 0;
|
2010-02-04 13:33:47 +02:00
|
|
|
while (!close) {
|
2014-08-10 14:25:54 +03:00
|
|
|
OutputSurface& s = *gmenu2x->s;
|
2014-08-10 05:26:59 +03:00
|
|
|
|
|
|
|
bg.blit(s, 0, 0);
|
2013-08-14 14:25:07 +03:00
|
|
|
drawText(text, contentY, firstRow, rowsPerPage);
|
2014-08-10 05:26:59 +03:00
|
|
|
s.flip();
|
2010-02-04 13:33:47 +02:00
|
|
|
|
2011-10-23 09:57:52 +03:00
|
|
|
switch(gmenu2x->input.waitForPressedButton()) {
|
|
|
|
case InputManager::UP:
|
|
|
|
if (firstRow > 0) firstRow--;
|
|
|
|
break;
|
|
|
|
case InputManager::DOWN:
|
2014-08-10 11:09:42 +03:00
|
|
|
if (firstRow < maxFirstRow) firstRow++;
|
2011-10-23 09:57:52 +03:00
|
|
|
break;
|
|
|
|
case InputManager::ALTLEFT:
|
2014-08-10 11:09:42 +03:00
|
|
|
if (firstRow >= rowsPerPage - 1) firstRow -= rowsPerPage - 1;
|
2011-10-23 09:57:52 +03:00
|
|
|
else firstRow = 0;
|
|
|
|
break;
|
|
|
|
case InputManager::ALTRIGHT:
|
2014-08-10 11:09:42 +03:00
|
|
|
firstRow = min(firstRow + rowsPerPage - 1, maxFirstRow);
|
2011-10-23 09:57:52 +03:00
|
|
|
break;
|
|
|
|
case InputManager::SETTINGS:
|
|
|
|
case InputManager::CANCEL:
|
|
|
|
close = true;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
2010-02-04 13:33:47 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|