diff options
author | Andrei Karas <akaras@inbox.ru> | 2013-08-14 22:10:31 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2013-08-14 22:10:31 +0300 |
commit | a2c06346e1830d888a72ccdb2e224686319af014 (patch) | |
tree | 23dac39f0ca04563c42dd2750135bee53a169012 /src/gui/widgets/tab.cpp | |
parent | f6751cdc1e3a60f31889eacabf3751f23dfdcb0b (diff) | |
download | manaverse-a2c06346e1830d888a72ccdb2e224686319af014.tar.gz manaverse-a2c06346e1830d888a72ccdb2e224686319af014.tar.bz2 manaverse-a2c06346e1830d888a72ccdb2e224686319af014.tar.xz manaverse-a2c06346e1830d888a72ccdb2e224686319af014.zip |
add support for icon in tabs.
Diffstat (limited to 'src/gui/widgets/tab.cpp')
-rw-r--r-- | src/gui/widgets/tab.cpp | 51 |
1 files changed, 42 insertions, 9 deletions
diff --git a/src/gui/widgets/tab.cpp b/src/gui/widgets/tab.cpp index 813ae0ef8..bce4ae11f 100644 --- a/src/gui/widgets/tab.cpp +++ b/src/gui/widgets/tab.cpp @@ -75,6 +75,7 @@ Tab::Tab(const Widget2 *const widget) : mPlayerFlashOutlineColor(&getThemeColor(Theme::TAB_PLAYER_FLASH_OUTLINE)), mFlash(0), mVertexes(new ImageCollection), + mImage(nullptr), mMode(0), mRedraw(true), mHasMouse(false) @@ -98,6 +99,11 @@ Tab::~Tab() delete mLabel; mLabel = nullptr; + if (mImage) + { + mImage->decRef(); + mImage = nullptr; + } delete mVertexes; mVertexes = nullptr; } @@ -210,26 +216,37 @@ void Tab::draw(gcn::Graphics *graphics) updateAlpha(); + Graphics *const g = static_cast<Graphics*>(graphics); + // draw tab if (openGLMode != 2) { const ImageRect &rect = skin->getBorder(); - if (mRedraw || mode != mMode - || static_cast<Graphics*>(graphics)->getRedraw()) + if (mRedraw || mode != mMode || g->getRedraw()) { mMode = mode; mRedraw = false; mVertexes->clear(); - static_cast<Graphics*>(graphics)->calcWindow(mVertexes, 0, 0, + g->calcWindow(mVertexes, 0, 0, mDimension.width, mDimension.height, rect); } - static_cast<Graphics*>(graphics)->drawTile(mVertexes); + g->drawTile(mVertexes); } else { - static_cast<Graphics*>(graphics)->drawImageRect( - 0, 0, mDimension.width, mDimension.height, skin->getBorder()); + g->drawImageRect(0, 0, + mDimension.width, mDimension.height, skin->getBorder()); + } + + if (mImage) + { + const Skin *const skin1 = tabImg[TAB_STANDARD]; + if (skin1) + { + const int padding = skin1->getPadding(); + g->drawImage(mImage, padding, padding); + } } drawChildren(graphics); @@ -262,10 +279,18 @@ void Tab::adjustSize() const Skin *const skin = tabImg[TAB_STANDARD]; if (!skin) return; - const int padding = skin->getPadding(); + const int pad2 = skin->getPadding() * 2; - setSize(mLabel->getWidth() + 2 * padding, - mLabel->getHeight() + 2 * padding); + if (mImage) + { + const SDL_Rect &rect = mImage->mBounds; + setSize(rect.w + pad2, rect.h + pad2); + } + else + { + setSize(mLabel->getWidth() + pad2, + mLabel->getHeight() + pad2); + } if (mTabbedArea) mTabbedArea->adjustTabPositions(); @@ -288,6 +313,14 @@ void Tab::setCaption(const std::string &caption) adjustSize(); } +void Tab::setImage(Image *const image) +{ + if (mImage) + mImage->decRef(); + mImage = image; + adjustSize(); +} + const std::string &Tab::getCaption() const { return mLabel->getCaption(); |