diff options
author | Ira Rice <irarice@gmail.com> | 2009-03-11 21:38:17 -0600 |
---|---|---|
committer | Ira Rice <irarice@gmail.com> | 2009-03-11 21:38:17 -0600 |
commit | c410a861fddc7829408d687e61c67c6101555067 (patch) | |
tree | c97f3ddaab9184b00d8e91cc65b759bcc719ff41 /src/gui | |
parent | 1e2fbea2e6d4ab319763c6ffb35e4e4acdd4d5f5 (diff) | |
download | mana-c410a861fddc7829408d687e61c67c6101555067.tar.gz mana-c410a861fddc7829408d687e61c67c6101555067.tar.bz2 mana-c410a861fddc7829408d687e61c67c6101555067.tar.xz mana-c410a861fddc7829408d687e61c67c6101555067.zip |
Modified Skin class to use proper encapsulation, instead of leaving its
skin variables public.
Signed-off-by: Ira Rice <irarice@gmail.com>
Diffstat (limited to 'src/gui')
-rw-r--r-- | src/gui/popup.cpp | 6 | ||||
-rw-r--r-- | src/gui/skin.cpp | 47 | ||||
-rw-r--r-- | src/gui/skin.h | 40 | ||||
-rw-r--r-- | src/gui/window.cpp | 18 |
4 files changed, 81 insertions, 30 deletions
diff --git a/src/gui/popup.cpp b/src/gui/popup.cpp index 4cf6bbf0..8e0c8fb9 100644 --- a/src/gui/popup.cpp +++ b/src/gui/popup.cpp @@ -123,12 +123,12 @@ void Popup::draw(gcn::Graphics *graphics) Graphics *g = static_cast<Graphics*>(graphics); - g->drawImageRect(0, 0, getWidth(), getHeight(), mSkin->border); + g->drawImageRect(0, 0, getWidth(), getHeight(), mSkin->getBorder()); // Update Popup alpha values if (mAlphaChanged) { - for_each(mSkin->border.grid, mSkin->border.grid + 9, + for_each(mSkin->getBorder().grid, mSkin->getBorder().grid + 9, std::bind2nd(std::mem_fun(&Image::setAlpha), config.getValue("guialpha", 0.8))); } @@ -201,7 +201,7 @@ void Popup::setGuiAlpha() for (int i = 0; i < 9; i++) { //logger->log("Popup::setGuiAlpha: Border Image (%i)", i); - mSkin->border.grid[i]->setAlpha(config.getValue("guialpha", 0.8)); + mSkin->getBorder().grid[i]->setAlpha(config.getValue("guialpha", 0.8)); } mAlphaChanged = false; diff --git a/src/gui/skin.cpp b/src/gui/skin.cpp index e9d081e9..8787770c 100644 --- a/src/gui/skin.cpp +++ b/src/gui/skin.cpp @@ -31,9 +31,11 @@ SkinLoader* skinLoader = NULL; -Skin::Skin(): - closeImage(NULL), - instances(0) +Skin::Skin(ImageRect skin, Image* close, std::string name): + instances(0), + mName(name), + border(skin), + closeImage(close) { } @@ -49,6 +51,18 @@ Skin::~Skin() closeImage->decRef(); } +int Skin::getMinWidth() +{ + return (border.grid[0]->getWidth() + border.grid[1]->getWidth()) + + border.grid[2]->getWidth(); +} + +int Skin::getMinHeight() +{ + return (border.grid[0]->getHeight() + border.grid[3]->getHeight()) + + border.grid[6]->getHeight(); +} + Skin* SkinLoader::load(const std::string &filename) { SkinIterator skinIterator = mSkins.find(filename); @@ -59,8 +73,6 @@ Skin* SkinLoader::load(const std::string &filename) return skinIterator->second; } - Skin* skin = new Skin(); - ResourceManager *resman = ResourceManager::getInstance(); logger->log("Loading Skin '%s'.", filename.c_str()); @@ -81,6 +93,8 @@ Skin* SkinLoader::load(const std::string &filename) std::string skinSetImage; skinSetImage = XML::getProperty(rootNode, "image", ""); Image *dBorders = NULL; + ImageRect border; + if (!skinSetImage.empty()) { logger->log("SkinLoader::load(): <skinset> defines " @@ -120,27 +134,27 @@ Skin* SkinLoader::load(const std::string &filename) const int height = XML::getProperty(partNode, "height", 1); if (partType == "top-left-corner") - skin->border.grid[0] = dBorders->getSubImage(xPos, yPos, width, height); + border.grid[0] = dBorders->getSubImage(xPos, yPos, width, height); else if (partType == "top-edge") - skin->border.grid[1] = dBorders->getSubImage(xPos, yPos, width, height); + border.grid[1] = dBorders->getSubImage(xPos, yPos, width, height); else if (partType == "top-right-corner") - skin->border.grid[2] = dBorders->getSubImage(xPos, yPos, width, height); + border.grid[2] = dBorders->getSubImage(xPos, yPos, width, height); // MIDDLE ROW else if (partType == "left-edge") - skin->border.grid[3] = dBorders->getSubImage(xPos, yPos, width, height); + border.grid[3] = dBorders->getSubImage(xPos, yPos, width, height); else if (partType == "bg-quad") - skin->border.grid[4] = dBorders->getSubImage(xPos, yPos, width, height); + border.grid[4] = dBorders->getSubImage(xPos, yPos, width, height); else if (partType == "right-edge") - skin->border.grid[5] = dBorders->getSubImage(xPos, yPos, width, height); + border.grid[5] = dBorders->getSubImage(xPos, yPos, width, height); // BOTTOM ROW else if (partType == "bottom-left-corner") - skin->border.grid[6] = dBorders->getSubImage(xPos, yPos, width, height); + border.grid[6] = dBorders->getSubImage(xPos, yPos, width, height); else if (partType == "bottom-edge") - skin->border.grid[7] = dBorders->getSubImage(xPos, yPos, width, height); + border.grid[7] = dBorders->getSubImage(xPos, yPos, width, height); else if (partType == "bottom-right-corner") - skin->border.grid[8] = dBorders->getSubImage(xPos, yPos, width, height); + border.grid[8] = dBorders->getSubImage(xPos, yPos, width, height); // Part is of an uknown type. else @@ -158,7 +172,10 @@ Skin* SkinLoader::load(const std::string &filename) logger->log("Finished loading Skin."); // Hard-coded for now until we update the above code to look for window buttons. - skin->closeImage = resman->getImage("graphics/gui/close_button.png"); + Image* closeImage = resman->getImage("graphics/gui/close_button.png"); + + Skin* skin = new Skin(border, closeImage); + mSkins[filename] = skin; return skin; } diff --git a/src/gui/skin.h b/src/gui/skin.h index 6dddb4a8..b7e70330 100644 --- a/src/gui/skin.h +++ b/src/gui/skin.h @@ -32,13 +32,47 @@ class Image; class Skin { public: - Skin(); + Skin(ImageRect skin, Image* close, 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. + */ + std::string getName() { return mName; } + + /** + * Returns the background skin. + */ + ImageRect getBorder() { return border; } + + /** + * Returns the image used by a close button for this skin. + */ + Image* getCloseImage() { return closeImage; } + + /** + * Returns the number of instances which use this skin. + */ + int getNumberOfInstances() { return instances; } + + /** + * Returns the minimum width which can be used with this skin. + */ + int getMinWidth(); + + /** + * Returns the minimum height which can be used with this skin. + */ + int getMinHeight(); + + int instances; + + private: std::string mName; /**< Name of the skin to use */ ImageRect border; /**< The window border and background */ Image *closeImage; /**< Close Button Image */ - int instances; }; // Map containing all window skins @@ -47,7 +81,7 @@ typedef std::map<std::string, Skin*> Skins; // Iterator for window skins typedef Skins::iterator SkinIterator; -class SkinLoader +class SkinLoader { public: SkinLoader(); diff --git a/src/gui/window.cpp b/src/gui/window.cpp index 76c19751..5c01daf3 100644 --- a/src/gui/window.cpp +++ b/src/gui/window.cpp @@ -148,7 +148,7 @@ void Window::draw(gcn::Graphics *graphics) Graphics *g = static_cast<Graphics*>(graphics); - g->drawImageRect(0, 0, getWidth(), getHeight(), mSkin->border); + g->drawImageRect(0, 0, getWidth(), getHeight(), mSkin->getBorder()); // Draw title if (mShowTitle) @@ -161,8 +161,8 @@ void Window::draw(gcn::Graphics *graphics) // Draw Close Button if (mCloseButton) { - g->drawImage(mSkin->closeImage, - getWidth() - mSkin->closeImage->getWidth() - getPadding(), + g->drawImage(mSkin->getCloseImage(), + getWidth() - mSkin->getCloseImage()->getWidth() - getPadding(), getPadding() ); } @@ -170,10 +170,10 @@ void Window::draw(gcn::Graphics *graphics) // Update window alpha values if (mAlphaChanged) { - for_each(mSkin->border.grid, mSkin->border.grid + 9, + for_each(mSkin->getBorder().grid, mSkin->getBorder().grid + 9, std::bind2nd(std::mem_fun(&Image::setAlpha), config.getValue("guialpha", 0.8))); - mSkin->closeImage->setAlpha(config.getValue("guialpha", 0.8)); + mSkin->getCloseImage()->setAlpha(config.getValue("guialpha", 0.8)); } drawChildren(graphics); } @@ -352,10 +352,10 @@ void Window::mousePressed(gcn::MouseEvent &event) if (mCloseButton) { gcn::Rectangle closeButtonRect( - getWidth() - mSkin->closeImage->getWidth() - getPadding(), + getWidth() - mSkin->getCloseImage()->getWidth() - getPadding(), getPadding(), - mSkin->closeImage->getWidth(), - mSkin->closeImage->getHeight()); + mSkin->getCloseImage()->getWidth(), + mSkin->getCloseImage()->getHeight()); if (closeButtonRect.isPointInRect(x, y)) { @@ -666,7 +666,7 @@ void Window::setGuiAlpha() for (int i = 0; i < 9; i++) { //logger->log("Window::setGuiAlpha: Border Image (%i)", i); - mSkin->border.grid[i]->setAlpha(config.getValue("guialpha", 0.8)); + mSkin->getBorder().grid[i]->setAlpha(config.getValue("guialpha", 0.8)); } mAlphaChanged = false; |