summaryrefslogtreecommitdiff
path: root/src/gui/widgets/textbox.cpp
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2013-06-17 21:28:18 +0300
committerAndrei Karas <akaras@inbox.ru>2013-06-17 21:28:18 +0300
commit0387b5dfbc508587f9ce0b9b1c1f366520f11c0b (patch)
tree7afdf1db63c0490a05b53db0c42afba1df02631a /src/gui/widgets/textbox.cpp
parentdf994f808e69d567fddc742656a1df86c15bf576 (diff)
downloadmanaverse-0387b5dfbc508587f9ce0b9b1c1f366520f11c0b.tar.gz
manaverse-0387b5dfbc508587f9ce0b9b1c1f366520f11c0b.tar.bz2
manaverse-0387b5dfbc508587f9ce0b9b1c1f366520f11c0b.tar.xz
manaverse-0387b5dfbc508587f9ce0b9b1c1f366520f11c0b.zip
improve textbox.
Diffstat (limited to 'src/gui/widgets/textbox.cpp')
-rw-r--r--src/gui/widgets/textbox.cpp28
1 files changed, 15 insertions, 13 deletions
diff --git a/src/gui/widgets/textbox.cpp b/src/gui/widgets/textbox.cpp
index 386a89bad..c1bf84d85 100644
--- a/src/gui/widgets/textbox.cpp
+++ b/src/gui/widgets/textbox.cpp
@@ -57,12 +57,6 @@ void TextBox::setTextWrapped(const std::string &text, const int minDimension)
// point and try to beat it
mMinWidth = minDimension;
- std::stringstream wrappedStream;
- size_t newlinePos;
- size_t lastNewlinePos = 0;
- int minWidth = 0;
- int xpos;
-
size_t spacePos = text.rfind(" ", text.size());
if (spacePos != std::string::npos)
@@ -74,6 +68,12 @@ void TextBox::setTextWrapped(const std::string &text, const int minDimension)
mMinWidth = length;
}
+ std::stringstream wrappedStream;
+ size_t newlinePos;
+ size_t lastNewlinePos = 0;
+ int minWidth = 0;
+ int xpos;
+
do
{
// Determine next piece of string to wrap
@@ -86,6 +86,8 @@ void TextBox::setTextWrapped(const std::string &text, const int minDimension)
text.substr(lastNewlinePos, newlinePos - lastNewlinePos);
size_t lastSpacePos = 0;
xpos = 0;
+ gcn::Font *const font = getFont();
+ const int spaceWidth = font->getWidth(" ");
do
{
@@ -94,10 +96,10 @@ void TextBox::setTextWrapped(const std::string &text, const int minDimension)
if (spacePos == std::string::npos)
spacePos = line.size();
- std::string word =
+ const std::string word =
line.substr(lastSpacePos, spacePos - lastSpacePos);
- const int width = getFont()->getWidth(word);
+ const int width = font->getWidth(word);
if (xpos == 0 && width > mMinWidth)
{
@@ -105,10 +107,10 @@ void TextBox::setTextWrapped(const std::string &text, const int minDimension)
xpos = width;
wrappedStream << word;
}
- else if (xpos != 0 && xpos + getFont()->getWidth(" ") + width <=
+ else if (xpos != 0 && xpos + spaceWidth + width <=
mMinWidth)
{
- xpos += getFont()->getWidth(" ") + width;
+ xpos += spaceWidth + width;
wrappedStream << " " << word;
}
else if (lastSpacePos == 0)
@@ -355,16 +357,16 @@ void TextBox::draw(gcn::Graphics* graphics)
graphics->fillRectangle(gcn::Rectangle(0, 0, getWidth(), getHeight()));
}
+ gcn::Font *const font = getFont();
if (isFocused() && isEditable())
{
- drawCaret(graphics, getFont()->getWidth(
+ drawCaret(graphics, font->getWidth(
mTextRows[mCaretRow].substr(0, mCaretColumn)),
- mCaretRow * getFont()->getHeight());
+ mCaretRow * font->getHeight());
}
static_cast<Graphics*>(graphics)->setColorAll(
mForegroundColor, mForegroundColor2);
- gcn::Font *const font = getFont();
const int fontHeight = font->getHeight();
for (size_t i = 0, sz = mTextRows.size(); i < sz; i++)