00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "gui/widgets/textpreview.h"
00023
00024 #include "gui/gui.h"
00025 #include "gui/palette.h"
00026 #include "gui/textrenderer.h"
00027 #include "gui/truetypefont.h"
00028
00029 #include "configuration.h"
00030
00031 #include <typeinfo>
00032
00033 float TextPreview::mAlpha = 1.0;
00034
00035 TextPreview::TextPreview(const std::string &text):
00036 mText(text)
00037 {
00038 mTextAlpha = false;
00039 mFont = gui->getFont();
00040 mTextColor = &guiPalette->getColor(Palette::TEXT);
00041 mTextBGColor = NULL;
00042 mBGColor = &guiPalette->getColor(Palette::BACKGROUND);
00043 mOpaque = false;
00044 }
00045
00046 void TextPreview::draw(gcn::Graphics* graphics)
00047 {
00048 if (config.getValue("guialpha", 0.8) != mAlpha)
00049 mAlpha = config.getValue("guialpha", 0.8);
00050
00051 int alpha = (int) (mAlpha * 255.0f);
00052
00053 if (!mTextAlpha)
00054 alpha = 255;
00055
00056 if (mOpaque)
00057 {
00058 graphics->setColor(gcn::Color((int) mBGColor->r,
00059 (int) mBGColor->g,
00060 (int) mBGColor->b,
00061 (int)(mAlpha * 255.0f)));
00062 graphics->fillRectangle(gcn::Rectangle(0, 0, getWidth(), getHeight()));
00063 }
00064
00065 if (mTextBGColor && typeid(*mFont) == typeid(TrueTypeFont))
00066 {
00067 TrueTypeFont *font = static_cast<TrueTypeFont*>(mFont);
00068 int x = font->getWidth(mText) + 1 + 2 * ((mOutline || mShadow) ? 1 :0);
00069 int y = font->getHeight() + 1 + 2 * ((mOutline || mShadow) ? 1 : 0);
00070 graphics->setColor(gcn::Color((int) mTextBGColor->r,
00071 (int) mTextBGColor->g,
00072 (int) mTextBGColor->b,
00073 (int)(mAlpha * 255.0f)));
00074 graphics->fillRectangle(gcn::Rectangle(1, 1, x, y));
00075 }
00076
00077 TextRenderer::renderText(graphics, mText, 2, 2, gcn::Graphics::LEFT,
00078 gcn::Color(mTextColor->r, mTextColor->g,
00079 mTextColor->b, alpha),
00080 mFont, mOutline, mShadow, alpha);
00081 }