summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2012-04-07 17:53:50 +0300
committerAndrei Karas <akaras@inbox.ru>2012-04-07 17:53:50 +0300
commit5fdcc0aa69967ec46375c3734f038aee80a264f8 (patch)
tree94977c5ec14216e732ff81f8c03f4aa9f9bb091e
parent631c4390274133697ab57437f8bef13a946aa3b7 (diff)
downloadmanaplus-5fdcc0aa69967ec46375c3734f038aee80a264f8.tar.gz
manaplus-5fdcc0aa69967ec46375c3734f038aee80a264f8.tar.bz2
manaplus-5fdcc0aa69967ec46375c3734f038aee80a264f8.tar.xz
manaplus-5fdcc0aa69967ec46375c3734f038aee80a264f8.zip
Change implimentation for removeing old links from browser box class.
-rw-r--r--src/gui/widgets/browserbox.cpp44
-rw-r--r--src/gui/widgets/browserbox.h1
2 files changed, 17 insertions, 28 deletions
diff --git a/src/gui/widgets/browserbox.cpp b/src/gui/widgets/browserbox.cpp
index be04b99aa..8cbeec78c 100644
--- a/src/gui/widgets/browserbox.cpp
+++ b/src/gui/widgets/browserbox.cpp
@@ -107,6 +107,7 @@ void BrowserBox::addRow(const std::string &row, bool atTop)
std::string newRow;
size_t idx1;
gcn::Font *font = getFont();
+ int linksCount = 0;
if (getWidth() < 0)
return;
@@ -143,6 +144,7 @@ void BrowserBox::addRow(const std::string &row, bool atTop)
bLink.x2 = bLink.x1 + font->getWidth(bLink.caption) + 1;
mLinks.push_back(bLink);
+ linksCount ++;
newRow += "##<" + bLink.caption;
@@ -165,45 +167,29 @@ void BrowserBox::addRow(const std::string &row, bool atTop)
newRow = replaceAll(newRow, "%VER%", SMALL_VERSION);
if (atTop)
+ {
mTextRows.push_front(newRow);
+ mTextRowLinksCount.push_front(linksCount);
+ }
else
+ {
mTextRows.push_back(newRow);
+ mTextRowLinksCount.push_back(linksCount);
+ }
//discard older rows when a row limit has been set
- if (mMaxRows > 0)
+ if (mMaxRows > 0 && !mTextRows.empty())
{
while (mTextRows.size() > mMaxRows)
{
mTextRows.pop_front();
+ int cnt = mTextRowLinksCount.front();
+ mTextRowLinksCount.pop_front();
- int yStart = 0;
-
- LinePartIterator i = mLineParts.begin();
- if (i != mLineParts.end())
+ while (cnt && !mLinks.empty())
{
- ++ i;
- for (; i != mLineParts.end(); ++ i)
- {
- const LinePart &part = *i;
- if (!part.mX)
- {
- yStart = part.mY;
- break;
- }
- }
- }
-
- LinkIterator it = mLinks.begin();
- LinkIterator it_end = mLinks.end();
- while (it != it_end)
- {
- (*it).y1 -= yStart;
- (*it).y2 -= yStart;
-
- if ((*it).y1 < 0)
- it = mLinks.erase(it);
- else
- ++ it;
+ mLinks.erase(mLinks.begin());
+ cnt --;
}
}
}
@@ -294,11 +280,13 @@ void BrowserBox::addImage(const std::string &path)
return;
mTextRows.push_back("~~~" + path);
+ mTextRowLinksCount.push_back(0);
}
void BrowserBox::clearRows()
{
mTextRows.clear();
+ mTextRowLinksCount.clear();
mLinks.clear();
setWidth(0);
setHeight(0);
diff --git a/src/gui/widgets/browserbox.h b/src/gui/widgets/browserbox.h
index b1582e077..55bea8dad 100644
--- a/src/gui/widgets/browserbox.h
+++ b/src/gui/widgets/browserbox.h
@@ -207,6 +207,7 @@ class BrowserBox : public gcn::Widget,
typedef TextRows::iterator TextRowIterator;
TextRows mTextRows;
+ std::list<int> mTextRowLinksCount;
typedef std::vector<LinePart> LinePartList;
typedef LinePartList::iterator LinePartIterator;