diff --git a/src/textdialog.cpp b/src/textdialog.cpp index 46a45a3..c4f1d19 100644 --- a/src/textdialog.cpp +++ b/src/textdialog.cpp @@ -77,23 +77,23 @@ void TextDialog::preProcess() { } } -void TextDialog::drawText(vector *text, unsigned firstRow, - unsigned rowsPerPage) { - gmenu2x->s->setClipRect(0,41,gmenu2x->resX-10,gmenu2x->resY-60); +void TextDialog::drawText(vector *text, unsigned int y, + unsigned int firstRow, unsigned int rowsPerPage) +{ + const int fontHeight = gmenu2x->font->getHeight(); - for (unsigned i=firstRow; isize(); i++) { - int rowY; - if (text->at(i)=="----") { //draw a line - rowY = 42+(int)((i-firstRow+0.5)*gmenu2x->font->getHeight()); - gmenu2x->s->hline(5,rowY,gmenu2x->resX-16,255,255,255,130); - gmenu2x->s->hline(5,rowY+1,gmenu2x->resX-16,0,0,0,130); + for (unsigned i = firstRow; i < firstRow + rowsPerPage && i < text->size(); i++) { + const string &line = text->at(i); + int rowY = y + (i - firstRow) * fontHeight; + if (line == "----") { // horizontal ruler + rowY += fontHeight / 2; + gmenu2x->s->hline(5, rowY, gmenu2x->resX - 16, 255, 255, 255, 130); + gmenu2x->s->hline(5, rowY+1, gmenu2x->resX - 16, 0, 0, 0, 130); } else { - rowY = 42+(i-firstRow)*gmenu2x->font->getHeight(); - gmenu2x->font->write(gmenu2x->s, text->at(i), 5, rowY); + gmenu2x->font->write(gmenu2x->s, line, 5, rowY); } } - gmenu2x->s->clearClipRect(); gmenu2x->drawScrollBar(rowsPerPage, text->size(), firstRow); } @@ -117,11 +117,16 @@ void TextDialog::exec() { bg.convertToDisplayFormat(); + const int fontHeight = gmenu2x->font->getHeight(); + unsigned int contentY, contentHeight; + tie(contentY, contentHeight) = gmenu2x->getContentArea(); + const unsigned rowsPerPage = contentHeight / fontHeight; + contentY += (contentHeight % fontHeight) / 2; + unsigned firstRow = 0; - unsigned rowsPerPage = (gmenu2x->resY - 60) / gmenu2x->font->getHeight(); while (!close) { bg.blit(gmenu2x->s, 0, 0); - drawText(text, firstRow, rowsPerPage); + drawText(text, contentY, firstRow, rowsPerPage); gmenu2x->s->flip(); switch(gmenu2x->input.waitForPressedButton()) { diff --git a/src/textdialog.h b/src/textdialog.h index 7eb798f..4ede7b2 100644 --- a/src/textdialog.h +++ b/src/textdialog.h @@ -32,8 +32,8 @@ protected: std::string title, description, icon; void preProcess(); - void drawText(std::vector *text, unsigned firstRow, - unsigned rowsPerPage); + void drawText(std::vector *text, unsigned int y, + unsigned int firstRow, unsigned int rowsPerPage); public: TextDialog(GMenu2X *gmenu2x, const std::string &title, diff --git a/src/textmanualdialog.cpp b/src/textmanualdialog.cpp index 539e975..b662e4b 100644 --- a/src/textmanualdialog.cpp +++ b/src/textmanualdialog.cpp @@ -99,7 +99,7 @@ void TextManualDialog::exec() { while (!close) { bg.blit(gmenu2x->s,0,0); writeSubTitle(pages[page].title); - drawText(&pages[page].text, firstRow, rowsPerPage); + drawText(&pages[page].text, 42 /* TODO */, firstRow, rowsPerPage); ss.clear(); ss << page+1;