summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPhilipp Sehmisch <tmw@crushnet.org>2007-10-26 00:22:12 +0000
committerPhilipp Sehmisch <tmw@crushnet.org>2007-10-26 00:22:12 +0000
commitdb8b740bfa402c929247efd954096fac7b72b2a3 (patch)
tree62164d11ad6ce852bb672298068b69f9b5b4de7e /src
parent4f49eb94ddf9d2f0f3c59560c761188d101bd5f8 (diff)
downloadmana-db8b740bfa402c929247efd954096fac7b72b2a3.tar.gz
mana-db8b740bfa402c929247efd954096fac7b72b2a3.tar.bz2
mana-db8b740bfa402c929247efd954096fac7b72b2a3.tar.xz
mana-db8b740bfa402c929247efd954096fac7b72b2a3.zip
Added possibility of length limitation to browserbox and used it for the chatlog (length set by the config option "ChatLogLength").
Diffstat (limited to 'src')
-rw-r--r--src/gui/browserbox.cpp23
-rw-r--r--src/gui/browserbox.h8
-rw-r--r--src/gui/chat.cpp2
-rw-r--r--src/main.cpp1
4 files changed, 26 insertions, 8 deletions
diff --git a/src/gui/browserbox.cpp b/src/gui/browserbox.cpp
index 21609434..185777d0 100644
--- a/src/gui/browserbox.cpp
+++ b/src/gui/browserbox.cpp
@@ -42,7 +42,9 @@ BrowserBox::BrowserBox(unsigned int mode):
gcn::Widget(),
mMode(mode), mHighMode(UNDERLINE | BACKGROUND),
mOpaque(true),
- mUseLinksAndUserColors(true), mSelectedLink(-1)
+ mUseLinksAndUserColors(true),
+ mSelectedLink(-1),
+ mMaxRows(0)
{
setFocusable(true);
addMouseListener(this);
@@ -154,6 +156,12 @@ void BrowserBox::addRow(const std::string &row)
mTextRows.push_back(newRow);
+ //discard older rows when a row limit has been set
+ if (mMaxRows > 0)
+ {
+ while (mTextRows.size() > mMaxRows) mTextRows.pop_front();
+ }
+
// Auto size mode
if (mMode == AUTO_SIZE)
{
@@ -169,14 +177,15 @@ void BrowserBox::addRow(const std::string &row)
if (mMode == AUTO_WRAP)
{
- unsigned int i, j, y = 0;
+ unsigned int j, y = 0;
unsigned int nextChar;
char hyphen = '~';
int hyphenWidth = font->getWidth(hyphen);
int x = 0;
- for (i = 0; i < mTextRows.size(); i++)
+
+ for (TextRowIterator i = mTextRows.begin(); i != mTextRows.end(); i++)
{
- std::string row = mTextRows[i];
+ std::string row = *i;
for (j = 0; j < row.size(); j++)
{
x += font->getWidth(row.at(j));
@@ -290,17 +299,17 @@ BrowserBox::draw(gcn::Graphics *graphics)
}
}
- unsigned int i, j;
+ unsigned int j;
int x = 0, y = 0;
int wrappedLines = 0;
gcn::ImageFont *font = dynamic_cast<gcn::ImageFont*>(getFont());
graphics->setColor(BLACK);
- for (i = 0; i < mTextRows.size(); i++)
+ for (TextRowIterator i = mTextRows.begin(); i != mTextRows.end(); i++)
{
int selColor = BLACK;
int prevColor = selColor;
- std::string row = mTextRows[i];
+ std::string row = *(i);
x = 0;
for (j = 0; j < row.size(); j++)
diff --git a/src/gui/browserbox.h b/src/gui/browserbox.h
index 666a7754..9c0e8ef1 100644
--- a/src/gui/browserbox.h
+++ b/src/gui/browserbox.h
@@ -74,6 +74,11 @@ class BrowserBox : public gcn::Widget, public gcn::MouseListener
void setHighlightMode(unsigned int highMode);
/**
+ * Sets the maximum numbers of rows in the browser box. 0 = no limit.
+ */
+ void setMaxRow(int max) {mMaxRows = max; };
+
+ /**
* Disable links & user defined colors to be used in chat input.
*/
void disableLinksAndUserColors();
@@ -144,7 +149,7 @@ class BrowserBox : public gcn::Widget, public gcn::MouseListener
};
private:
- typedef std::vector<std::string> TextRows;
+ typedef std::list<std::string> TextRows;
typedef TextRows::iterator TextRowIterator;
TextRows mTextRows;
@@ -158,6 +163,7 @@ class BrowserBox : public gcn::Widget, public gcn::MouseListener
bool mOpaque;
bool mUseLinksAndUserColors;
int mSelectedLink;
+ unsigned int mMaxRows;
#ifdef USE_OPENGL
static int instances; /**< Number of Window instances */
diff --git a/src/gui/chat.cpp b/src/gui/chat.cpp
index 48c84b96..10fc1577 100644
--- a/src/gui/chat.cpp
+++ b/src/gui/chat.cpp
@@ -33,6 +33,7 @@
#include "scrollarea.h"
#include "windowcontainer.h"
+#include "../configuration.h"
#include "../game.h"
#include "../localplayer.h"
@@ -61,6 +62,7 @@ ChatWindow::ChatWindow(Network *network):
mTextOutput = new BrowserBox(BrowserBox::AUTO_WRAP);
mTextOutput->setOpaque(false);
mTextOutput->disableLinksAndUserColors();
+ mTextOutput->setMaxRow((int) config.getValue("ChatLogLength", 0));
mScrollArea = new ScrollArea(mTextOutput);
mScrollArea->setPosition(
mScrollArea->getBorderSize(), mScrollArea->getBorderSize());
diff --git a/src/main.cpp b/src/main.cpp
index 066041a4..9c8b6f4e 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -234,6 +234,7 @@ void init_engine(const Options &options)
config.setValue("fpslimit", 60);
config.setValue("updatehost", "http://updates.themanaworld.org");
config.setValue("customcursor", 1);
+ config.setValue("ChatLogLength", 64);
// Checking if the configuration file exists... otherwise creates it with
// default options !