00001
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #include "std3d.h"
00027
00028 #include "3d/texture_multi_file.h"
00029 #include "3d/texture_file.h"
00030
00031
00032 namespace NL3D
00033 {
00034
00035 static std::string DummyTexName("CTextureMultiFile:Dummy");
00036
00038 CTextureMultiFile::CTextureMultiFile(uint numTexs ) : _CurrSelectedTexture(0), _FileNames(numTexs)
00039 {
00040 }
00041
00042
00044 void CTextureMultiFile::setNumTextures(uint numTexs)
00045 {
00046 _FileNames.resize(numTexs);
00047 _CurrSelectedTexture = (uint) std::min((sint) _CurrSelectedTexture, std::min((sint) 0, (sint) (numTexs - 1)));
00048 }
00049
00050
00052 void CTextureMultiFile::setFileName(uint index, const char *fileName)
00053 {
00054 _FileNames[index] = fileName;
00055 if (index == _CurrSelectedTexture) touch();
00056
00057 }
00058
00059
00061 sint CTextureMultiFile::getTexIndex(uint index) const
00062 {
00063 if (_FileNames.empty())
00064 {
00065 return -1;
00066 }
00067 sint usedTexture = index >= _FileNames.size() ? 0 : index;
00068 if (_FileNames[usedTexture].empty())
00069 {
00070 return (usedTexture != 0 && !_FileNames[0].empty()) ? 0 : -1;
00071 }
00072 return usedTexture;
00073 }
00074
00075
00077 void CTextureMultiFile::doGenerate()
00078 {
00079 sint usedTexture = getTexIndex(_CurrSelectedTexture);
00080 if (usedTexture == -1)
00081 {
00082 makeDummy();
00083 }
00084 else
00085 {
00086 CTextureFile::buildBitmapFromFile(*this, _FileNames[usedTexture], false);
00087 }
00088 }
00089
00091 void CTextureMultiFile::serial(NLMISC::IStream &f) throw(NLMISC::EStream)
00092 {
00093 (void)f.serialVersion(0);
00094
00095
00096 ITexture::serial(f);
00097
00098 f.serialCont(_FileNames);
00099 f.serial(_CurrSelectedTexture);
00100
00101 if(f.isReading())
00102 touch();
00103 }
00104
00105
00107 const std::string &CTextureMultiFile::getTexNameByIndex(uint index) const
00108 {
00109 sint usedTexture = getTexIndex(index);
00110 return usedTexture == -1 ? DummyTexName : _FileNames[usedTexture];
00111 }
00112
00113
00115 std::string CTextureMultiFile::getShareName() const
00116 {
00117 return getTexNameByIndex(_CurrSelectedTexture);
00118 }
00119
00121 void CTextureMultiFile::selectTexture(uint index)
00122 {
00123 if (index != _CurrSelectedTexture)
00124 {
00125 _CurrSelectedTexture = index;
00126 touch();
00127 }
00128 }
00129
00130
00132 ITexture *CTextureMultiFile::buildNonSelectableVersion(uint index)
00133 {
00134 CTextureFile *tf = new CTextureFile(getTexNameByIndex(index));
00135
00136 (ITexture &) *tf = (ITexture &) *this;
00137
00138 return tf;
00139 }
00140
00141
00142 }