ImageID.cpp

Go to the documentation of this file.
00001 ////////////////////////////////////////////////////////////////////////////////
00002 //    Scorched3D (c) 2000-2009
00003 //
00004 //    This file is part of Scorched3D.
00005 //
00006 //    Scorched3D is free software; you can redistribute it and/or modify
00007 //    it under the terms of the GNU General Public License as published by
00008 //    the Free Software Foundation; either version 2 of the License, or
00009 //    (at your option) any later version.
00010 //
00011 //    Scorched3D is distributed in the hope that it will be useful,
00012 //    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 //    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 //    GNU General Public License for more details.
00015 //
00016 //    You should have received a copy of the GNU General Public License
00017 //    along with Scorched3D; if not, write to the Free Software
00018 //    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019 ////////////////////////////////////////////////////////////////////////////////
00020 
00021 #include <common/ImageID.h>
00022 #include <common/Defines.h>
00023 #include <XML/XMLParser.h>
00024 
00025 ImageID::ImageID()
00026 {
00027 }
00028 
00029 ImageID::~ImageID()
00030 {
00031 }
00032 
00033 bool ImageID::initFromString(
00034                 const char *type,
00035                 const char *imageName,
00036                 const char *alphaName,
00037                 bool invert)
00038 {
00039         type_ = type;
00040         imageName_ = imageName;
00041         alphaName_ = alphaName;
00042         invert_ = invert;
00043         return true;
00044 }
00045 
00046 
00047 bool ImageID::initFromNode(const char *directory, XMLNode *imageNode)
00048 {
00049         XMLNode *typeNode = 0;
00050         if (!imageNode->getNamedParameter("type", typeNode)) return false;
00051         type_ = typeNode->getContent();
00052         if (0 != strcmp("bmp", type_.c_str()) &&
00053                 0 != strcmp("png", type_.c_str()))
00054         {
00055                 return imageNode->returnError(
00056                         S3D::formatStringBuffer(
00057                                 "Unknown image type \"%s\"",
00058                                 type_.c_str()));
00059         }
00060 
00061         std::string image, alpha;
00062         if (!imageNode->getNamedChild("image", image)) return false;
00063         imageName_ = std::string(directory) + std::string("/") + image;
00064         if (!S3D::fileExists(S3D::getDataFile(imageName_.c_str())))
00065         {
00066                 return imageNode->returnError(
00067                         S3D::formatStringBuffer(
00068                                 "Image file \"%s\" does not exist",
00069                                 imageName_.c_str()));
00070         }
00071 
00072         if (imageNode->getNamedChild("alpha", alpha, false))
00073         {
00074                 alphaName_ = std::string(directory) + std::string("/") + alpha;
00075                 if (!S3D::fileExists(S3D::getDataFile(alphaName_.c_str())))
00076                 {
00077                         return imageNode->returnError(
00078                                 S3D::formatStringBuffer(
00079                                         "Alpha file \"%s\" does not exist",
00080                                         alphaName_.c_str()));
00081                         return false;
00082                 }
00083         }
00084 
00085         invert_ = false;
00086         imageNode->getNamedChild("invert", invert_, false);
00087 
00088         return imageNode->failChildren();
00089 }
00090 
00091 const char *ImageID::getStringHash()
00092 { 
00093         hash_ = imageName_ + "-" + alphaName_ + (invert_?"A":"B");
00094         return hash_.c_str(); 
00095 }

Generated on Mon Feb 16 15:14:48 2009 for Scorched3D by  doxygen 1.5.3