diff options
Diffstat (limited to 'src/gui/widgets')
-rw-r--r-- | src/gui/widgets/label.cpp | 38 | ||||
-rw-r--r-- | src/gui/widgets/label.h | 9 | ||||
-rw-r--r-- | src/gui/widgets/tabs/tab.cpp | 57 | ||||
-rw-r--r-- | src/gui/widgets/tabs/tab.h | 1 |
4 files changed, 81 insertions, 24 deletions
diff --git a/src/gui/widgets/label.cpp b/src/gui/widgets/label.cpp index 8b074a0b1..65e7f86d0 100644 --- a/src/gui/widgets/label.cpp +++ b/src/gui/widgets/label.cpp @@ -78,8 +78,10 @@ Label::Label(const Widget2 *const widget) : Widget(widget), ToolTipListener(), mCaption(), + mTextChunk(), mAlignment(Graphics::LEFT), - mPadding(0) + mPadding(0), + mTextChanged(true) { init(); } @@ -89,8 +91,10 @@ Label::Label(const Widget2 *const widget, Widget(widget), ToolTipListener(), mCaption(caption), + mTextChunk(), mAlignment(Graphics::LEFT), - mPadding(0) + mPadding(0), + mTextChanged(true) { const Font *const font = getFont(); if (font) @@ -113,6 +117,7 @@ Label::~Label() theme->unload(mSkin); } removeMouseListener(this); + mTextChunk.deleteImage(); } void Label::init() @@ -160,7 +165,21 @@ void Label::draw(Graphics* graphics) } graphics->setColorAll(mForegroundColor, mForegroundColor2); - font->drawString(graphics, mCaption, textX, textY); + if (mTextChanged) + { + mTextChunk.textFont = font; + mTextChunk.deleteImage(); + mTextChunk.text = mCaption; + mTextChunk.color = mForegroundColor; + mTextChunk.color2 = mForegroundColor2; + font->generate(mTextChunk); + mTextChanged = false; + } + + const Image *const image = mTextChunk.img; + if (image) + graphics->drawImage(image, textX, textY); +// font->drawString(graphics, mCaption, textX, textY); BLOCK_END("Label::draw") } @@ -174,6 +193,9 @@ void Label::adjustSize() void Label::setForegroundColor(const Color &color) { + if (mForegroundColor != color || mForegroundColor2 != color) + mTextChanged = true; +// logger->log("Label::setForegroundColor: " + mCaption); mForegroundColor = color; mForegroundColor2 = color; } @@ -181,6 +203,9 @@ void Label::setForegroundColor(const Color &color) void Label::setForegroundColorAll(const Color &color1, const Color &color2) { + if (mForegroundColor != color1 || mForegroundColor2 != color2) + mTextChanged = true; +// logger->log("Label::setForegroundColorAll: " + mCaption); mForegroundColor = color1; mForegroundColor2 = color2; } @@ -221,3 +246,10 @@ void Label::resizeTo(const int maxSize, const int minSize) setWidth(sz); } } + +void Label::setCaption(const std::string& caption) +{ + if (caption != mCaption) + mTextChanged = true; + mCaption = caption; +} diff --git a/src/gui/widgets/label.h b/src/gui/widgets/label.h index 681908b71..9e82f0a5d 100644 --- a/src/gui/widgets/label.h +++ b/src/gui/widgets/label.h @@ -65,6 +65,8 @@ #ifndef GUI_WIDGETS_LABEL_H #define GUI_WIDGETS_LABEL_H +#include "gui/fonts/textchunk.h" + #include "gui/widgets/widget.h" #include "listeners/tooltiplistener.h" @@ -132,8 +134,7 @@ class Label final : public Widget, * @param caption The caption of the label. * @see getCaption, adjustSize */ - void setCaption(const std::string& caption) - { mCaption = caption; } + void setCaption(const std::string& caption); /** * Sets the alignment of the caption. The alignment is relative @@ -165,12 +166,16 @@ class Label final : public Widget, */ std::string mCaption; + TextChunk mTextChunk; + /** * Holds the alignment of the caption. */ Graphics::Alignment mAlignment; int mPadding; + + bool mTextChanged; }; #endif // GUI_WIDGETS_LABEL_H diff --git a/src/gui/widgets/tabs/tab.cpp b/src/gui/widgets/tabs/tab.cpp index 2f300fb5f..e361c78ff 100644 --- a/src/gui/widgets/tabs/tab.cpp +++ b/src/gui/widgets/tabs/tab.cpp @@ -120,6 +120,7 @@ Tab::Tab(const Widget2 *const widget) : mVertexes(new ImageCollection), mImage(nullptr), mMode(0), + mLabelMode(-1), mHasMouse(false) { init(); @@ -211,37 +212,55 @@ void Tab::draw(Graphics *graphics) // check which type of tab to draw if (mTabbedArea) { + int labelMode = mFlash; + if (mTabbedArea->isTabSelected(this)) { - mLabel->setForegroundColorAll(*mTabSelectedColor, - *mTabSelectedOutlineColor); + labelMode = 3; mode = TAB_SELECTED; // if tab is selected, it doesnt need to highlight activity mFlash = 0; } - else if (mHasMouse) + else if (!labelMode) { - mLabel->setForegroundColorAll(*mTabHighlightedColor, - *mTabHighlightedOutlineColor); - mode = TAB_HIGHLIGHTED; + if (mHasMouse) + { + labelMode = 4; + mode = TAB_HIGHLIGHTED; + } } - else + else if (mHasMouse) { - mLabel->setForegroundColorAll(*mTabColor, *mTabOutlineColor); + mode = TAB_HIGHLIGHTED; } - switch (mFlash) + if (labelMode != mLabelMode) { - case 1: - mLabel->setForegroundColorAll(*mFlashColor, - *mFlashOutlineColor); - break; - case 2: - mLabel->setForegroundColorAll(*mPlayerFlashColor, - *mPlayerFlashOutlineColor); - break; - default: - break; + 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; + } } } diff --git a/src/gui/widgets/tabs/tab.h b/src/gui/widgets/tabs/tab.h index 06b5a3d18..8b26ee3d4 100644 --- a/src/gui/widgets/tabs/tab.h +++ b/src/gui/widgets/tabs/tab.h @@ -228,6 +228,7 @@ class Tab notfinal : public BasicContainer, ImageCollection *mVertexes; Image *mImage; int mMode; + int mLabelMode; protected: bool mHasMouse; |