diff options
author | Andrei Karas <akaras@inbox.ru> | 2013-06-06 13:49:23 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2013-06-06 13:49:23 +0300 |
commit | 81c3e097402f19ec7e8ed1971c03a1b45ed0439e (patch) | |
tree | 1687575fe5ebb0e552d2e3da33e6973a0db14d4f /src/gui/widgets/label.cpp | |
parent | 58ccd6f9619f84e8e87ca9c6c7cd6f8bc01e7bfc (diff) | |
download | manaplus-81c3e097402f19ec7e8ed1971c03a1b45ed0439e.tar.gz manaplus-81c3e097402f19ec7e8ed1971c03a1b45ed0439e.tar.bz2 manaplus-81c3e097402f19ec7e8ed1971c03a1b45ed0439e.tar.xz manaplus-81c3e097402f19ec7e8ed1971c03a1b45ed0439e.zip |
Improve label.
Diffstat (limited to 'src/gui/widgets/label.cpp')
-rw-r--r-- | src/gui/widgets/label.cpp | 28 |
1 files changed, 18 insertions, 10 deletions
diff --git a/src/gui/widgets/label.cpp b/src/gui/widgets/label.cpp index 854b0f33c..90c8f6f66 100644 --- a/src/gui/widgets/label.cpp +++ b/src/gui/widgets/label.cpp @@ -50,8 +50,12 @@ Label::~Label() gui->removeDragged(this); mInstances --; - if (mInstances == 0 && Theme::instance()) - Theme::instance()->unload(mSkin); + if (mInstances == 0) + { + Theme *const theme = Theme::instance(); + if (theme) + theme->unload(mSkin); + } } void Label::init() @@ -60,8 +64,9 @@ void Label::init() mForegroundColor2 = getThemeColor(Theme::LABEL_OUTLINE); if (mInstances == 0) { - if (Theme::instance()) - mSkin = Theme::instance()->load("label.xml", ""); + Theme *const theme = Theme::instance(); + if (theme) + mSkin = theme->load("label.xml", ""); } mInstances ++; @@ -75,7 +80,8 @@ void Label::draw(gcn::Graphics* graphics) { BLOCK_START("Label::draw") int textX; - const int textY = getHeight() / 2 - getFont()->getHeight() / 2; + const gcn::Rectangle &rect = mDimension; + const int textY = rect.height / 2 - getFont()->getHeight() / 2; gcn::Font *const font = getFont(); switch (mAlignment) @@ -85,11 +91,11 @@ void Label::draw(gcn::Graphics* graphics) textX = mPadding; break; case Graphics::CENTER: - textX = (getWidth() - font->getWidth(mCaption)) / 2; + textX = (rect.width - font->getWidth(mCaption)) / 2; break; case Graphics::RIGHT: - if (getWidth() > mPadding) - textX = getWidth() - mPadding - font->getWidth(mCaption); + if (rect.width > mPadding) + textX = rect.width - mPadding - font->getWidth(mCaption); else textX = 0; break; @@ -103,8 +109,10 @@ void Label::draw(gcn::Graphics* graphics) void Label::adjustSize() { - setWidth(getFont()->getWidth(getCaption()) + 2 * mPadding); - setHeight(getFont()->getHeight() + 2 * mPadding); + gcn::Font *const font = getFont(); + const int pad2 = 2 * mPadding; + setWidth(font->getWidth(mCaption) + pad2); + setHeight(font->getHeight() + pad2); } void Label::setForegroundColor(const gcn::Color &color) |