summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2013-06-18 12:59:20 +0300
committerAndrei Karas <akaras@inbox.ru>2013-06-18 12:59:20 +0300
commit4a137325c501fe143197f2fcb97b0ad63ba4bbab (patch)
treefa70f4336990c3ba51bae795bb64f03bf37a2af2 /src
parentdc81c59c99e911499f5c12b0ba21e54a96210ebe (diff)
downloadmanaverse-4a137325c501fe143197f2fcb97b0ad63ba4bbab.tar.gz
manaverse-4a137325c501fe143197f2fcb97b0ad63ba4bbab.tar.bz2
manaverse-4a137325c501fe143197f2fcb97b0ad63ba4bbab.tar.xz
manaverse-4a137325c501fe143197f2fcb97b0ad63ba4bbab.zip
improve textfield.
Diffstat (limited to 'src')
-rw-r--r--src/gui/widgets/textfield.cpp25
-rw-r--r--src/gui/widgets/textfield.h14
2 files changed, 20 insertions, 19 deletions
diff --git a/src/gui/widgets/textfield.cpp b/src/gui/widgets/textfield.cpp
index 5d0621e1e..006fb4503 100644
--- a/src/gui/widgets/textfield.cpp
+++ b/src/gui/widgets/textfield.cpp
@@ -49,7 +49,8 @@ ImageRect TextField::skin;
TextField::TextField(const Widget2 *const widget,
const std::string &text, const bool loseFocusOnTab,
- gcn::ActionListener *const listener, std::string eventId,
+ gcn::ActionListener *const listener,
+ const std::string &eventId,
const bool sendAlwaysEvents):
gcn::TextField(text),
gcn::FocusListener(),
@@ -72,9 +73,10 @@ TextField::TextField(const Widget2 *const widget,
if (instances == 0)
{
- if (Theme::instance())
+ Theme *const theme = Theme::instance();
+ if (theme)
{
- mSkin = Theme::instance()->loadSkinRect(skin, "textfield.xml",
+ mSkin = theme->loadSkinRect(skin, "textfield.xml",
"textfield_background.xml");
}
}
@@ -136,16 +138,15 @@ void TextField::draw(gcn::Graphics *graphics)
BLOCK_START("TextField::draw")
updateAlpha();
+ gcn::Font *const font = getFont();
if (isFocused())
{
drawCaret(graphics,
- getFont()->getWidth(mText.substr(0, mCaretPosition)) -
- mXScroll);
+ font->getWidth(mText.substr(0, mCaretPosition)) - mXScroll);
}
static_cast<Graphics*>(graphics)->setColorAll(
mForegroundColor, mForegroundColor2);
- gcn::Font *const font = getFont();
font->drawString(graphics, mText, mPadding - mXScroll, mPadding);
BLOCK_END("TextField::draw")
}
@@ -153,9 +154,9 @@ void TextField::draw(gcn::Graphics *graphics)
void TextField::drawFrame(gcn::Graphics *graphics)
{
BLOCK_START("TextField::drawFrame")
- const int bs = 2 * getFrameSize();
+ const int bs = 2 * mFrameSize;
static_cast<Graphics*>(graphics)->drawImageRect(0, 0,
- getWidth() + bs, getHeight() + bs, skin);
+ mDimension.width + bs, mDimension.height + bs, skin);
BLOCK_END("TextField::drawFrame")
}
@@ -367,7 +368,6 @@ void TextField::keyPressed(gcn::KeyEvent &keyEvent)
}
const int action = static_cast<KeyEvent*>(&keyEvent)->getActionId();
-
switch (action)
{
case Input::KEY_GUI_LEFT:
@@ -501,14 +501,15 @@ void TextField::fixScroll()
const int caretX = getFont()->getWidth(
mText.substr(0, mCaretPosition));
+ const int width = mDimension.width;
const int pad = 2 * mPadding;
- if (caretX - mXScroll >= getWidth() - pad)
+ if (caretX - mXScroll >= width - pad)
{
- mXScroll = caretX - getWidth() + pad;
+ mXScroll = caretX - width + pad;
}
else if (caretX - mXScroll <= 0)
{
- mXScroll = caretX - getWidth() / 2;
+ mXScroll = caretX - width / 2;
if (mXScroll < 0)
mXScroll = 0;
diff --git a/src/gui/widgets/textfield.h b/src/gui/widgets/textfield.h
index d26d16d21..5e1553acd 100644
--- a/src/gui/widgets/textfield.h
+++ b/src/gui/widgets/textfield.h
@@ -51,7 +51,7 @@ class TextField : public gcn::TextField,
const std::string &text = "",
const bool loseFocusOnTab = true,
gcn::ActionListener *const listener = nullptr,
- std::string eventId = "",
+ const std::string &eventId = "",
const bool sendAlwaysEvents = false);
A_DELETE_COPY(TextField)
@@ -81,7 +81,7 @@ class TextField : public gcn::TextField,
/**
* Set the range on the field if it is numeric
*/
- void setRange(int min, int max)
+ void setRange(const int min, const int max)
{
mMinimum = min;
mMaximum = max;
@@ -95,13 +95,13 @@ class TextField : public gcn::TextField,
/**
* Set the minimum value for a range
*/
- void setMinimum(int min)
+ void setMinimum(const int min)
{ mMinimum = min; }
/**
* Set the maximum value for a range
*/
- void setMaximum(int max)
+ void setMaximum(const int max)
{ mMaximum = max; }
/**
@@ -109,7 +109,7 @@ class TextField : public gcn::TextField,
*/
int getValue() const A_WARN_UNUSED;
- void setSendAlwaysEvents(bool b)
+ void setSendAlwaysEvents(const bool b)
{ mSendAlwaysEvents = b; }
void adjustSize();
@@ -124,9 +124,9 @@ class TextField : public gcn::TextField,
void handleCopy() const;
- void focusGained(const gcn::Event &event);
+ void focusGained(const gcn::Event &event) override;
- void focusLost(const gcn::Event &event);
+ void focusLost(const gcn::Event &event) override;
protected:
void drawCaret(gcn::Graphics* graphics, int x) override;