diff options
Diffstat (limited to 'src/gui/widgets')
-rw-r--r-- | src/gui/widgets/tab.cpp | 10 | ||||
-rw-r--r-- | src/gui/widgets/textpreview.cpp | 36 | ||||
-rw-r--r-- | src/gui/widgets/textpreview.h | 30 |
3 files changed, 68 insertions, 8 deletions
diff --git a/src/gui/widgets/tab.cpp b/src/gui/widgets/tab.cpp index 3a79dd91..7a2d9ee8 100644 --- a/src/gui/widgets/tab.cpp +++ b/src/gui/widgets/tab.cpp @@ -24,6 +24,8 @@ #include "tab.h" #include "tabbedarea.h" +#include "../palette.h" + #include "../../configuration.h" #include "../../graphics.h" @@ -123,13 +125,17 @@ void Tab::draw(gcn::Graphics *graphics) { mode = TAB_SELECTED; // if tab is selected, it doesnt need to highlight activity - mLabel->setForegroundColor(gcn::Color(0, 0, 0)); + mLabel->setForegroundColor(guiPalette->getColor(Palette::TEXT)); mHighlighted = false; } else if (mHighlighted) { mode = TAB_HIGHLIGHTED; - mLabel->setForegroundColor(gcn::Color(255, 0, 0)); + mLabel->setForegroundColor(guiPalette->getColor(Palette::TAB_HIGHLIGHT)); + } + else + { + mLabel->setForegroundColor(guiPalette->getColor(Palette::TEXT)); } } diff --git a/src/gui/widgets/textpreview.cpp b/src/gui/widgets/textpreview.cpp index 4fcaa4a7..01790a67 100644 --- a/src/gui/widgets/textpreview.cpp +++ b/src/gui/widgets/textpreview.cpp @@ -28,28 +28,54 @@ #include "../textrenderer.h" #include "../truetypefont.h" +#include "../../configuration.h" + +float TextPreview::mAlpha = config.getValue("guialpha", 0.8); + TextPreview::TextPreview(const std::string* text) { mText = text; + mTextAlpha = false; mFont = gui->getFont(); mTextColor = &guiPalette->getColor(Palette::TEXT); mTextBGColor = NULL; mBGColor = &guiPalette->getColor(Palette::BACKGROUND); + mOpaque = false; } void TextPreview::draw(gcn::Graphics* graphics) { - graphics->setColor(*mBGColor); - graphics->fillRectangle(gcn::Rectangle(0, 0, getWidth(), getHeight())); + if (config.getValue("guialpha", 0.8) != mAlpha) + mAlpha = config.getValue("guialpha", 0.8); + + int alpha = (int) (mAlpha * 255.0f); + + if (!mTextAlpha) + alpha = 255; + + if (mOpaque) + { + graphics->setColor(gcn::Color((int) mBGColor->r, + (int) mBGColor->g, + (int) mBGColor->b, + (int)(mAlpha * 255.0f))); + graphics->fillRectangle(gcn::Rectangle(0, 0, getWidth(), getHeight())); + } - if (mTextBGColor && typeid(*mFont) == typeid(TrueTypeFont)) { + if (mTextBGColor && typeid(*mFont) == typeid(TrueTypeFont)) + { TrueTypeFont *font = static_cast<TrueTypeFont*>(mFont); - graphics->setColor(*mTextBGColor); int x = font->getWidth(*mText) + 1 + 2 * ((mOutline || mShadow) ? 1 :0); int y = font->getHeight() + 1 + 2 * ((mOutline || mShadow) ? 1 : 0); + graphics->setColor(gcn::Color((int) mTextBGColor->r, + (int) mTextBGColor->g, + (int) mTextBGColor->b, + (int)(mAlpha * 255.0f))); graphics->fillRectangle(gcn::Rectangle(1, 1, x, y)); } TextRenderer::renderText(graphics, *mText, 2, 2, gcn::Graphics::LEFT, - mTextColor, mFont, mOutline, mShadow); + gcn::Color(mTextColor->r, mTextColor->g, + mTextColor->b, alpha), + mFont, mOutline, mShadow, alpha); } diff --git a/src/gui/widgets/textpreview.h b/src/gui/widgets/textpreview.h index 1c1fa1e4..e7b7db80 100644 --- a/src/gui/widgets/textpreview.h +++ b/src/gui/widgets/textpreview.h @@ -29,7 +29,8 @@ /** * Preview widget for particle colors, etc. */ -class TextPreview : public gcn::Widget { +class TextPreview : public gcn::Widget +{ public: TextPreview(const std::string* text); @@ -44,6 +45,16 @@ class TextPreview : public gcn::Widget { } /** + * Sets the text to use the set alpha value. + * + * @param alpha whether to use alpha values for the text or not + */ + inline void useTextAlpha(bool alpha) + { + mTextAlpha = alpha; + } + + /** * Sets the color the text background is drawn in. This is only the * rectangle directly behind the text, not to full widget. * @@ -101,12 +112,29 @@ class TextPreview : public gcn::Widget { */ void draw(gcn::Graphics *graphics); + /** + * Set opacity for this widget (whether or not to show the background + * color) + * + * @param opaque Whether the widget should be opaque or not + */ + void setOpaque(bool opaque) { mOpaque = opaque; } + + /** + * Gets opacity for this widget (whether or not the background color + * is shown below the widget) + */ + bool isOpaque() { return mOpaque; } + private: gcn::Font *mFont; const std::string* mText; const gcn::Color* mTextColor; const gcn::Color* mBGColor; const gcn::Color* mTextBGColor; + static float mAlpha; + bool mTextAlpha; + bool mOpaque; bool mShadow; bool mOutline; }; |