From 3575c7a606c2d24c0d444e9999892c0390fa5ae8 Mon Sep 17 00:00:00 2001 From: Ira Rice Date: Sat, 14 Mar 2009 13:21:35 -0600 Subject: Made a label class derived from the guichan label class which utilizes the palette colors. While technically, this can be accomplished through other means, it's rather clumsy overall, and is prone to introducing in programmer errors. This commit finally catches every case where text is used, and applies the text color from the color dialog to each of them appropriately. Signed-off-by: Ira Rice --- src/gui/textfield.cpp | 29 ++++++++++++----------------- 1 file changed, 12 insertions(+), 17 deletions(-) (limited to 'src/gui/textfield.cpp') diff --git a/src/gui/textfield.cpp b/src/gui/textfield.cpp index 054bc405..257ddaa1 100644 --- a/src/gui/textfield.cpp +++ b/src/gui/textfield.cpp @@ -22,6 +22,7 @@ #include +#include "palette.h" #include "sdlinput.h" #include "textfield.h" @@ -55,8 +56,10 @@ TextField::TextField(const std::string& text): int gridy[4] = {0, 3, 28, 31}; int a = 0, x, y; - for (y = 0; y < 3; y++) { - for (x = 0; x < 3; x++) { + for (y = 0; y < 3; y++) + { + for (x = 0; x < 3; x++) + { skin.grid[a] = textbox->getSubImage( gridx[x], gridy[y], gridx[x + 1] - gridx[x] + 1, @@ -77,9 +80,7 @@ TextField::~TextField() instances--; if (instances == 0) - { for_each(skin.grid, skin.grid + 9, dtor()); - } } void TextField::draw(gcn::Graphics *graphics) @@ -90,11 +91,11 @@ void TextField::draw(gcn::Graphics *graphics) if (isFocused()) { drawCaret(graphics, - getFont()->getWidth(mText.substr(0, mCaretPosition)) - - mXScroll); + getFont()->getWidth(mText.substr(0, mCaretPosition)) - + mXScroll); } - graphics->setColor(getForegroundColor()); + graphics->setColor(guiPalette->getColor(Palette::TEXT)); graphics->setFont(getFont()); graphics->drawText(mText, 1 - mXScroll, 1); @@ -102,9 +103,7 @@ void TextField::draw(gcn::Graphics *graphics) { mAlpha = config.getValue("guialpha", 0.8); for (int a = 0; a < 9; a++) - { skin.grid[a]->setAlpha(mAlpha); - } } } @@ -122,9 +121,8 @@ void TextField::setNumeric(bool numeric) { mNumeric = numeric; if (!numeric) - { return; - } + const char *text = mText.c_str(); for (const char *textPtr = text; *textPtr; ++textPtr) { @@ -139,18 +137,15 @@ void TextField::setNumeric(bool numeric) int TextField::getValue() const { if (!mNumeric) - { return 0; - } + int value = atoi(mText.c_str()); if (value < mMinimum) - { return mMinimum; - } + if (value > mMaximum) - { return mMaximum; - } + return value; } -- cgit v1.2.3-70-g09d2