summaryrefslogtreecommitdiff
path: root/src/gui/skin.cpp
diff options
context:
space:
mode:
authorIra Rice <irarice@gmail.com>2009-03-11 21:38:17 -0600
committerIra Rice <irarice@gmail.com>2009-03-11 21:38:17 -0600
commitc410a861fddc7829408d687e61c67c6101555067 (patch)
treec97f3ddaab9184b00d8e91cc65b759bcc719ff41 /src/gui/skin.cpp
parent1e2fbea2e6d4ab319763c6ffb35e4e4acdd4d5f5 (diff)
downloadmana-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/skin.cpp')
-rw-r--r--src/gui/skin.cpp47
1 files changed, 32 insertions, 15 deletions
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;
}