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 "textmanualdialog.h"
|
|
|
|
|
2011-10-23 17:13:02 +03:00
|
|
|
#include "gmenu2x.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
|
|
|
|
2011-10-23 18:00:23 +03:00
|
|
|
#include <algorithm>
|
2011-10-23 17:13:02 +03:00
|
|
|
#include <sstream>
|
|
|
|
|
2010-02-04 13:33:47 +02:00
|
|
|
using namespace std;
|
|
|
|
|
2014-07-24 04:36:01 +03:00
|
|
|
TextManualDialog::TextManualDialog(GMenu2X *gmenu2x, const string &title, const string &icon, const string &text)
|
2010-02-04 13:33:47 +02:00
|
|
|
: TextDialog(gmenu2x,title,"",icon,text) {
|
|
|
|
|
|
|
|
//split the text in multiple pages
|
2014-07-24 04:36:01 +03:00
|
|
|
for (uint i=0; i<this->text.size(); i++) {
|
|
|
|
string line = trim(this->text.at(i));
|
2010-02-04 13:33:47 +02:00
|
|
|
if (line[0]=='[' && line[line.length()-1]==']') {
|
|
|
|
ManualPage mp;
|
|
|
|
mp.title = line.substr(1,line.length()-2);
|
|
|
|
pages.push_back(mp);
|
|
|
|
} else {
|
|
|
|
if (pages.size()==0) {
|
|
|
|
ManualPage mp;
|
|
|
|
mp.title = gmenu2x->tr["Untitled"];
|
|
|
|
pages.push_back(mp);
|
|
|
|
}
|
2014-07-24 04:36:01 +03:00
|
|
|
pages[pages.size()-1].text.push_back(this->text.at(i));
|
2010-02-04 13:33:47 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (pages.size()==0) {
|
|
|
|
ManualPage mp;
|
|
|
|
mp.title = gmenu2x->tr["Untitled"];
|
|
|
|
pages.push_back(mp);
|
|
|
|
}
|
|
|
|
|
|
|
|
//delete first and last blank lines from each page
|
|
|
|
for (uint page=0; page<pages.size(); page++) {
|
|
|
|
if (pages[page].text.size() > 0) {
|
|
|
|
//first lines
|
2013-08-16 10:16:04 +03:00
|
|
|
while (trim(pages[page].text[0]).empty())
|
2010-02-04 13:33:47 +02:00
|
|
|
pages[page].text.erase(pages[page].text.begin());
|
|
|
|
//last lines
|
2013-08-16 10:16:04 +03:00
|
|
|
while (trim(pages[page].text[pages[page].text.size()-1]).empty())
|
2010-02-04 13:33:47 +02:00
|
|
|
pages[page].text.erase(pages[page].text.end());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void TextManualDialog::exec() {
|
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+(description.empty() ? "" : ": "+description));
|
2010-02-04 13:33:47 +02:00
|
|
|
|
2014-08-10 05:26:59 +03:00
|
|
|
gmenu2x->drawButton(bg, "start", gmenu2x->tr["Exit"],
|
|
|
|
gmenu2x->drawButton(bg, "cancel", "",
|
|
|
|
gmenu2x->drawButton(bg, "right", gmenu2x->tr["Change page"],
|
|
|
|
gmenu2x->drawButton(bg, "left", "",
|
|
|
|
gmenu2x->drawButton(bg, "down", gmenu2x->tr["Scroll"],
|
2014-08-15 19:41:17 +03:00
|
|
|
gmenu2x->drawButton(bg, "up", "", 5))))));
|
2010-02-04 13:33:47 +02:00
|
|
|
|
2011-06-03 12:46:36 +03:00
|
|
|
bg.convertToDisplayFormat();
|
|
|
|
|
2010-02-04 13:33:47 +02:00
|
|
|
stringstream ss;
|
|
|
|
ss << pages.size();
|
|
|
|
string spagecount;
|
|
|
|
ss >> spagecount;
|
|
|
|
string pageStatus;
|
2011-10-23 09:57:52 +03:00
|
|
|
|
2014-08-10 07:56:00 +03:00
|
|
|
const int fontHeight = gmenu2x->font->getLineSpacing();
|
|
|
|
unsigned int contentY, contentHeight;
|
|
|
|
tie(contentY, contentHeight) = gmenu2x->getContentArea();
|
|
|
|
const unsigned rowsPerPage = max(contentHeight / fontHeight, 1u);
|
|
|
|
contentY += (contentHeight % fontHeight) / 2;
|
2014-08-10 11:09:42 +03:00
|
|
|
|
|
|
|
unsigned page = 0, firstRow = 0;
|
|
|
|
bool close = false;
|
|
|
|
|
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);
|
|
|
|
writeSubTitle(s, pages[page].title);
|
2014-08-10 07:56:00 +03:00
|
|
|
drawText(pages[page].text, contentY, firstRow, rowsPerPage);
|
2010-02-04 13:33:47 +02:00
|
|
|
|
|
|
|
ss.clear();
|
|
|
|
ss << page+1;
|
|
|
|
ss >> pageStatus;
|
|
|
|
pageStatus = gmenu2x->tr["Page"]+": "+pageStatus+"/"+spagecount;
|
2014-08-10 05:26:59 +03:00
|
|
|
gmenu2x->font->write(s, pageStatus, 310, 230, Font::HAlignRight, Font::VAlignMiddle);
|
2010-02-04 13:33:47 +02:00
|
|
|
|
2014-08-10 05:26:59 +03:00
|
|
|
s.flip();
|
2010-02-04 13:33:47 +02:00
|
|
|
|
2014-08-10 11:09:42 +03:00
|
|
|
const unsigned maxFirstRow = pages[page].text.size() < rowsPerPage
|
|
|
|
? 0 : pages[page].text.size() - rowsPerPage;
|
|
|
|
|
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::LEFT:
|
|
|
|
if (page > 0) {
|
|
|
|
page--;
|
|
|
|
firstRow = 0;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case InputManager::RIGHT:
|
|
|
|
if (page < pages.size() -1) {
|
|
|
|
page++;
|
|
|
|
firstRow = 0;
|
|
|
|
}
|
|
|
|
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::CANCEL:
|
|
|
|
case InputManager::SETTINGS:
|
|
|
|
close = true;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
2010-02-04 13:33:47 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|