summaryrefslogtreecommitdiff
path: root/src/gui
diff options
context:
space:
mode:
Diffstat (limited to 'src/gui')
-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;