From 78ab7c7a2877efd245293ad00cd36bcaa8646507 Mon Sep 17 00:00:00 2001 From: Jared Adams Date: Fri, 5 Mar 2010 07:39:43 -0700 Subject: Rename SkinLoader to Theme MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Also merge the guialpha ConfigListener into Theme. Reviewed-by: Thorbjørn Lindeijer --- mana.cbp | 4 +- mana.files | 6 +- src/CMakeLists.txt | 4 +- src/Makefile.am | 4 +- src/client.cpp | 12 +- src/gui/emotepopup.cpp | 4 +- src/gui/gui.cpp | 7 +- src/gui/skilldialog.cpp | 4 +- src/gui/skin.cpp | 367 ----------------------------- src/gui/skin.h | 170 ------------- src/gui/specialswindow.cpp | 4 +- src/gui/speechbubble.cpp | 2 +- src/gui/theme.cpp | 345 +++++++++++++++++++++++++++ src/gui/theme.h | 172 ++++++++++++++ src/gui/widgets/avatarlistbox.cpp | 6 +- src/gui/widgets/button.cpp | 6 +- src/gui/widgets/checkbox.cpp | 6 +- src/gui/widgets/dropdown.cpp | 18 +- src/gui/widgets/emoteshortcutcontainer.cpp | 4 +- src/gui/widgets/itemcontainer.cpp | 4 +- src/gui/widgets/itemshortcutcontainer.cpp | 4 +- src/gui/widgets/listbox.cpp | 4 +- src/gui/widgets/playerbox.cpp | 4 +- src/gui/widgets/popup.cpp | 6 +- src/gui/widgets/progressbar.cpp | 6 +- src/gui/widgets/progressindicator.cpp | 6 +- src/gui/widgets/radiobutton.cpp | 14 +- src/gui/widgets/resizegrip.cpp | 4 +- src/gui/widgets/scrollarea.cpp | 26 +- src/gui/widgets/slider.cpp | 8 +- src/gui/widgets/tab.cpp | 6 +- src/gui/widgets/textfield.cpp | 6 +- src/gui/widgets/window.cpp | 8 +- src/item.cpp | 6 +- src/localplayer.cpp | 6 +- src/text.cpp | 4 +- 36 files changed, 621 insertions(+), 646 deletions(-) delete mode 100644 src/gui/skin.cpp delete mode 100644 src/gui/skin.h create mode 100644 src/gui/theme.cpp create mode 100644 src/gui/theme.h diff --git a/mana.cbp b/mana.cbp index 6b5e6dd8..f589f5db 100644 --- a/mana.cbp +++ b/mana.cbp @@ -215,8 +215,6 @@ - - @@ -229,6 +227,8 @@ + + diff --git a/mana.files b/mana.files index 7f775498..b3f647a2 100644 --- a/mana.files +++ b/mana.files @@ -5,9 +5,9 @@ ./data/fonts/Makefile.am ./data/graphics/CMakeLists.txt ./data/graphics/gui/CMakeLists.txt -./data/graphics/gui/gui.xml ./data/graphics/gui/Makefile.am ./data/graphics/gui/speechbubble.xml +./data/graphics/gui/window.xml ./data/graphics/images/CMakeLists.txt ./data/graphics/images/Makefile.am ./data/graphics/Makefile.am @@ -161,8 +161,6 @@ ./src/gui/shortcutwindow.h ./src/gui/skilldialog.cpp ./src/gui/skilldialog.h -./src/gui/skin.cpp -./src/gui/skin.h ./src/gui/socialwindow.cpp ./src/gui/socialwindow.h ./src/gui/specialswindow.cpp @@ -175,6 +173,8 @@ ./src/gui/storagewindow.h ./src/gui/textdialog.cpp ./src/gui/textdialog.h +./src/gui/theme.cpp +./src/gui/theme.h ./src/gui/trade.cpp ./src/gui/trade.h ./src/gui/truetypefont.cpp diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index b84e59c6..68147db7 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -282,8 +282,6 @@ SET(SRCS gui/shortcutwindow.h gui/skilldialog.cpp gui/skilldialog.h - gui/skin.cpp - gui/skin.h gui/socialwindow.cpp gui/socialwindow.h gui/speechbubble.cpp @@ -296,6 +294,8 @@ SET(SRCS gui/storagewindow.h gui/textdialog.cpp gui/textdialog.h + gui/theme.cpp + gui/theme.h gui/trade.cpp gui/trade.h gui/truetypefont.cpp diff --git a/src/Makefile.am b/src/Makefile.am index f36fcdf2..55937c0c 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -181,8 +181,6 @@ mana_SOURCES = gui/widgets/avatarlistbox.cpp \ gui/shortcutwindow.h \ gui/skilldialog.cpp \ gui/skilldialog.h \ - gui/skin.cpp \ - gui/skin.h \ gui/socialwindow.cpp \ gui/socialwindow.h \ gui/speechbubble.cpp \ @@ -195,6 +193,8 @@ mana_SOURCES = gui/widgets/avatarlistbox.cpp \ gui/storagewindow.h \ gui/textdialog.cpp \ gui/textdialog.h \ + gui/theme.cpp \ + gui/theme.h \ gui/trade.cpp \ gui/trade.h \ gui/truetypefont.cpp \ diff --git a/src/client.cpp b/src/client.cpp index dfa42034..1b9dcd4c 100644 --- a/src/client.cpp +++ b/src/client.cpp @@ -40,7 +40,6 @@ #include "gui/charselectdialog.h" #include "gui/connectiondialog.h" #include "gui/gui.h" -#include "gui/skin.h" #include "gui/login.h" #include "gui/okdialog.h" #include "gui/palette.h" @@ -49,6 +48,7 @@ #include "gui/sdlinput.h" #include "gui/serverdialog.h" #include "gui/setup.h" +#include "gui/theme.h" #include "gui/unregisterdialog.h" #include "gui/updatewindow.h" #include "gui/worldselectdialog.h" @@ -340,7 +340,7 @@ Client::Client(const Options &options): // Initialize for drawing graphics->_beginDraw(); - SkinLoader::prepareThemePath(); + Theme::prepareThemePath(); // Initialize the item and emote shortcuts. itemShortcut = new ItemShortcut; @@ -601,7 +601,7 @@ int Client::exec() { // Don't allow an alpha opacity // lower than the default value - SkinLoader::instance()->setMinimumOpacity(0.8f); + Theme::instance()->setMinimumOpacity(0.8f); mCurrentDialog = new ServerDialog(&mCurrentServer, mConfigDir); @@ -627,7 +627,7 @@ int Client::exec() logger->log("State: LOGIN"); // Don't allow an alpha opacity // lower than the default value - SkinLoader::instance()->setMinimumOpacity(0.8f); + Theme::instance()->setMinimumOpacity(0.8f); if (mOptions.username.empty() || mOptions.password.empty()) @@ -744,7 +744,7 @@ int Client::exec() logger->log("State: CHAR SELECT"); // Don't allow an alpha opacity // lower than the default value - SkinLoader::instance()->setMinimumOpacity(0.8f); + Theme::instance()->setMinimumOpacity(0.8f); mCurrentDialog = new CharSelectDialog(&loginData); @@ -781,7 +781,7 @@ int Client::exec() sound.fadeOutMusic(1000); // Allow any alpha opacity - SkinLoader::instance()->setMinimumOpacity(-1.0f); + Theme::instance()->setMinimumOpacity(-1.0f); delete mSetupButton; delete mDesktop; diff --git a/src/gui/emotepopup.cpp b/src/gui/emotepopup.cpp index 2161e04c..7c05e263 100644 --- a/src/gui/emotepopup.cpp +++ b/src/gui/emotepopup.cpp @@ -29,7 +29,7 @@ #include "localplayer.h" #include "log.h" -#include "gui/skin.h" +#include "gui/theme.h" #include "resources/emotedb.h" #include "resources/image.h" @@ -57,7 +57,7 @@ EmotePopup::EmotePopup(): mEmotes.push_back(EmoteDB::getAnimation(i)); } - mSelectionImage = SkinLoader::getImageFromTheme("selection.png"); + mSelectionImage = Theme::getImageFromTheme("selection.png"); if (!mSelectionImage) logger->error("Unable to load selection.png"); diff --git a/src/gui/gui.cpp b/src/gui/gui.cpp index 1e36523c..a59b0157 100644 --- a/src/gui/gui.cpp +++ b/src/gui/gui.cpp @@ -24,7 +24,7 @@ #include "gui/focushandler.h" #include "gui/palette.h" #include "gui/sdlinput.h" -#include "gui/skin.h" +#include "gui/theme.h" #include "gui/truetypefont.h" #include "gui/widgets/window.h" @@ -154,7 +154,7 @@ Gui::~Gui() delete guiInput; - SkinLoader::deleteInstance(); + Theme::deleteInstance(); } void Gui::logic() @@ -209,8 +209,7 @@ void Gui::setUseCustomCursor(bool customCursor) SDL_ShowCursor(SDL_DISABLE); // Load the mouse cursor - mMouseCursors = SkinLoader::getImageSetFromTheme("mouse.png", - 40, 40); + mMouseCursors = Theme::getImageSetFromTheme("mouse.png", 40, 40); if (!mMouseCursors) logger->error("Unable to load mouse cursors."); diff --git a/src/gui/skilldialog.cpp b/src/gui/skilldialog.cpp index 09c7ccb2..76ddd7b0 100644 --- a/src/gui/skilldialog.cpp +++ b/src/gui/skilldialog.cpp @@ -25,7 +25,7 @@ #include "log.h" #include "gui/setup.h" -#include "gui/skin.h" +#include "gui/theme.h" #include "gui/widgets/button.h" #include "gui/widgets/container.h" @@ -86,7 +86,7 @@ struct SkillInfo } else { - icon = SkinLoader::getImageFromTheme("unknown-item.png"); + icon = Theme::getImageFromTheme("unknown-item.png"); } } diff --git a/src/gui/skin.cpp b/src/gui/skin.cpp deleted file mode 100644 index 22153720..00000000 --- a/src/gui/skin.cpp +++ /dev/null @@ -1,367 +0,0 @@ -/* - * Gui Skinning - * Copyright (C) 2008 The Legend of Mazzeroth Development Team - * Copyright (C) 2009 Aethyra Development Team - * Copyright (C) 2009 The Mana World Development Team - * Copyright (C) 2009-2010 The Mana Developers - * - * This file is part of The Mana Client. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#include "gui/skin.h" - -#include "client.h" -#include "configuration.h" -#include "configlistener.h" -#include "log.h" - -#include "resources/image.h" -#include "resources/imageset.h" -#include "resources/resourcemanager.h" - -#include "utils/dtor.h" -#include "utils/stringutils.h" -#include "utils/xml.h" - -#include - -#include - -std::string SkinLoader::mThemePath; -SkinLoader *SkinLoader::mInstance = 0; - -class SkinConfigListener : public ConfigListener -{ - public: - SkinConfigListener(SkinLoader *skinLoader) - : mSkinLoader(skinLoader) - { - config.addListener("guialpha", this); - } - - ~SkinConfigListener() - { - config.removeListener("guialpha", this); - } - - void optionChanged(const std::string &) - { - mSkinLoader->updateAlpha(); - } - - private: - SkinLoader *mSkinLoader; -}; - - -Skin::Skin(ImageRect skin, Image *close, Image *stickyUp, Image *stickyDown, - const std::string &filePath, - const std::string &name): - instances(0), - mFilePath(filePath), - mName(name), - mBorder(skin), - mCloseImage(close), - mStickyImageUp(stickyUp), - mStickyImageDown(stickyDown) -{ -} - -Skin::~Skin() -{ - // Clean up static resources - for (int i = 0; i < 9; i++) - delete mBorder.grid[i]; - - mCloseImage->decRef(); - delete mStickyImageUp; - delete mStickyImageDown; -} - -void Skin::updateAlpha(float minimumOpacityAllowed) -{ - 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)); - - mCloseImage->setAlpha(alpha); - mStickyImageUp->setAlpha(alpha); - mStickyImageDown->setAlpha(alpha); -} - -int Skin::getMinWidth() const -{ - return mBorder.grid[ImageRect::UPPER_LEFT]->getWidth() + - mBorder.grid[ImageRect::UPPER_RIGHT]->getWidth(); -} - -int Skin::getMinHeight() const -{ - return mBorder.grid[ImageRect::UPPER_LEFT]->getHeight() + - mBorder.grid[ImageRect::LOWER_LEFT]->getHeight(); -} - -SkinLoader::SkinLoader() - : mSkinConfigListener(new SkinConfigListener(this)), - mMinimumOpacity(-1.0f) -{ -} - -SkinLoader::~SkinLoader() -{ - delete_all(mSkins); - delete mSkinConfigListener; -} - -SkinLoader *SkinLoader::instance() -{ - if (!mInstance) - mInstance = new SkinLoader; - - return mInstance; -} - -void SkinLoader::deleteInstance() -{ - delete mInstance; - mInstance = 0; -} - -Skin *SkinLoader::load(const std::string &filename, - const std::string &defaultPath) -{ - // Check if this skin was already loaded - SkinIterator skinIterator = mSkins.find(filename); - if (mSkins.end() != skinIterator) - { - skinIterator->second->instances++; - return skinIterator->second; - } - - Skin *skin = readSkin(filename); - - if (!skin) - { - // Try falling back on the defaultPath if this makes sense - if (filename != defaultPath) - { - logger->log("Error loading skin '%s', falling back on default.", - filename.c_str()); - - skin = readSkin(defaultPath); - } - - if (!skin) - { - logger->error(strprintf("Error: Loading default skin '%s' failed. " - "Make sure the skin file is valid.", - defaultPath.c_str())); - } - } - - // Add the skin to the loaded skins - mSkins[filename] = skin; - - 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(mMinimumOpacity); -} - -Skin *SkinLoader::readSkin(const std::string &filename) -{ - if (filename.empty()) - return 0; - - logger->log("Loading skin '%s'.", filename.c_str()); - - XML::Document doc(resolveThemePath(filename)); - xmlNodePtr rootNode = doc.rootNode(); - - if (!rootNode || !xmlStrEqual(rootNode->name, BAD_CAST "skinset")) - return 0; - - const std::string skinSetImage = XML::getProperty(rootNode, "image", ""); - - if (skinSetImage.empty()) - { - logger->log("SkinLoader::readSkin(): Skinset does not define an " - "image!"); - return 0; - } - - logger->log("SkinLoader::load(): defines " - "'%s' as a skin image.", skinSetImage.c_str()); - - Image *dBorders = SkinLoader::getImageFromTheme(skinSetImage); - ImageRect border; - - // iterate 's - for_each_xml_child_node(widgetNode, rootNode) - { - if (!xmlStrEqual(widgetNode->name, BAD_CAST "widget")) - continue; - - const std::string widgetType = - XML::getProperty(widgetNode, "type", "unknown"); - if (widgetType == "Window") - { - // Iterate through 's - // LEEOR / TODO: - // We need to make provisions to load in a CloseButton image. For - // now it can just be hard-coded. - for_each_xml_child_node(partNode, widgetNode) - { - if (!xmlStrEqual(partNode->name, BAD_CAST "part")) - continue; - - const std::string partType = - XML::getProperty(partNode, "type", "unknown"); - // TOP ROW - const int xPos = XML::getProperty(partNode, "xpos", 0); - const int yPos = XML::getProperty(partNode, "ypos", 0); - const int width = XML::getProperty(partNode, "width", 1); - const int height = XML::getProperty(partNode, "height", 1); - - if (partType == "top-left-corner") - border.grid[0] = dBorders->getSubImage(xPos, yPos, width, height); - else if (partType == "top-edge") - border.grid[1] = dBorders->getSubImage(xPos, yPos, width, height); - else if (partType == "top-right-corner") - border.grid[2] = dBorders->getSubImage(xPos, yPos, width, height); - - // MIDDLE ROW - else if (partType == "left-edge") - border.grid[3] = dBorders->getSubImage(xPos, yPos, width, height); - else if (partType == "bg-quad") - border.grid[4] = dBorders->getSubImage(xPos, yPos, width, height); - else if (partType == "right-edge") - border.grid[5] = dBorders->getSubImage(xPos, yPos, width, height); - - // BOTTOM ROW - else if (partType == "bottom-left-corner") - border.grid[6] = dBorders->getSubImage(xPos, yPos, width, height); - else if (partType == "bottom-edge") - border.grid[7] = dBorders->getSubImage(xPos, yPos, width, height); - else if (partType == "bottom-right-corner") - border.grid[8] = dBorders->getSubImage(xPos, yPos, width, height); - - else - logger->log("SkinLoader::readSkin(): Unknown part type '%s'", - partType.c_str()); - } - } - else - { - logger->log("SkinLoader::readSkin(): Unknown widget type '%s'", - widgetType.c_str()); - } - } - - dBorders->decRef(); - - logger->log("Finished loading skin."); - - // Hard-coded for now until we update the above code to look for window buttons - Image *closeImage = SkinLoader::getImageFromTheme("close_button.png"); - Image *sticky = SkinLoader::getImageFromTheme("sticky_button.png"); - Image *stickyImageUp = sticky->getSubImage(0, 0, 15, 15); - Image *stickyImageDown = sticky->getSubImage(15, 0, 15, 15); - sticky->decRef(); - - Skin *skin = new Skin(border, closeImage, stickyImageUp, stickyImageDown, - filename); - skin->updateAlpha(mMinimumOpacity); - return skin; -} - -bool SkinLoader::tryThemePath(std::string themePath) -{ - if (!themePath.empty()) - { - themePath = "graphics/gui/" + themePath; - if (PHYSFS_exists(themePath.c_str())) - { - mThemePath = themePath; - return true; - } - } - - return false; -} - -void SkinLoader::prepareThemePath() -{ - // Try theme from settings - if (tryThemePath(config.getValue("theme", ""))) - return; - - // Try theme from branding - if (tryThemePath(branding.getValue("theme", ""))) - return; - - // Use default - mThemePath = "graphics/gui"; -} - -std::string SkinLoader::resolveThemePath(const std::string &path) -{ - // Need to strip off any dye info for the existence tests - int pos = path.find('|'); - std::string file; - if (pos > 0) - file = path.substr(0, pos); - else - file = path; - - // Might be a valid path already - if (PHYSFS_exists(file.c_str())) - return path; - - // Try the theme - file = getThemePath() + "/" + file; - if (PHYSFS_exists(file.c_str())) - return getThemePath() + "/" + path; - - // Backup - return "graphics/gui/" + path; -} - -Image *SkinLoader::getImageFromTheme(const std::string &path) -{ - ResourceManager *resman = ResourceManager::getInstance(); - return resman->getImage(resolveThemePath(path)); -} - -ImageSet *SkinLoader::getImageSetFromTheme(const std::string &path, - int w, int h) -{ - ResourceManager *resman = ResourceManager::getInstance(); - return resman->getImageSet(resolveThemePath(path), w, h); -} diff --git a/src/gui/skin.h b/src/gui/skin.h deleted file mode 100644 index 091d3001..00000000 --- a/src/gui/skin.h +++ /dev/null @@ -1,170 +0,0 @@ -/* - * Gui Skinning - * Copyright (C) 2008 The Legend of Mazzeroth Development Team - * Copyright (C) 2009 Aethyra Development Team - * Copyright (C) 2009 The Mana World Development Team - * Copyright (C) 2009-2010 The Mana Developers - * - * This file is part of The Mana Client. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#ifndef SKIN_H -#define SKIN_H - -#include "graphics.h" - -#include -#include - -class ConfigListener; -class Image; -class ImageSet; - -class Skin -{ - public: - Skin(ImageRect skin, Image *close, Image *stickyUp, Image *stickyDown, - const std::string &filePath, - const std::string &name = ""); - - ~Skin(); - - /** - * Returns the skin's name. Useful for giving a human friendly skin - * name if a dialog for skin selection for a specific window type is - * done. - */ - const std::string &getName() const { return mName; } - - /** - * Returns the skin's xml file path. - */ - const std::string &getFilePath() const { return mFilePath; } - - /** - * Returns the background skin. - */ - const ImageRect &getBorder() const { return mBorder; } - - /** - * Returns the image used by a close button for this skin. - */ - Image *getCloseImage() const { return mCloseImage; } - - /** - * Returns the image used by a sticky button for this skin. - */ - Image *getStickyImage(bool state) const - { return state ? mStickyImageDown : mStickyImageUp; } - - /** - * Returns the minimum width which can be used with this skin. - */ - int getMinWidth() const; - - /** - * Returns the minimum height which can be used with this skin. - */ - int getMinHeight() const; - - /** - * Updates the alpha value of the skin - */ - void updateAlpha(float minimumOpacityAllowed = 0.0f); - - int instances; - - private: - std::string mFilePath; /**< File name path for the skin */ - std::string mName; /**< Name of the skin to use */ - ImageRect mBorder; /**< The window border and background */ - Image *mCloseImage; /**< Close Button Image */ - Image *mStickyImageUp; /**< Sticky Button Image */ - Image *mStickyImageDown; /**< Sticky Button Image */ -}; - -class SkinLoader -{ - public: - static SkinLoader *instance(); - static void deleteInstance(); - - static void prepareThemePath(); - static std::string getThemePath() { return mThemePath; } - - /** - * Returns the patch to the given gui resource relative to the theme - * or, if it isn't in the theme, relative to 'graphics/gui'. - */ - static std::string resolveThemePath(const std::string &path); - - static Image *getImageFromTheme(const std::string &path); - static ImageSet *getImageSetFromTheme(const std::string &path, - int w, int h); - - /** - * Loads a skin. - */ - Skin *load(const std::string &filename, - const std::string &defaultPath = getThemePath()); - - /** - * Updates the alpha values of all of the skins. - */ - 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(); - - Skin *readSkin(const std::string &filename); - - // Map containing all window skins - typedef std::map Skins; - typedef Skins::iterator SkinIterator; - - Skins mSkins; - - /** - * The config listener that listens to changes relevant to all skins. - */ - ConfigListener *mSkinConfigListener; - - static std::string mThemePath; - static SkinLoader *mInstance; - - static bool tryThemePath(std::string themePath); - - /** - * Tells if the current skins opacity - * should not get less than the given value - */ - float mMinimumOpacity; -}; - -#endif diff --git a/src/gui/specialswindow.cpp b/src/gui/specialswindow.cpp index 3ca0f037..44551825 100644 --- a/src/gui/specialswindow.cpp +++ b/src/gui/specialswindow.cpp @@ -24,7 +24,7 @@ #include "log.h" #include "gui/setup.h" -#include "gui/skin.h" +#include "gui/theme.h" #include "gui/widgets/button.h" #include "gui/widgets/container.h" @@ -220,7 +220,7 @@ SpecialEntry::SpecialEntry(SpecialInfo *info) : if (!info->icon.empty()) mIcon = new Icon(info->icon); else - mIcon = new Icon(SkinLoader::resolveThemePath("unknown-item.png")); + mIcon = new Icon(Theme::resolveThemePath("unknown-item.png")); mIcon->setPosition(1, 0); add(mIcon); diff --git a/src/gui/speechbubble.cpp b/src/gui/speechbubble.cpp index f02965d1..5cc5772d 100644 --- a/src/gui/speechbubble.cpp +++ b/src/gui/speechbubble.cpp @@ -25,7 +25,7 @@ #include "graphics.h" #include "gui/gui.h" -#include "gui/skin.h" +#include "gui/theme.h" #include "gui/widgets/textbox.h" diff --git a/src/gui/theme.cpp b/src/gui/theme.cpp new file mode 100644 index 00000000..961694e6 --- /dev/null +++ b/src/gui/theme.cpp @@ -0,0 +1,345 @@ +/* + * Gui Skinning + * Copyright (C) 2008 The Legend of Mazzeroth Development Team + * Copyright (C) 2009 Aethyra Development Team + * Copyright (C) 2009 The Mana World Development Team + * Copyright (C) 2009-2010 The Mana Developers + * + * This file is part of The Mana Client. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "gui/theme.h" + +#include "client.h" +#include "configuration.h" +#include "log.h" + +#include "resources/image.h" +#include "resources/imageset.h" +#include "resources/resourcemanager.h" + +#include "utils/dtor.h" +#include "utils/stringutils.h" +#include "utils/xml.h" + +#include + +#include + +std::string Theme::mThemePath; +Theme *Theme::mInstance = 0; + +Skin::Skin(ImageRect skin, Image *close, Image *stickyUp, Image *stickyDown, + const std::string &filePath, + const std::string &name): + instances(0), + mFilePath(filePath), + mName(name), + mBorder(skin), + mCloseImage(close), + mStickyImageUp(stickyUp), + mStickyImageDown(stickyDown) +{ +} + +Skin::~Skin() +{ + // Clean up static resources + for (int i = 0; i < 9; i++) + delete mBorder.grid[i]; + + mCloseImage->decRef(); + delete mStickyImageUp; + delete mStickyImageDown; +} + +void Skin::updateAlpha(float minimumOpacityAllowed) +{ + 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)); + + mCloseImage->setAlpha(alpha); + mStickyImageUp->setAlpha(alpha); + mStickyImageDown->setAlpha(alpha); +} + +int Skin::getMinWidth() const +{ + return mBorder.grid[ImageRect::UPPER_LEFT]->getWidth() + + mBorder.grid[ImageRect::UPPER_RIGHT]->getWidth(); +} + +int Skin::getMinHeight() const +{ + return mBorder.grid[ImageRect::UPPER_LEFT]->getHeight() + + mBorder.grid[ImageRect::LOWER_LEFT]->getHeight(); +} + +Theme::Theme(): + mMinimumOpacity(-1.0f) +{ + config.addListener("guialpha", this); +} + +Theme::~Theme() +{ + delete_all(mSkins); + config.removeListener("guialpha", this); +} + +Theme *Theme::instance() +{ + if (!mInstance) + mInstance = new Theme; + + return mInstance; +} + +void Theme::deleteInstance() +{ + delete mInstance; + mInstance = 0; +} + +Skin *Theme::load(const std::string &filename, const std::string &defaultPath) +{ + // Check if this skin was already loaded + SkinIterator skinIterator = mSkins.find(filename); + if (mSkins.end() != skinIterator) + { + skinIterator->second->instances++; + return skinIterator->second; + } + + Skin *skin = readSkin(filename); + + if (!skin) + { + // Try falling back on the defaultPath if this makes sense + if (filename != defaultPath) + { + logger->log("Error loading skin '%s', falling back on default.", + filename.c_str()); + + skin = readSkin(defaultPath); + } + + if (!skin) + { + logger->error(strprintf("Error: Loading default skin '%s' failed. " + "Make sure the skin file is valid.", + defaultPath.c_str())); + } + } + + // Add the skin to the loaded skins + mSkins[filename] = skin; + + return skin; +} + +void Theme::setMinimumOpacity(float minimumOpacity) +{ + if (minimumOpacity > 1.0f) return; + + mMinimumOpacity = minimumOpacity; + updateAlpha(); +} + +void Theme::updateAlpha() +{ + for (SkinIterator iter = mSkins.begin(); iter != mSkins.end(); ++iter) + iter->second->updateAlpha(mMinimumOpacity); +} + +void Theme::optionChanged(const std::string &) +{ + updateAlpha(); +} + +Skin *Theme::readSkin(const std::string &filename) +{ + if (filename.empty()) + return 0; + + logger->log("Loading skin '%s'.", filename.c_str()); + + XML::Document doc(resolveThemePath(filename)); + xmlNodePtr rootNode = doc.rootNode(); + + if (!rootNode || !xmlStrEqual(rootNode->name, BAD_CAST "skinset")) + return 0; + + const std::string skinSetImage = XML::getProperty(rootNode, "image", ""); + + if (skinSetImage.empty()) + { + logger->log("Theme::readSkin(): Skinset does not define an image!"); + return 0; + } + + logger->log("Theme::load(): defines '%s' as a skin image.", + skinSetImage.c_str()); + + Image *dBorders = Theme::getImageFromTheme(skinSetImage); + ImageRect border; + + // iterate 's + for_each_xml_child_node(widgetNode, rootNode) + { + if (!xmlStrEqual(widgetNode->name, BAD_CAST "widget")) + continue; + + const std::string widgetType = + XML::getProperty(widgetNode, "type", "unknown"); + if (widgetType == "Window") + { + // Iterate through 's + // LEEOR / TODO: + // We need to make provisions to load in a CloseButton image. For + // now it can just be hard-coded. + for_each_xml_child_node(partNode, widgetNode) + { + if (!xmlStrEqual(partNode->name, BAD_CAST "part")) + continue; + + const std::string partType = + XML::getProperty(partNode, "type", "unknown"); + // TOP ROW + const int xPos = XML::getProperty(partNode, "xpos", 0); + const int yPos = XML::getProperty(partNode, "ypos", 0); + const int width = XML::getProperty(partNode, "width", 1); + const int height = XML::getProperty(partNode, "height", 1); + + if (partType == "top-left-corner") + border.grid[0] = dBorders->getSubImage(xPos, yPos, width, height); + else if (partType == "top-edge") + border.grid[1] = dBorders->getSubImage(xPos, yPos, width, height); + else if (partType == "top-right-corner") + border.grid[2] = dBorders->getSubImage(xPos, yPos, width, height); + + // MIDDLE ROW + else if (partType == "left-edge") + border.grid[3] = dBorders->getSubImage(xPos, yPos, width, height); + else if (partType == "bg-quad") + border.grid[4] = dBorders->getSubImage(xPos, yPos, width, height); + else if (partType == "right-edge") + border.grid[5] = dBorders->getSubImage(xPos, yPos, width, height); + + // BOTTOM ROW + else if (partType == "bottom-left-corner") + border.grid[6] = dBorders->getSubImage(xPos, yPos, width, height); + else if (partType == "bottom-edge") + border.grid[7] = dBorders->getSubImage(xPos, yPos, width, height); + else if (partType == "bottom-right-corner") + border.grid[8] = dBorders->getSubImage(xPos, yPos, width, height); + + else + logger->log("Theme::readSkin(): Unknown part type '%s'", + partType.c_str()); + } + } + else + { + logger->log("Theme::readSkin(): Unknown widget type '%s'", + widgetType.c_str()); + } + } + + dBorders->decRef(); + + logger->log("Finished loading skin."); + + // Hard-coded for now until we update the above code to look for window buttons + Image *closeImage = Theme::getImageFromTheme("close_button.png"); + Image *sticky = Theme::getImageFromTheme("sticky_button.png"); + Image *stickyImageUp = sticky->getSubImage(0, 0, 15, 15); + Image *stickyImageDown = sticky->getSubImage(15, 0, 15, 15); + sticky->decRef(); + + Skin *skin = new Skin(border, closeImage, stickyImageUp, stickyImageDown, + filename); + skin->updateAlpha(mMinimumOpacity); + return skin; +} + +bool Theme::tryThemePath(std::string themePath) +{ + if (!themePath.empty()) + { + themePath = "graphics/gui/" + themePath; + if (PHYSFS_exists(themePath.c_str())) + { + mThemePath = themePath; + return true; + } + } + + return false; +} + +void Theme::prepareThemePath() +{ + // Try theme from settings + if (tryThemePath(config.getValue("theme", ""))) + return; + + // Try theme from branding + if (tryThemePath(branding.getValue("theme", ""))) + return; + + // Use default + mThemePath = "graphics/gui"; +} + +std::string Theme::resolveThemePath(const std::string &path) +{ + // Need to strip off any dye info for the existence tests + int pos = path.find('|'); + std::string file; + if (pos > 0) + file = path.substr(0, pos); + else + file = path; + + // Might be a valid path already + if (PHYSFS_exists(file.c_str())) + return path; + + // Try the theme + file = getThemePath() + "/" + file; + if (PHYSFS_exists(file.c_str())) + return getThemePath() + "/" + path; + + // Backup + return "graphics/gui/" + path; +} + +Image *Theme::getImageFromTheme(const std::string &path) +{ + ResourceManager *resman = ResourceManager::getInstance(); + return resman->getImage(resolveThemePath(path)); +} + +ImageSet *Theme::getImageSetFromTheme(const std::string &path, + int w, int h) +{ + ResourceManager *resman = ResourceManager::getInstance(); + return resman->getImageSet(resolveThemePath(path), w, h); +} diff --git a/src/gui/theme.h b/src/gui/theme.h new file mode 100644 index 00000000..abc2612f --- /dev/null +++ b/src/gui/theme.h @@ -0,0 +1,172 @@ +/* + * Gui Skinning + * Copyright (C) 2008 The Legend of Mazzeroth Development Team + * Copyright (C) 2009 Aethyra Development Team + * Copyright (C) 2009 The Mana World Development Team + * Copyright (C) 2009-2010 The Mana Developers + * + * This file is part of The Mana Client. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef SKIN_H +#define SKIN_H + +#include "configlistener.h" +#include "graphics.h" + +#include +#include + +class Image; +class ImageSet; + +class Skin +{ + public: + Skin(ImageRect skin, Image *close, Image *stickyUp, Image *stickyDown, + const std::string &filePath, + const std::string &name = ""); + + ~Skin(); + + /** + * Returns the skin's name. Useful for giving a human friendly skin + * name if a dialog for skin selection for a specific window type is + * done. + */ + const std::string &getName() const { return mName; } + + /** + * Returns the skin's xml file path. + */ + const std::string &getFilePath() const { return mFilePath; } + + /** + * Returns the background skin. + */ + const ImageRect &getBorder() const { return mBorder; } + + /** + * Returns the image used by a close button for this skin. + */ + Image *getCloseImage() const { return mCloseImage; } + + /** + * Returns the image used by a sticky button for this skin. + */ + Image *getStickyImage(bool state) const + { return state ? mStickyImageDown : mStickyImageUp; } + + /** + * Returns the minimum width which can be used with this skin. + */ + int getMinWidth() const; + + /** + * Returns the minimum height which can be used with this skin. + */ + int getMinHeight() const; + + /** + * Updates the alpha value of the skin + */ + void updateAlpha(float minimumOpacityAllowed = 0.0f); + + int instances; + + private: + std::string mFilePath; /**< File name path for the skin */ + std::string mName; /**< Name of the skin to use */ + ImageRect mBorder; /**< The window border and background */ + Image *mCloseImage; /**< Close Button Image */ + Image *mStickyImageUp; /**< Sticky Button Image */ + Image *mStickyImageDown; /**< Sticky Button Image */ +}; + +class Theme : public ConfigListener +{ + public: + static Theme *instance(); + static void deleteInstance(); + + static void prepareThemePath(); + static std::string getThemePath() { return mThemePath; } + + /** + * Returns the patch to the given gui resource relative to the theme + * or, if it isn't in the theme, relative to 'graphics/gui'. + */ + static std::string resolveThemePath(const std::string &path); + + static Image *getImageFromTheme(const std::string &path); + static ImageSet *getImageSetFromTheme(const std::string &path, + int w, int h); + + /** + * Loads a skin. + */ + Skin *load(const std::string &filename, + const std::string &defaultPath = getThemePath()); + + /** + * Updates the alpha values of all of the skins. + */ + 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); + + void optionChanged(const std::string &); + + private: + Theme(); + ~Theme(); + + Skin *readSkin(const std::string &filename); + + // Map containing all window skins + typedef std::map Skins; + typedef Skins::iterator SkinIterator; + + Skins mSkins; + + /** + * The config listener that listens to changes relevant to all skins. + */ + ConfigListener *mSkinConfigListener; + + static std::string mThemePath; + static Theme *mInstance; + + static bool tryThemePath(std::string themePath); + + /** + * Tells if the current skins opacity + * should not get less than the given value + */ + float mMinimumOpacity; +}; + +#endif diff --git a/src/gui/widgets/avatarlistbox.cpp b/src/gui/widgets/avatarlistbox.cpp index 92386739..17651137 100644 --- a/src/gui/widgets/avatarlistbox.cpp +++ b/src/gui/widgets/avatarlistbox.cpp @@ -25,7 +25,7 @@ #include "gui/chat.h" #include "gui/gui.h" #include "gui/palette.h" -#include "gui/skin.h" +#include "gui/theme.h" #include "resources/image.h" #include "resources/resourcemanager.h" @@ -45,8 +45,8 @@ AvatarListBox::AvatarListBox(AvatarListModel *model): if (instances == 1) { - onlineIcon = SkinLoader::getImageFromTheme("circle-green.png"); - offlineIcon = SkinLoader::getImageFromTheme("circle-gray.png"); + onlineIcon = Theme::getImageFromTheme("circle-green.png"); + offlineIcon = Theme::getImageFromTheme("circle-gray.png"); } setWidth(200); diff --git a/src/gui/widgets/button.cpp b/src/gui/widgets/button.cpp index 36a47859..aff46b2a 100644 --- a/src/gui/widgets/button.cpp +++ b/src/gui/widgets/button.cpp @@ -25,7 +25,7 @@ #include "graphics.h" #include "gui/palette.h" -#include "gui/skin.h" +#include "gui/theme.h" #include "resources/image.h" @@ -90,7 +90,7 @@ void Button::init() for (mode = 0; mode < BUTTON_COUNT; mode++) { - btn[mode] = SkinLoader::getImageFromTheme(data[mode].file); + btn[mode] = Theme::getImageFromTheme(data[mode].file); a = 0; for (y = 0; y < 3; y++) { @@ -126,7 +126,7 @@ Button::~Button() void Button::updateAlpha() { float alpha = std::max(config.getValue("guialpha", 0.8f), - (double)SkinLoader::instance()->getMinimumOpacity()); + (double) Theme::instance()->getMinimumOpacity()); if (mAlpha != alpha) { diff --git a/src/gui/widgets/checkbox.cpp b/src/gui/widgets/checkbox.cpp index 0fefbfe9..5ca38727 100644 --- a/src/gui/widgets/checkbox.cpp +++ b/src/gui/widgets/checkbox.cpp @@ -25,7 +25,7 @@ #include "graphics.h" #include "gui/palette.h" -#include "gui/skin.h" +#include "gui/theme.h" #include "resources/image.h" @@ -44,7 +44,7 @@ CheckBox::CheckBox(const std::string &caption, bool selected): { if (instances == 0) { - Image *checkBox = SkinLoader::getImageFromTheme("checkbox.png"); + Image *checkBox = Theme::getImageFromTheme("checkbox.png"); checkBoxNormal = checkBox->getSubImage(0, 0, 9, 10); checkBoxChecked = checkBox->getSubImage(9, 0, 9, 10); checkBoxDisabled = checkBox->getSubImage(18, 0, 9, 10); @@ -93,7 +93,7 @@ void CheckBox::draw(gcn::Graphics* graphics) void CheckBox::updateAlpha() { float alpha = std::max(config.getValue("guialpha", 0.8f), - (double)SkinLoader::instance()->getMinimumOpacity()); + (double) Theme::instance()->getMinimumOpacity()); if (mAlpha != alpha) { diff --git a/src/gui/widgets/dropdown.cpp b/src/gui/widgets/dropdown.cpp index eb0cdef2..57a09ed2 100644 --- a/src/gui/widgets/dropdown.cpp +++ b/src/gui/widgets/dropdown.cpp @@ -26,7 +26,7 @@ #include "gui/palette.h" #include "gui/sdlinput.h" -#include "gui/skin.h" +#include "gui/theme.h" #include "gui/widgets/listbox.h" #include "gui/widgets/scrollarea.h" @@ -55,14 +55,10 @@ DropDown::DropDown(gcn::ListModel *listModel): // Load the background skin // Get the button skin - buttons[1][0] = - SkinLoader::getImageFromTheme("vscroll_up_default.png"); - buttons[0][0] = - SkinLoader::getImageFromTheme("vscroll_down_default.png"); - buttons[1][1] = - SkinLoader::getImageFromTheme("vscroll_up_pressed.png"); - buttons[0][1] = - SkinLoader::getImageFromTheme("vscroll_down_pressed.png"); + buttons[1][0] = Theme::getImageFromTheme("vscroll_up_default.png"); + buttons[0][0] = Theme::getImageFromTheme("vscroll_down_default.png"); + buttons[1][1] = Theme::getImageFromTheme("vscroll_up_pressed.png"); + buttons[0][1] = Theme::getImageFromTheme("vscroll_down_pressed.png"); buttons[0][0]->setAlpha(mAlpha); buttons[0][1]->setAlpha(mAlpha); @@ -70,7 +66,7 @@ DropDown::DropDown(gcn::ListModel *listModel): buttons[1][1]->setAlpha(mAlpha); // get the border skin - Image *boxBorder = SkinLoader::getImageFromTheme("deepbox.png"); + Image *boxBorder = Theme::getImageFromTheme("deepbox.png"); int gridx[4] = {0, 3, 28, 31}; int gridy[4] = {0, 3, 28, 31}; int a = 0, x, y; @@ -115,7 +111,7 @@ DropDown::~DropDown() void DropDown::updateAlpha() { float alpha = std::max(config.getValue("guialpha", 0.8f), - (double)SkinLoader::instance()->getMinimumOpacity()); + (double) Theme::instance()->getMinimumOpacity()); if (mAlpha != alpha) { diff --git a/src/gui/widgets/emoteshortcutcontainer.cpp b/src/gui/widgets/emoteshortcutcontainer.cpp index dd13c679..aadc6f24 100644 --- a/src/gui/widgets/emoteshortcutcontainer.cpp +++ b/src/gui/widgets/emoteshortcutcontainer.cpp @@ -32,7 +32,7 @@ #include "log.h" #include "gui/palette.h" -#include "gui/skin.h" +#include "gui/theme.h" #include "resources/emotedb.h" #include "resources/image.h" @@ -49,7 +49,7 @@ EmoteShortcutContainer::EmoteShortcutContainer(): addMouseListener(this); addWidgetListener(this); - mBackgroundImg = SkinLoader::getImageFromTheme("item_shortcut_bgr.png"); + mBackgroundImg = Theme::getImageFromTheme("item_shortcut_bgr.png"); mBackgroundImg->setAlpha(config.getValue("guialpha", 0.8)); diff --git a/src/gui/widgets/itemcontainer.cpp b/src/gui/widgets/itemcontainer.cpp index b4270912..0a211d29 100644 --- a/src/gui/widgets/itemcontainer.cpp +++ b/src/gui/widgets/itemcontainer.cpp @@ -32,7 +32,7 @@ #include "gui/outfitwindow.h" #include "gui/palette.h" #include "gui/sdlinput.h" -#include "gui/skin.h" +#include "gui/theme.h" #include "gui/viewport.h" #include "net/net.h" @@ -67,7 +67,7 @@ ItemContainer::ItemContainer(Inventory *inventory, bool forceQuantity): mItemPopup = new ItemPopup; setFocusable(true); - mSelImg = SkinLoader::getImageFromTheme("selection.png"); + mSelImg = Theme::getImageFromTheme("selection.png"); if (!mSelImg) logger->error("Unable to load selection.png"); diff --git a/src/gui/widgets/itemshortcutcontainer.cpp b/src/gui/widgets/itemshortcutcontainer.cpp index 92a3e7d0..da5d11c5 100644 --- a/src/gui/widgets/itemshortcutcontainer.cpp +++ b/src/gui/widgets/itemshortcutcontainer.cpp @@ -32,7 +32,7 @@ #include "gui/inventorywindow.h" #include "gui/itempopup.h" #include "gui/palette.h" -#include "gui/skin.h" +#include "gui/theme.h" #include "gui/viewport.h" #include "resources/image.h" @@ -50,7 +50,7 @@ ItemShortcutContainer::ItemShortcutContainer(): mItemPopup = new ItemPopup; - mBackgroundImg = SkinLoader::getImageFromTheme("item_shortcut_bgr.png"); + mBackgroundImg = Theme::getImageFromTheme("item_shortcut_bgr.png"); mMaxItems = itemShortcut->getItemCount(); mBackgroundImg->setAlpha(config.getValue("guialpha", 0.8)); diff --git a/src/gui/widgets/listbox.cpp b/src/gui/widgets/listbox.cpp index bfef9e2f..138cf3a0 100644 --- a/src/gui/widgets/listbox.cpp +++ b/src/gui/widgets/listbox.cpp @@ -25,7 +25,7 @@ #include "gui/palette.h" #include "gui/sdlinput.h" -#include "gui/skin.h" +#include "gui/theme.h" #include #include @@ -46,7 +46,7 @@ ListBox::~ListBox() void ListBox::updateAlpha() { float alpha = std::max(config.getValue("guialpha", 0.8), - (double)SkinLoader::instance()->getMinimumOpacity()); + (double) Theme::instance()->getMinimumOpacity()); if (mAlpha != alpha) mAlpha = alpha; diff --git a/src/gui/widgets/playerbox.cpp b/src/gui/widgets/playerbox.cpp index 24395db7..d2c16dbc 100644 --- a/src/gui/widgets/playerbox.cpp +++ b/src/gui/widgets/playerbox.cpp @@ -26,7 +26,7 @@ #include "graphics.h" #include "player.h" -#include "gui/skin.h" +#include "gui/theme.h" #include "resources/image.h" @@ -44,7 +44,7 @@ PlayerBox::PlayerBox(const Player *player): if (instances == 0) { // Load the background skin - Image *textbox = SkinLoader::getImageFromTheme("deepbox.png"); + Image *textbox = Theme::getImageFromTheme("deepbox.png"); int bggridx[4] = {0, 3, 28, 31}; int bggridy[4] = {0, 3, 28, 31}; int a = 0, x, y; diff --git a/src/gui/widgets/popup.cpp b/src/gui/widgets/popup.cpp index 970b21ec..5cc8fad6 100644 --- a/src/gui/widgets/popup.cpp +++ b/src/gui/widgets/popup.cpp @@ -26,7 +26,7 @@ #include "graphics.h" #include "log.h" -#include "gui/skin.h" +#include "gui/theme.h" #include "gui/viewport.h" #include "gui/widgets/windowcontainer.h" @@ -51,7 +51,7 @@ Popup::Popup(const std::string &name, const std::string &skin): setPadding(3); // Loads the skin - mSkin = SkinLoader::instance()->load(skin, mDefaultSkinPath); + mSkin = Theme::instance()->load(skin, mDefaultSkinPath); // Add this window to the window container windowContainer->add(this); @@ -86,7 +86,7 @@ void Popup::loadPopupConfiguration() if (skinName.compare(mSkin->getFilePath()) != 0) { mSkin->instances--; - mSkin = SkinLoader::instance()->load(skinName, mDefaultSkinPath); + mSkin = Theme::instance()->load(skinName, mDefaultSkinPath); } } diff --git a/src/gui/widgets/progressbar.cpp b/src/gui/widgets/progressbar.cpp index 31c32132..99a8c36a 100644 --- a/src/gui/widgets/progressbar.cpp +++ b/src/gui/widgets/progressbar.cpp @@ -27,7 +27,7 @@ #include "gui/gui.h" #include "gui/palette.h" -#include "gui/skin.h" +#include "gui/theme.h" #include "resources/image.h" @@ -58,7 +58,7 @@ ProgressBar::ProgressBar(float progress, if (mInstances == 0) { - Image *dBorders = SkinLoader::getImageFromTheme("vscroll_grey.png"); + Image *dBorders = Theme::getImageFromTheme("vscroll_grey.png"); mBorder.grid[0] = dBorders->getSubImage(0, 0, 4, 4); mBorder.grid[1] = dBorders->getSubImage(4, 0, 3, 4); mBorder.grid[2] = dBorders->getSubImage(7, 0, 4, 4); @@ -122,7 +122,7 @@ void ProgressBar::logic() void ProgressBar::updateAlpha() { float alpha = std::max(config.getValue("guialpha", 0.8), - (double)SkinLoader::instance()->getMinimumOpacity()); + (double) Theme::instance()->getMinimumOpacity()); if (mAlpha != alpha) { diff --git a/src/gui/widgets/progressindicator.cpp b/src/gui/widgets/progressindicator.cpp index f88f6045..1941da4a 100644 --- a/src/gui/widgets/progressindicator.cpp +++ b/src/gui/widgets/progressindicator.cpp @@ -20,7 +20,7 @@ #include "progressindicator.h" -#include "gui/skin.h" +#include "gui/theme.h" #include "resources/animation.h" #include "resources/imageset.h" @@ -33,8 +33,8 @@ ProgressIndicator::ProgressIndicator() { - ImageSet *images = - SkinLoader::getImageSetFromTheme("progress-indicator.png", 32, 32); + ImageSet *images = Theme::getImageSetFromTheme("progress-indicator.png", + 32, 32); Animation *anim = new Animation; for (ImageSet::size_type i = 0; i < images->size(); ++i) diff --git a/src/gui/widgets/radiobutton.cpp b/src/gui/widgets/radiobutton.cpp index 41c8faf7..96797225 100644 --- a/src/gui/widgets/radiobutton.cpp +++ b/src/gui/widgets/radiobutton.cpp @@ -24,7 +24,7 @@ #include "configuration.h" #include "graphics.h" -#include "gui/skin.h" +#include "gui/theme.h" #include "resources/image.h" @@ -44,12 +44,12 @@ RadioButton::RadioButton(const std::string &caption, const std::string &group, { if (instances == 0) { - radioNormal = SkinLoader::getImageFromTheme("radioout.png"); - radioChecked = SkinLoader::getImageFromTheme("radioin.png"); - radioDisabled = SkinLoader::getImageFromTheme("radioout.png"); - radioDisabledChecked = SkinLoader::getImageFromTheme("radioin.png"); - radioNormalHi = SkinLoader::getImageFromTheme("radioout_highlight.png"); - radioCheckedHi = SkinLoader::getImageFromTheme("radioin_highlight.png"); + radioNormal = Theme::getImageFromTheme("radioout.png"); + radioChecked = Theme::getImageFromTheme("radioin.png"); + radioDisabled = Theme::getImageFromTheme("radioout.png"); + radioDisabledChecked = Theme::getImageFromTheme("radioin.png"); + radioNormalHi = Theme::getImageFromTheme("radioout_highlight.png"); + radioCheckedHi = Theme::getImageFromTheme("radioin_highlight.png"); radioNormal->setAlpha(mAlpha); radioChecked->setAlpha(mAlpha); radioDisabled->setAlpha(mAlpha); diff --git a/src/gui/widgets/resizegrip.cpp b/src/gui/widgets/resizegrip.cpp index d0b9b845..f0c3691c 100644 --- a/src/gui/widgets/resizegrip.cpp +++ b/src/gui/widgets/resizegrip.cpp @@ -24,7 +24,7 @@ #include "configuration.h" #include "graphics.h" -#include "gui/skin.h" +#include "gui/theme.h" #include "resources/image.h" @@ -39,7 +39,7 @@ ResizeGrip::ResizeGrip(const std::string &image) if (mInstances == 0) { // Load the grip image - gripImage = SkinLoader::getImageFromTheme(image); + gripImage = Theme::getImageFromTheme(image); gripImage->setAlpha(mAlpha); } diff --git a/src/gui/widgets/scrollarea.cpp b/src/gui/widgets/scrollarea.cpp index dea99e8e..0c7f4d7d 100644 --- a/src/gui/widgets/scrollarea.cpp +++ b/src/gui/widgets/scrollarea.cpp @@ -24,7 +24,7 @@ #include "configuration.h" #include "graphics.h" -#include "gui/skin.h" +#include "gui/theme.h" #include "resources/image.h" @@ -95,7 +95,7 @@ void ScrollArea::init() if (instances == 0) { // Load the background skin - Image *textbox = SkinLoader::getImageFromTheme("deepbox.png"); + Image *textbox = Theme::getImageFromTheme("deepbox.png"); const int bggridx[4] = {0, 3, 28, 31}; const int bggridy[4] = {0, 3, 28, 31}; int a = 0, x, y; @@ -116,8 +116,8 @@ void ScrollArea::init() textbox->decRef(); // Load vertical scrollbar skin - Image *vscroll = SkinLoader::getImageFromTheme("vscroll_grey.png"); - Image *vscrollHi = SkinLoader::getImageFromTheme("vscroll_highlight.png"); + Image *vscroll = Theme::getImageFromTheme("vscroll_grey.png"); + Image *vscrollHi = Theme::getImageFromTheme("vscroll_highlight.png"); int vsgridx[4] = {0, 4, 7, 11}; int vsgridy[4] = {0, 4, 15, 19}; @@ -145,21 +145,21 @@ void ScrollArea::init() vscrollHi->decRef(); buttons[UP][0] = - SkinLoader::getImageFromTheme("vscroll_up_default.png"); + Theme::getImageFromTheme("vscroll_up_default.png"); buttons[DOWN][0] = - SkinLoader::getImageFromTheme("vscroll_down_default.png"); + Theme::getImageFromTheme("vscroll_down_default.png"); buttons[LEFT][0] = - SkinLoader::getImageFromTheme("hscroll_left_default.png"); + Theme::getImageFromTheme("hscroll_left_default.png"); buttons[RIGHT][0] = - SkinLoader::getImageFromTheme("hscroll_right_default.png"); + Theme::getImageFromTheme("hscroll_right_default.png"); buttons[UP][1] = - SkinLoader::getImageFromTheme("vscroll_up_pressed.png"); + Theme::getImageFromTheme("vscroll_up_pressed.png"); buttons[DOWN][1] = - SkinLoader::getImageFromTheme("vscroll_down_pressed.png"); + Theme::getImageFromTheme("vscroll_down_pressed.png"); buttons[LEFT][1] = - SkinLoader::getImageFromTheme("hscroll_left_pressed.png"); + Theme::getImageFromTheme("hscroll_left_pressed.png"); buttons[RIGHT][1] = - SkinLoader::getImageFromTheme("hscroll_right_pressed.png"); + Theme::getImageFromTheme("hscroll_right_pressed.png"); } instances++; @@ -214,7 +214,7 @@ void ScrollArea::logic() void ScrollArea::updateAlpha() { float alpha = std::max(config.getValue("guialpha", 0.8), - (double)SkinLoader::instance()->getMinimumOpacity()); + (double) Theme::instance()->getMinimumOpacity()); if (alpha != mAlpha) { diff --git a/src/gui/widgets/slider.cpp b/src/gui/widgets/slider.cpp index af36518a..6a9a5c7c 100644 --- a/src/gui/widgets/slider.cpp +++ b/src/gui/widgets/slider.cpp @@ -24,7 +24,7 @@ #include "configuration.h" #include "graphics.h" -#include "gui/skin.h" +#include "gui/theme.h" #include "resources/image.h" @@ -82,8 +82,8 @@ void Slider::init() // Load resources if (mInstances == 0) { - Image *slider = SkinLoader::getImageFromTheme("slider.png"); - Image *sliderHi = SkinLoader::getImageFromTheme("slider_hilight.png"); + Image *slider = Theme::getImageFromTheme("slider.png"); + Image *sliderHi = Theme::getImageFromTheme("slider_hilight.png"); x = 0; y = 0; w = 15; h = 6; @@ -127,7 +127,7 @@ void Slider::init() void Slider::updateAlpha() { float alpha = std::max(config.getValue("guialpha", 0.8), - (double)SkinLoader::instance()->getMinimumOpacity()); + (double) Theme::instance()->getMinimumOpacity()); if (alpha != mAlpha) { diff --git a/src/gui/widgets/tab.cpp b/src/gui/widgets/tab.cpp index 17145eae..d770dbfe 100644 --- a/src/gui/widgets/tab.cpp +++ b/src/gui/widgets/tab.cpp @@ -25,7 +25,7 @@ #include "graphics.h" #include "gui/palette.h" -#include "gui/skin.h" +#include "gui/theme.h" #include "gui/widgets/tabbedarea.h" @@ -96,7 +96,7 @@ void Tab::init() for (mode = 0; mode < TAB_COUNT; mode++) { - tab[mode] = SkinLoader::getImageFromTheme(data[mode].file); + tab[mode] = Theme::getImageFromTheme(data[mode].file); a = 0; for (y = 0; y < 3; y++) { @@ -119,7 +119,7 @@ void Tab::init() void Tab::updateAlpha() { float alpha = std::max(config.getValue("guialpha", 0.8), - (double)SkinLoader::instance()->getMinimumOpacity()); + (double) Theme::instance()->getMinimumOpacity()); // TODO We don't need to do this for every tab on every draw // Maybe use a config listener to do it as the value changes. diff --git a/src/gui/widgets/textfield.cpp b/src/gui/widgets/textfield.cpp index e599c37d..1fab4eb7 100644 --- a/src/gui/widgets/textfield.cpp +++ b/src/gui/widgets/textfield.cpp @@ -26,7 +26,7 @@ #include "gui/palette.h" #include "gui/sdlinput.h" -#include "gui/skin.h" +#include "gui/theme.h" #include "resources/image.h" @@ -52,7 +52,7 @@ TextField::TextField(const std::string &text, bool loseFocusOnTab): if (instances == 0) { // Load the skin - Image *textbox = SkinLoader::getImageFromTheme("deepbox.png"); + Image *textbox = Theme::getImageFromTheme("deepbox.png"); int gridx[4] = {0, 3, 28, 31}; int gridy[4] = {0, 3, 28, 31}; int a = 0, x, y; @@ -87,7 +87,7 @@ TextField::~TextField() void TextField::updateAlpha() { float alpha = std::max(config.getValue("guialpha", 0.8), - (double)SkinLoader::instance()->getMinimumOpacity()); + (double) Theme::instance()->getMinimumOpacity()); if (alpha != mAlpha) { diff --git a/src/gui/widgets/window.cpp b/src/gui/widgets/window.cpp index 83c918cf..b3d6bd02 100644 --- a/src/gui/widgets/window.cpp +++ b/src/gui/widgets/window.cpp @@ -26,7 +26,7 @@ #include "gui/gui.h" #include "gui/palette.h" -#include "gui/skin.h" +#include "gui/theme.h" #include "gui/viewport.h" #include "gui/widgets/layout.h" @@ -73,7 +73,7 @@ Window::Window(const std::string &caption, bool modal, Window *parent, setTitleBarHeight(20); // Loads the skin - mSkin = SkinLoader::instance()->load(skin, mDefaultSkinPath); + mSkin = Theme::instance()->load(skin, mDefaultSkinPath); // Add this window to the window container windowContainer->add(this); @@ -531,7 +531,7 @@ void Window::loadWindowState() if (skinName.compare(mSkin->getFilePath()) != 0) { mSkin->instances--; - mSkin = SkinLoader::instance()->load(skinName, mDefaultSkinPath); + mSkin = Theme::instance()->load(skinName, mDefaultSkinPath); } if (mGrip) @@ -709,7 +709,7 @@ int Window::getResizeHandles(gcn::MouseEvent &event) int Window::getGuiAlpha() { float alpha = std::max(config.getValue("guialpha", 0.8), - (double)SkinLoader::instance()->getMinimumOpacity()); + (double) Theme::instance()->getMinimumOpacity()); return (int) (alpha * 255.0f); } diff --git a/src/item.cpp b/src/item.cpp index 378c7efe..79ccd2c3 100644 --- a/src/item.cpp +++ b/src/item.cpp @@ -21,7 +21,7 @@ #include "item.h" -#include "gui/skin.h" +#include "gui/theme.h" #include "resources/image.h" #include "resources/iteminfo.h" @@ -62,8 +62,8 @@ void Item::setId(int id) mDrawImage = resman->getImage(imagePath); if (!mImage) - mImage = SkinLoader::getImageFromTheme("unknown-item.png"); + mImage = Theme::getImageFromTheme("unknown-item.png"); if (!mDrawImage) - mDrawImage = SkinLoader::getImageFromTheme("unknown-item.png"); + mDrawImage = Theme::getImageFromTheme("unknown-item.png"); } diff --git a/src/localplayer.cpp b/src/localplayer.cpp index 8c918a97..a48c7f4c 100644 --- a/src/localplayer.cpp +++ b/src/localplayer.cpp @@ -43,9 +43,9 @@ #include "gui/ministatus.h" #include "gui/palette.h" #include "gui/skilldialog.h" -#include "gui/skin.h" #include "gui/statuswindow.h" #include "gui/storagewindow.h" +#include "gui/theme.h" #include "gui/widgets/chattab.h" @@ -1061,8 +1061,8 @@ void LocalPlayer::loadTargetCursor(const std::string &filename, assert(size > -1); assert(size < 3); - ImageSet *currentImageSet = SkinLoader::getImageSetFromTheme(filename, - width, height); + ImageSet *currentImageSet = Theme::getImageSetFromTheme(filename, + width, height); Animation *anim = new Animation; for (unsigned int i = 0; i < currentImageSet->size(); ++i) diff --git a/src/text.cpp b/src/text.cpp index ce09146f..f6c71dba 100644 --- a/src/text.cpp +++ b/src/text.cpp @@ -28,7 +28,7 @@ #include "gui/gui.h" #include "gui/palette.h" -#include "gui/skin.h" +#include "gui/theme.h" #include "resources/resourcemanager.h" #include "resources/image.h" @@ -50,7 +50,7 @@ Text::Text(const std::string &text, int x, int y, if (textManager == 0) { textManager = new TextManager; - Image *sbImage = SkinLoader::getImageFromTheme("bubble.png|W:#" + Image *sbImage = Theme::getImageFromTheme("bubble.png|W:#" + config.getValue("speechBubblecolor", "000000")); mBubble.grid[0] = sbImage->getSubImage(0, 0, 5, 5); mBubble.grid[1] = sbImage->getSubImage(5, 0, 5, 5); -- cgit v1.2.3-60-g2f50