From 9c7446cc89957b46c7a41671cc0f7fb2f5f2f4fe Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Tue, 4 Jun 2013 13:55:47 +0300 Subject: improve icon class. --- src/gui/widgets/icon.cpp | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) (limited to 'src/gui/widgets') diff --git a/src/gui/widgets/icon.cpp b/src/gui/widgets/icon.cpp index 61b2611cf..9232aea0d 100644 --- a/src/gui/widgets/icon.cpp +++ b/src/gui/widgets/icon.cpp @@ -33,7 +33,10 @@ Icon::Icon(const Widget2 *const widget, const std::string &file) : mImage(ResourceManager::getInstance()->getImage(file)) { if (mImage) - setSize(mImage->mBounds.w, mImage->mBounds.h); + { + const SDL_Rect &bounds = mImage->mBounds; + setSize(bounds.w, bounds.h); + } } Icon::Icon(const Widget2 *const widget, Image *const image) : @@ -42,7 +45,10 @@ Icon::Icon(const Widget2 *const widget, Image *const image) : mImage(image) { if (mImage) - setSize(mImage->mBounds.w, mImage->mBounds.h); + { + const SDL_Rect &bounds = mImage->mBounds; + setSize(bounds.w, bounds.h); + } } Icon::~Icon() @@ -55,7 +61,10 @@ void Icon::setImage(Image *const image) { mImage = image; if (mImage) - setSize(mImage->mBounds.w, mImage->mBounds.h); + { + const SDL_Rect &bounds = mImage->mBounds; + setSize(bounds.w, bounds.h); + } } void Icon::draw(gcn::Graphics *g) @@ -64,8 +73,8 @@ void Icon::draw(gcn::Graphics *g) if (mImage) { Graphics *const graphics = static_cast(g); - graphics->drawImage(mImage, (getWidth() - mImage->mBounds.w) / 2, - (getHeight() - mImage->mBounds.h) / 2); + graphics->drawImage(mImage, (mDimension.width - mImage->mBounds.w) / 2, + (mDimension.height - mImage->mBounds.h) / 2); } BLOCK_END("Icon::draw") } -- cgit v1.2.3-70-g09d2