summaryrefslogtreecommitdiff
path: root/src/gui/widgets/textbox.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/gui/widgets/textbox.cpp')
-rw-r--r--src/gui/widgets/textbox.cpp50
1 files changed, 47 insertions, 3 deletions
diff --git a/src/gui/widgets/textbox.cpp b/src/gui/widgets/textbox.cpp
index 419fa16e..7fd7d626 100644
--- a/src/gui/widgets/textbox.cpp
+++ b/src/gui/widgets/textbox.cpp
@@ -21,15 +21,19 @@
#include "gui/widgets/textbox.h"
+#include "gui/gui.h"
#include "resources/theme.h"
#include <guichan/font.hpp>
#include <sstream>
-TextBox::TextBox() :
- mTextColor(&Theme::getThemeColor(Theme::TEXT))
+TextBox::TextBox()
{
+ auto &palette = gui->getTheme()->getPalette(0);
+ mTextColor = &palette.getColor(Theme::TEXT);
+ mOutlineColor = palette.getOutlineColor(Theme::TEXT);
+
setOpaque(false);
setFrameSize(0);
mMinWidth = getWidth();
@@ -91,7 +95,7 @@ void TextBox::setTextWrapped(const std::string &text, int minDimension)
xpos = width;
wrappedStream << word;
}
- else if (xpos != 0 && xpos + getFont()->getWidth(" ") + width <=
+ else if (xpos != 0 && xpos + getFont()->getWidth(" ") + width <=
mMinWidth)
{
xpos += getFont()->getWidth(" ") + width;
@@ -147,3 +151,43 @@ void TextBox::setTextWrapped(const std::string &text, int minDimension)
gcn::TextBox::setText(wrappedStream.str());
}
+
+/**
+ * Overridden so we can customize the color and outline of the text.
+ */
+void TextBox::draw(gcn::Graphics *graphics)
+{
+ unsigned int i;
+
+ if (mOpaque)
+ {
+ graphics->setColor(getBackgroundColor());
+ graphics->fillRectangle(gcn::Rectangle(0, 0, getWidth(), getHeight()));
+ }
+
+ if (isFocused() && isEditable())
+ {
+ drawCaret(graphics,
+ getFont()->getWidth(mTextRows[mCaretRow].substr(0, mCaretColumn)),
+ mCaretRow * getFont()->getHeight());
+ }
+
+ graphics->setColor(*mTextColor);
+ graphics->setFont(getFont());
+
+ auto g = static_cast<Graphics*>(graphics);
+
+ for (i = 0; i < mTextRows.size(); i++)
+ {
+ // Move the text one pixel so we can have a caret before a letter.
+ g->drawText(mTextRows[i],
+ 1,
+ i * getFont()->getHeight(),
+ gcn::Graphics::LEFT,
+ *mTextColor,
+ getFont(),
+ mOutlineColor.has_value(),
+ false,
+ mOutlineColor);
+ }
+}