From 6b8cc23d56d0f46bb8b53bbfb3468adea6a7dd77 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Mon, 25 May 2015 18:32:11 +0300 Subject: Add safeDraw method into tab. --- src/gui/widgets/tabs/tab.cpp | 135 ++++++++++++++++++++++++++++++++----------- src/gui/widgets/tabs/tab.h | 2 + 2 files changed, 103 insertions(+), 34 deletions(-) diff --git a/src/gui/widgets/tabs/tab.cpp b/src/gui/widgets/tabs/tab.cpp index 21b51d79a..5be8f55dc 100644 --- a/src/gui/widgets/tabs/tab.cpp +++ b/src/gui/widgets/tabs/tab.cpp @@ -273,53 +273,120 @@ void Tab::draw(Graphics *graphics) updateAlpha(); - // draw tab - if (isBatchDrawRenders(openGLMode)) + const ImageRect &rect = skin->getBorder(); + if (mRedraw || mode != mMode || graphics->getRedraw()) { - const ImageRect &rect = skin->getBorder(); - if (mRedraw || mode != mMode || graphics->getRedraw()) + mMode = mode; + mRedraw = false; + mVertexes->clear(); + graphics->calcWindow(mVertexes, + 0, 0, + mDimension.width, mDimension.height, + rect); + + if (mImage) { - mMode = mode; - mRedraw = false; - mVertexes->clear(); - graphics->calcWindow(mVertexes, - 0, 0, - mDimension.width, mDimension.height, - rect); - - if (mImage) + const Skin *const skin1 = tabImg[TAB_STANDARD]; + if (skin1) { - const Skin *const skin1 = tabImg[TAB_STANDARD]; - if (skin1) - { - const int padding = skin1->getPadding(); - graphics->calcTileCollection(mVertexes, - mImage, - padding, - padding); - } + const int padding = skin1->getPadding(); + graphics->calcTileCollection(mVertexes, + mImage, + padding, + padding); } - graphics->finalize(mVertexes); } - - graphics->drawTileCollection(mVertexes); + graphics->finalize(mVertexes); } - else + + graphics->drawTileCollection(mVertexes); + + drawChildren(graphics); + BLOCK_END("Tab::draw") +} + +void Tab::safeDraw(Graphics *graphics) +{ + BLOCK_START("Tab::draw") + int mode = TAB_STANDARD; + + // check which type of tab to draw + if (mTabbedArea) { - graphics->drawImageRect(0, 0, - mDimension.width, mDimension.height, - skin->getBorder()); - if (mImage) + int labelMode = mFlash; + + if (mTabbedArea->isTabSelected(this)) { - const Skin *const skin1 = tabImg[TAB_STANDARD]; - if (skin1) + labelMode = 3; + mode = TAB_SELECTED; + // if tab is selected, it doesnt need to highlight activity + mFlash = 0; + } + else if (!labelMode) + { + if (mHasMouse) { - const int padding = skin1->getPadding(); - graphics->drawImage(mImage, padding, padding); + labelMode = 4; + mode = TAB_HIGHLIGHTED; + } + } + else if (mHasMouse) + { + mode = TAB_HIGHLIGHTED; + } + + if (labelMode != mLabelMode) + { + mLabelMode = labelMode; + switch (labelMode) + { + case 0: // default state + default: + mLabel->setForegroundColorAll(*mTabColor, + *mTabOutlineColor); + break; + case 1: // mFlash == 1 + mLabel->setForegroundColorAll(*mFlashColor, + *mFlashOutlineColor); + break; + case 2: // mFlash == 2 + mLabel->setForegroundColorAll(*mPlayerFlashColor, + *mPlayerFlashOutlineColor); + break; + case 3: // mTabbedArea->isTabSelected(this) + mLabel->setForegroundColorAll(*mTabSelectedColor, + *mTabSelectedOutlineColor); + break; + case 4: // mHasMouse + mLabel->setForegroundColorAll(*mTabHighlightedColor, + *mTabHighlightedOutlineColor); + break; } } } + const Skin *const skin = tabImg[mode]; + if (!skin) + { + BLOCK_END("Tab::draw") + return; + } + + updateAlpha(); + + graphics->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(); + graphics->drawImage(mImage, padding, padding); + } + } + drawChildren(graphics); BLOCK_END("Tab::draw") } diff --git a/src/gui/widgets/tabs/tab.h b/src/gui/widgets/tabs/tab.h index 8b26ee3d4..f4644df08 100644 --- a/src/gui/widgets/tabs/tab.h +++ b/src/gui/widgets/tabs/tab.h @@ -111,6 +111,8 @@ class Tab notfinal : public BasicContainer, */ void draw(Graphics *graphics) override final; + void safeDraw(Graphics *graphics) override final; + /** * Set the normal color for the tab's text. */ -- cgit v1.2.3-60-g2f50