From 011133ef09dd4340c7649100cea170e2595b6b2f Mon Sep 17 00:00:00 2001 From: Ira Rice Date: Fri, 13 Mar 2009 00:47:50 -0600 Subject: Made the TextPreview widget respect alpha values. Signed-off-by: Ira Rice --- src/gui/widgets/textpreview.cpp | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) (limited to 'src/gui/widgets/textpreview.cpp') diff --git a/src/gui/widgets/textpreview.cpp b/src/gui/widgets/textpreview.cpp index b13d12e4..e34bb5cb 100644 --- a/src/gui/widgets/textpreview.cpp +++ b/src/gui/widgets/textpreview.cpp @@ -28,6 +28,10 @@ #include "../textrenderer.h" #include "../truetypefont.h" +#include "../../configuration.h" + +float TextPreview::mAlpha = config.getValue("guialpha", 0.8); + TextPreview::TextPreview(const std::string* text) { mText = text; @@ -40,22 +44,28 @@ TextPreview::TextPreview(const std::string* text) void TextPreview::draw(gcn::Graphics* graphics) { + if (config.getValue("guialpha", 0.8) != mAlpha) + mAlpha = config.getValue("guialpha", 0.8); + if (mOpaque) { - graphics->setColor(*mBGColor); + graphics->setColor(gcn::Color((int) mBGColor->r, + (int) mBGColor->g, + (int) mBGColor->b, + (int)(mAlpha * 255.0f))); graphics->fillRectangle(gcn::Rectangle(0, 0, getWidth(), getHeight())); } - const std::string ttf = "TrueTypeFont"; - - if (mTextBGColor && typeid(*mFont).name() == ttf) + if (mTextBGColor && typeid(*mFont) == typeid(TrueTypeFont)) { TrueTypeFont *font = static_cast(mFont); - graphics->setColor(*mTextBGColor); int x = font->getWidth(*mText) + 1 + 2 * ((mOutline || mShadow) ? 1 :0); int y = font->getHeight() + 1 + 2 * ((mOutline || mShadow) ? 1 : 0); - if (mOpaque) - graphics->fillRectangle(gcn::Rectangle(1, 1, x, y)); + graphics->setColor(gcn::Color((int) mTextBGColor->r, + (int) mTextBGColor->g, + (int) mTextBGColor->b, + (int)(mAlpha * 255.0f))); + graphics->fillRectangle(gcn::Rectangle(1, 1, x, y)); } TextRenderer::renderText(graphics, *mText, 2, 2, gcn::Graphics::LEFT, -- cgit v1.2.3-60-g2f50