1
0
mirror of git://projects.qi-hardware.com/gmenu2x.git synced 2024-11-22 06:07:30 +02:00

Rewrote the manual paging code

Nebuleon spotted a bug in TextManualDialog where the unsigned value
'pages[page].text.size() - rowsPerPage' could wrap around at 0 for
short chapters. I decided to change a bit more than just fixing the
bug though.
This commit is contained in:
Maarten ter Huurne 2014-08-10 10:09:42 +02:00
parent 799ebb9a29
commit 0535f8273b
2 changed files with 18 additions and 16 deletions

View File

@ -23,6 +23,8 @@
#include "gmenu2x.h"
#include "utilities.h"
#include <algorithm>
using namespace std;
TextDialog::TextDialog(GMenu2X *gmenu2x, const string &title, const string &description, const string &icon, const string &text)
@ -79,6 +81,8 @@ void TextDialog::exec() {
unsigned int contentY, contentHeight;
tie(contentY, contentHeight) = gmenu2x->getContentArea();
const unsigned rowsPerPage = contentHeight / fontHeight;
const unsigned maxFirstRow =
text.size() < rowsPerPage ? 0 : text.size() - rowsPerPage;
contentY += (contentHeight % fontHeight) / 2;
unsigned firstRow = 0;
@ -94,19 +98,14 @@ void TextDialog::exec() {
if (firstRow > 0) firstRow--;
break;
case InputManager::DOWN:
if (firstRow + rowsPerPage < text.size()) firstRow++;
if (firstRow < maxFirstRow) firstRow++;
break;
case InputManager::ALTLEFT:
if (firstRow >= rowsPerPage-1) firstRow -= rowsPerPage-1;
if (firstRow >= rowsPerPage - 1) firstRow -= rowsPerPage - 1;
else firstRow = 0;
break;
case InputManager::ALTRIGHT:
if (firstRow + rowsPerPage*2 -1 < text.size()) {
firstRow += rowsPerPage-1;
} else {
firstRow = text.size() < rowsPerPage ?
0 : text.size() - rowsPerPage;
}
firstRow = min(firstRow + rowsPerPage - 1, maxFirstRow);
break;
case InputManager::SETTINGS:
case InputManager::CANCEL:

View File

@ -68,9 +68,6 @@ TextManualDialog::TextManualDialog(GMenu2X *gmenu2x, const string &title, const
}
void TextManualDialog::exec() {
bool close = false;
uint page=0;
Surface bg(gmenu2x->bg);
//link icon
@ -89,13 +86,17 @@ void TextManualDialog::exec() {
bg.convertToDisplayFormat();
uint firstRow = 0, rowsPerPage = 180/gmenu2x->font->getLineSpacing();
stringstream ss;
ss << pages.size();
string spagecount;
ss >> spagecount;
string pageStatus;
const unsigned rowsPerPage = 180 / gmenu2x->font->getLineSpacing();
unsigned page = 0, firstRow = 0;
bool close = false;
while (!close) {
Surface& s = *gmenu2x->s;
@ -111,12 +112,15 @@ void TextManualDialog::exec() {
s.flip();
const unsigned maxFirstRow = pages[page].text.size() < rowsPerPage
? 0 : pages[page].text.size() - rowsPerPage;
switch(gmenu2x->input.waitForPressedButton()) {
case InputManager::UP:
if (firstRow > 0) firstRow--;
break;
case InputManager::DOWN:
if (firstRow + rowsPerPage < pages[page].text.size()) firstRow++;
if (firstRow < maxFirstRow) firstRow++;
break;
case InputManager::LEFT:
if (page > 0) {
@ -131,12 +135,11 @@ void TextManualDialog::exec() {
}
break;
case InputManager::ALTLEFT:
if (firstRow >= rowsPerPage-1) firstRow -= rowsPerPage-1;
if (firstRow >= rowsPerPage - 1) firstRow -= rowsPerPage - 1;
else firstRow = 0;
break;
case InputManager::ALTRIGHT:
if (firstRow + rowsPerPage*2 -1 < pages[page].text.size()) firstRow += rowsPerPage-1;
else firstRow = max(0ul, (unsigned long) (pages[page].text.size() - rowsPerPage));
firstRow = min(firstRow + rowsPerPage - 1, maxFirstRow);
break;
case InputManager::CANCEL:
case InputManager::SETTINGS: