diff options
Diffstat (limited to 'src')
-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 | ||||
-rw-r--r-- | src/main.cpp | 33 |
8 files changed, 119 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... diff --git a/src/main.cpp b/src/main.cpp index 63ba2241..49444d17 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -45,6 +45,7 @@ #include "gui/charselectdialog.h" #include "gui/gui.h" +#include "gui/skin.h" #include "gui/login.h" #include "gui/okdialog.h" #include "gui/palette.h" @@ -1070,6 +1071,10 @@ int main(int argc, char *argv[]) case STATE_CHOOSE_SERVER: logger->log("State: CHOOSE_SERVER"); + // Don't allow an alpha opacity + // lower than the default value + SkinLoader::instance()->setMinimumOpacity(0.8f); + // Allow changing this using a server choice dialog // We show the dialog box only if the command-line // options weren't set. @@ -1109,6 +1114,10 @@ int main(int argc, char *argv[]) case STATE_LOGIN: logger->log("State: LOGIN"); + // Don't allow an alpha opacity + // lower than the default value + SkinLoader::instance()->setMinimumOpacity(0.8f); + if (options.username.empty() || options.password.empty()) { currentDialog = new LoginDialog(&loginData); @@ -1182,6 +1191,10 @@ int main(int argc, char *argv[]) case STATE_CHAR_SELECT: logger->log("State: CHAR_SELECT"); + // Don't allow an alpha opacity + // lower than the default value + SkinLoader::instance()->setMinimumOpacity(0.8f); + currentDialog = new CharSelectDialog(&charInfo, &loginData); @@ -1275,6 +1288,10 @@ int main(int argc, char *argv[]) Net::GameServer::connect(gameServerConnection, token); Net::ChatServer::connect(chatServerConnection, token); + + // Allow any alpha opacity + SkinLoader::instance()->setMinimumOpacity(-1.0f); + sound.fadeOutMusic(1000); delete setupButton; @@ -1341,6 +1358,10 @@ int main(int argc, char *argv[]) break; case STATE_CHAR_SELECT: + // Don't allow an alpha opacity + // lower than the default value + SkinLoader::instance()->setMinimumOpacity(0.8f); + if (state == STATE_CONNECTING) network->disconnect(); break; @@ -1397,6 +1418,10 @@ int main(int argc, char *argv[]) case STATE_LOGIN: logger->log("State: LOGIN"); + // Don't allow an alpha opacity + // lower than the default value + SkinLoader::instance()->setMinimumOpacity(0.8f); + if (!loginData.password.empty()) { loginData.registerLogin = false; @@ -1443,6 +1468,11 @@ int main(int argc, char *argv[]) break; case STATE_CHAR_SELECT: logger->log("State: CHAR_SELECT"); + + // Don't allow an alpha opacity + // lower than the default value + SkinLoader::instance()->setMinimumOpacity(0.8f); + currentDialog = new CharSelectDialog(&charInfo, &loginData); positionDialog(currentDialog, screenWidth, screenHeight); @@ -1472,6 +1502,9 @@ int main(int argc, char *argv[]) desktop = NULL; logger->log("State: GAME"); + // Allow any alpha opacity + SkinLoader::instance()->setMinimumOpacity(-1.0f); + game->logic(); delete game; game = 0; |