diff options
author | Andrei Karas <akaras@inbox.ru> | 2012-10-21 20:28:25 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2012-10-21 20:31:57 +0300 |
commit | d03dcbba2674854cac2d94c259a7ffb20026d188 (patch) | |
tree | bbf84b3ddb74acc77e56adb5ce7c1e44ac90d76a /src/gui/widgets/textpreview.cpp | |
parent | 2f1886147d8dfd741ca95c9751f4f0e81b4cdd73 (diff) | |
download | mv-d03dcbba2674854cac2d94c259a7ffb20026d188.tar.gz mv-d03dcbba2674854cac2d94c259a7ffb20026d188.tar.bz2 mv-d03dcbba2674854cac2d94c259a7ffb20026d188.tar.xz mv-d03dcbba2674854cac2d94c259a7ffb20026d188.zip |
Extend theming for textpreview.
New theme file: textpreview.xml
Theme option: padding
Diffstat (limited to 'src/gui/widgets/textpreview.cpp')
-rw-r--r-- | src/gui/widgets/textpreview.cpp | 42 |
1 files changed, 37 insertions, 5 deletions
diff --git a/src/gui/widgets/textpreview.cpp b/src/gui/widgets/textpreview.cpp index 47cd71dfa..f9f0269c0 100644 --- a/src/gui/widgets/textpreview.cpp +++ b/src/gui/widgets/textpreview.cpp @@ -31,7 +31,9 @@ #include "debug.h" +int TextPreview::instances = 0; float TextPreview::mAlpha = 1.0; +Skin *TextPreview::mSkin = nullptr; TextPreview::TextPreview(const Widget2 *const widget, const std::string &text) : @@ -45,8 +47,33 @@ TextPreview::TextPreview(const Widget2 *const widget, mTextAlpha(false), mOpaque(false), mShadow(false), - mOutline(false) + mOutline(false), + mPadding(0) { + if (instances == 0) + { + if (Theme::instance()) + mSkin = Theme::instance()->load("textpreview.xml", ""); + } + + instances++; + + if (mSkin) + mPadding = mSkin->getOption("padding", 0); + + adjustSize(); +} + +TextPreview::~TextPreview() +{ + instances--; + + if (instances == 0) + { + Theme *const theme = Theme::instance(); + if (theme) + theme->unload(mSkin); + } } void TextPreview::draw(gcn::Graphics* graphics) @@ -78,11 +105,16 @@ void TextPreview::draw(gcn::Graphics* graphics) static_cast<int>(mTextBGColor->g), static_cast<int>(mTextBGColor->b), static_cast<int>(mAlpha * 255.0f))); - graphics->fillRectangle(gcn::Rectangle(1, 1, x, y)); + graphics->fillRectangle(gcn::Rectangle(mPadding, mPadding, x, y)); } } - TextRenderer::renderText(graphics, mText, 2, 2, gcn::Graphics::LEFT, - gcn::Color(mTextColor->r, mTextColor->g, mTextColor->b, alpha), - mFont, mOutline, mShadow); + TextRenderer::renderText(graphics, mText, mPadding + 1, mPadding + 1, + gcn::Graphics::LEFT, gcn::Color(mTextColor->r, mTextColor->g, + mTextColor->b, alpha), mFont, mOutline, mShadow); +} + +void TextPreview::adjustSize() +{ + setHeight(getFont()->getHeight() + 2 * mPadding); } |