diff options
author | Bertram <bertram@cegetel.net> | 2009-09-02 23:40:45 +0200 |
---|---|---|
committer | Bertram <bertram@cegetel.net> | 2009-09-02 23:40:45 +0200 |
commit | efb541eeef2ad839c885c494c3a065f1f7d5dc03 (patch) | |
tree | f8f912a1aa62dfd902153a8dcb3e9d1549ae8e7c /src/gui | |
parent | 63049c5bf3ed38c3cb67edf740ed67f7fed663dd (diff) | |
download | mana-efb541eeef2ad839c885c494c3a065f1f7d5dc03.tar.gz mana-efb541eeef2ad839c885c494c3a065f1f7d5dc03.tar.bz2 mana-efb541eeef2ad839c885c494c3a065f1f7d5dc03.tar.xz mana-efb541eeef2ad839c885c494c3a065f1f7d5dc03.zip |
Added a minimum alpha opacity value handle in SkinLoader and made use of it.
Part 1 of 3 for Mantis #847
Only a few controls follow minimum opacity value at login stage.
Part 2 will make all other controls do the same.
Part 3 will try to set default gui opacity value as a constant.
Diffstat (limited to 'src/gui')
-rw-r--r-- | src/gui/skin.cpp | 20 | ||||
-rw-r--r-- | src/gui/skin.h | 22 | ||||
-rw-r--r-- | src/gui/widgets/button.cpp | 33 | ||||
-rw-r--r-- | src/gui/widgets/button.h | 5 | ||||
-rw-r--r-- | src/gui/widgets/checkbox.cpp | 29 | ||||
-rw-r--r-- | src/gui/widgets/checkbox.h | 5 | ||||
-rw-r--r-- | src/gui/widgets/window.cpp | 2 |
7 files changed, 86 insertions, 30 deletions
diff --git a/src/gui/skin.cpp b/src/gui/skin.cpp index 5881a073..f3f907e1 100644 --- a/src/gui/skin.cpp +++ b/src/gui/skin.cpp @@ -87,9 +87,10 @@ Skin::~Skin() delete mStickyImageDown; } -void Skin::updateAlpha() +void Skin::updateAlpha(float minimumOpacityAllowed) { - const float alpha = config.getValue("guialpha", 0.8); + const float alpha = std::max((double)minimumOpacityAllowed, + config.getValue("guialpha", 0.8f)); for_each(mBorder.grid, mBorder.grid + 9, std::bind2nd(std::mem_fun(&Image::setAlpha), alpha)); @@ -112,7 +113,8 @@ int Skin::getMinHeight() const } SkinLoader::SkinLoader() - : mSkinConfigListener(new SkinConfigListener(this)) + : mSkinConfigListener(new SkinConfigListener(this)), + mMinimumOpacity(-1.0f) { } @@ -174,10 +176,18 @@ Skin *SkinLoader::load(const std::string &filename, return skin; } +void SkinLoader::setMinimumOpacity(float minimumOpacity) +{ + if (minimumOpacity > 1.0f) return; + + mMinimumOpacity = minimumOpacity; + updateAlpha(); +} + void SkinLoader::updateAlpha() { for (SkinIterator iter = mSkins.begin(); iter != mSkins.end(); ++iter) - iter->second->updateAlpha(); + iter->second->updateAlpha(mMinimumOpacity); } Skin *SkinLoader::readSkin(const std::string &filename) @@ -284,6 +294,6 @@ Skin *SkinLoader::readSkin(const std::string &filename) Skin *skin = new Skin(border, closeImage, stickyImageUp, stickyImageDown, filename); - skin->updateAlpha(); + skin->updateAlpha(mMinimumOpacity); return skin; } diff --git a/src/gui/skin.h b/src/gui/skin.h index c56072d3..5f612c26 100644 --- a/src/gui/skin.h +++ b/src/gui/skin.h @@ -82,7 +82,7 @@ class Skin /** * Updates the alpha value of the skin */ - void updateAlpha(); + void updateAlpha(float minimumOpacityAllowed = 0.0f); int instances; @@ -95,7 +95,7 @@ class Skin Image *mStickyImageDown; /**< Sticky Button Image */ }; -class SkinLoader +class SkinLoader { public: static SkinLoader *instance(); @@ -112,6 +112,18 @@ class SkinLoader */ void updateAlpha(); + /** + * Get the minimum opacity allowed to skins. + */ + float getMinimumOpacity() + { return mMinimumOpacity; } + + /** + * Set the minimum opacity allowed to skins. + * Set a negative value to free the minimum allowed. + */ + void setMinimumOpacity(float minimumOpacity); + private: SkinLoader(); ~SkinLoader(); @@ -130,6 +142,12 @@ class SkinLoader ConfigListener *mSkinConfigListener; static SkinLoader *mInstance; + + /** + * Tells if the current skins opacity + * should not get less than the given value + */ + float mMinimumOpacity; }; #endif diff --git a/src/gui/widgets/button.cpp b/src/gui/widgets/button.cpp index 2357b263..9f44cdfc 100644 --- a/src/gui/widgets/button.cpp +++ b/src/gui/widgets/button.cpp @@ -28,6 +28,7 @@ #include "resources/image.h" #include "resources/resourcemanager.h" +#include "gui/skin.h" #include "utils/dtor.h" @@ -101,12 +102,12 @@ void Button::init() data[x].gridX, data[y].gridY, data[x + 1].gridX - data[x].gridX + 1, data[y + 1].gridY - data[y].gridY + 1); - button[mode].grid[a]->setAlpha(mAlpha); a++; } } btn[mode]->decRef(); } + updateAlpha(); } mInstances++; } @@ -124,6 +125,24 @@ Button::~Button() } } +void Button::updateAlpha() +{ + float alpha = std::max(config.getValue("guialpha", 0.8f), + (double)SkinLoader::instance()->getMinimumOpacity()); + + if (mAlpha != alpha) + { + mAlpha = alpha; + for (int a = 0; a < 9; a++) + { + button[BUTTON_DISABLED].grid[a]->setAlpha(mAlpha); + button[BUTTON_PRESSED].grid[a]->setAlpha(mAlpha); + button[BUTTON_HIGHLIGHTED].grid[a]->setAlpha(mAlpha); + button[BUTTON_STANDARD].grid[a]->setAlpha(mAlpha); + } + } +} + void Button::draw(gcn::Graphics *graphics) { int mode; @@ -137,17 +156,7 @@ void Button::draw(gcn::Graphics *graphics) else mode = BUTTON_STANDARD; - if (config.getValue("guialpha", 0.8) != mAlpha) - { - mAlpha = config.getValue("guialpha", 0.8); - for (int a = 0; a < 9; a++) - { - button[BUTTON_DISABLED].grid[a]->setAlpha(mAlpha); - button[BUTTON_PRESSED].grid[a]->setAlpha(mAlpha); - button[BUTTON_HIGHLIGHTED].grid[a]->setAlpha(mAlpha); - button[BUTTON_STANDARD].grid[a]->setAlpha(mAlpha); - } - } + updateAlpha(); static_cast<Graphics*>(graphics)-> drawImageRect(0, 0, getWidth(), getHeight(), button[mode]); diff --git a/src/gui/widgets/button.h b/src/gui/widgets/button.h index eebf7931..7eb7e2ef 100644 --- a/src/gui/widgets/button.h +++ b/src/gui/widgets/button.h @@ -56,6 +56,11 @@ class Button : public gcn::Button */ void draw(gcn::Graphics *graphics); + /** + * Update the alpha value to the button components. + */ + void updateAlpha(); + private: void init(); diff --git a/src/gui/widgets/checkbox.cpp b/src/gui/widgets/checkbox.cpp index dd57f674..9b4ab2f4 100644 --- a/src/gui/widgets/checkbox.cpp +++ b/src/gui/widgets/checkbox.cpp @@ -28,6 +28,7 @@ #include "resources/image.h" #include "resources/resourcemanager.h" +#include "gui/skin.h" int CheckBox::instances = 0; float CheckBox::mAlpha = 1.0; @@ -91,6 +92,23 @@ void CheckBox::draw(gcn::Graphics* graphics) graphics->drawText(getCaption(), h - 2, 0); } +void CheckBox::updateAlpha() +{ + float alpha = std::max(config.getValue("guialpha", 0.8f), + (double)SkinLoader::instance()->getMinimumOpacity()); + + if (mAlpha != alpha) + { + mAlpha = alpha; + checkBoxNormal->setAlpha(mAlpha); + checkBoxChecked->setAlpha(mAlpha); + checkBoxDisabled->setAlpha(mAlpha); + checkBoxDisabledChecked->setAlpha(mAlpha); + checkBoxNormal->setAlpha(mAlpha); + checkBoxCheckedHi->setAlpha(mAlpha); + } +} + void CheckBox::drawBox(gcn::Graphics* graphics) { Image *box; @@ -112,16 +130,7 @@ void CheckBox::drawBox(gcn::Graphics* graphics) else box = checkBoxDisabled; - if (config.getValue("guialpha", 0.8) != mAlpha) - { - mAlpha = config.getValue("guialpha", 0.8); - checkBoxNormal->setAlpha(mAlpha); - checkBoxChecked->setAlpha(mAlpha); - checkBoxDisabled->setAlpha(mAlpha); - checkBoxDisabledChecked->setAlpha(mAlpha); - checkBoxNormal->setAlpha(mAlpha); - checkBoxCheckedHi->setAlpha(mAlpha); - } + updateAlpha(); static_cast<Graphics*>(graphics)->drawImage(box, 2, 2); } diff --git a/src/gui/widgets/checkbox.h b/src/gui/widgets/checkbox.h index 7a7c8674..a65a5196 100644 --- a/src/gui/widgets/checkbox.h +++ b/src/gui/widgets/checkbox.h @@ -51,6 +51,11 @@ class CheckBox : public gcn::CheckBox void draw(gcn::Graphics* graphics); /** + * Update the alpha value to the checkbox components. + */ + void updateAlpha(); + + /** * Draws the check box, not the caption. */ void drawBox(gcn::Graphics* graphics); diff --git a/src/gui/widgets/window.cpp b/src/gui/widgets/window.cpp index 1ee84a6f..9c098bdb 100644 --- a/src/gui/widgets/window.cpp +++ b/src/gui/widgets/window.cpp @@ -750,7 +750,7 @@ void Window::center() void Window::checkIfIsOffScreen(bool partially, bool entirely) { // Move the window onto screen if it has become off screen - // For instance, because of resolution change... + // For instance, because of resolution change... // First of all, don't deal when a window hasn't got // any size initialized yet... |