summaryrefslogtreecommitdiff
path: root/src/guichan/widgets/textfield.cpp
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2011-05-31 01:27:37 +0300
committerAndrei Karas <akaras@inbox.ru>2011-05-31 01:27:37 +0300
commit9d3b975bcb84ad1c61d628de2804751c0d0707dd (patch)
treefe7494b1ecd561a40dc96d088c77d69b6d4ce13e /src/guichan/widgets/textfield.cpp
parent1d0044cbc81e547ad688a295288910d58e1a3fb1 (diff)
downloadplus-9d3b975bcb84ad1c61d628de2804751c0d0707dd.tar.gz
plus-9d3b975bcb84ad1c61d628de2804751c0d0707dd.tar.bz2
plus-9d3b975bcb84ad1c61d628de2804751c0d0707dd.tar.xz
plus-9d3b975bcb84ad1c61d628de2804751c0d0707dd.zip
Fix code style and missing members initialisations.
Diffstat (limited to 'src/guichan/widgets/textfield.cpp')
-rw-r--r--src/guichan/widgets/textfield.cpp44
1 files changed, 17 insertions, 27 deletions
diff --git a/src/guichan/widgets/textfield.cpp b/src/guichan/widgets/textfield.cpp
index e8fc9c5d6..7f4325529 100644
--- a/src/guichan/widgets/textfield.cpp
+++ b/src/guichan/widgets/textfield.cpp
@@ -81,10 +81,8 @@ namespace gcn
void TextField::setText(const std::string& text)
{
- if(text.size() < mCaretPosition )
- {
+ if (text.size() < mCaretPosition)
mCaretPosition = text.size();
- }
mText = text;
}
@@ -105,11 +103,13 @@ namespace gcn
graphics->drawLine(0, 1, 0, getHeight() - 2);
graphics->setColor(highlightColor);
graphics->drawLine(getWidth() - 1, 1, getWidth() - 1, getHeight() - 1);
- graphics->drawLine(0, getHeight() - 1, getWidth() - 1, getHeight() - 1);
+ graphics->drawLine(0, getHeight() - 1,
+ getWidth() - 1, getHeight() - 1);
// Push a clip area so the other drawings don't need to worry
// about the border.
- graphics->pushClipArea(Rectangle(1, 1, getWidth() - 2, getHeight() - 2));
+ graphics->pushClipArea(Rectangle(1, 1,
+ getWidth() - 2, getHeight() - 2));
graphics->setColor(getBackgroundColor());
graphics->fillRectangle(Rectangle(0, 0, getWidth(), getHeight()));
@@ -117,13 +117,16 @@ namespace gcn
if (isFocused())
{
graphics->setColor(getSelectionColor());
- graphics->drawRectangle(Rectangle(0, 0, getWidth() - 2, getHeight() - 2));
- graphics->drawRectangle(Rectangle(1, 1, getWidth() - 4, getHeight() - 4));
+ graphics->drawRectangle(Rectangle(0, 0,
+ getWidth() - 2, getHeight() - 2));
+ graphics->drawRectangle(Rectangle(1, 1,
+ getWidth() - 4, getHeight() - 4));
}
if (isFocused())
{
- drawCaret(graphics, getFont()->getWidth(mText.substr(0, mCaretPosition)) - mXScroll);
+ drawCaret(graphics, getFont()->getWidth(
+ mText.substr(0, mCaretPosition)) - mXScroll);
}
graphics->setColor(getForegroundColor());
@@ -149,7 +152,8 @@ namespace gcn
{
if (mouseEvent.getButton() == MouseEvent::LEFT)
{
- mCaretPosition = getFont()->getStringIndexAt(mText, mouseEvent.getX() + mXScroll);
+ mCaretPosition = getFont()->getStringIndexAt(
+ mText, mouseEvent.getX() + mXScroll);
fixScroll();
}
}
@@ -167,50 +171,42 @@ namespace gcn
{
--mCaretPosition;
}
-
else if (key.getValue() == Key::RIGHT && mCaretPosition < mText.size())
{
++mCaretPosition;
}
-
- else if (key.getValue() == Key::DELETE && mCaretPosition < mText.size())
+ else if (key.getValue() == Key::DELETE
+ && mCaretPosition < mText.size())
{
mText.erase(mCaretPosition, 1);
}
-
else if (key.getValue() == Key::BACKSPACE && mCaretPosition > 0)
{
mText.erase(mCaretPosition - 1, 1);
--mCaretPosition;
}
-
else if (key.getValue() == Key::ENTER)
{
distributeActionEvent();
}
-
else if (key.getValue() == Key::HOME)
{
mCaretPosition = 0;
}
-
else if (key.getValue() == Key::END)
{
mCaretPosition = mText.size();
}
-
else if (key.isCharacter()
&& key.getValue() != Key::TAB)
{
- mText.insert(mCaretPosition, std::string(1,(char)key.getValue()));
+ mText.insert(mCaretPosition, std::string(1, (char)key.getValue()));
++mCaretPosition;
}
if (key.getValue() != Key::TAB)
- {
keyEvent.consume();
- }
-
+
fixScroll();
}
@@ -242,9 +238,7 @@ namespace gcn
mXScroll = caretX - getWidth() / 2;
if (mXScroll < 0)
- {
mXScroll = 0;
- }
}
}
}
@@ -252,13 +246,9 @@ namespace gcn
void TextField::setCaretPosition(unsigned int position)
{
if (position > mText.size())
- {
mCaretPosition = mText.size();
- }
else
- {
mCaretPosition = position;
- }
fixScroll();
}