From c6c4eef4e49bb4de90845408af9f642a1a4e224b Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Fri, 17 Aug 2012 16:34:36 +0300 Subject: Improve size calculations. --- src/gui/widgets/browserbox.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'src/gui/widgets/browserbox.cpp') diff --git a/src/gui/widgets/browserbox.cpp b/src/gui/widgets/browserbox.cpp index 534bd1d19..cf2a9ea88 100644 --- a/src/gui/widgets/browserbox.cpp +++ b/src/gui/widgets/browserbox.cpp @@ -120,6 +120,7 @@ void BrowserBox::addRow(const std::string &row, bool atTop) // Check for links in format "@@link|Caption@@" idx1 = tmp.find("@@"); + const int sz = static_cast(mTextRows.size()); while (idx1 != std::string::npos) { size_t idx2 = tmp.find("|", idx1); @@ -129,7 +130,7 @@ void BrowserBox::addRow(const std::string &row, bool atTop) break; bLink.link = tmp.substr(idx1 + 2, idx2 - (idx1 + 2)); bLink.caption = tmp.substr(idx2 + 1, idx3 - (idx2 + 1)); - bLink.y1 = static_cast(mTextRows.size()) * font->getHeight(); + bLink.y1 = sz * font->getHeight(); bLink.y2 = bLink.y1 + font->getHeight(); newRow += tmp.substr(0, idx1); @@ -224,19 +225,19 @@ void BrowserBox::addRow(const std::string &row, bool atTop) i != i_end; ++ i) { std::string tempRow = *i; - for (unsigned int j = 0; j < tempRow.size(); j++) + for (unsigned int j = 0, sz = tempRow.size(); j < sz; j++) { std::string character = tempRow.substr(j, 1); x += font->getWidth(character); nextChar = j + 1; // Wraping between words (at blank spaces) - if (nextChar < tempRow.size() && tempRow.at(nextChar) == ' ') + if (nextChar < sz && tempRow.at(nextChar) == ' ') { int nextSpacePos = static_cast( tempRow.find(" ", (nextChar + 1))); if (nextSpacePos <= 0) - nextSpacePos = static_cast(tempRow.size()) - 1; + nextSpacePos = static_cast(sz) - 1; unsigned nextWordWidth = font->getWidth( tempRow.substr(nextChar, -- cgit v1.2.3-70-g09d2