# Home    # nevrax.com   
Nevrax
Nevrax.org
#News
#Mailing-list
#Documentation
#CVS
#Bugs
#License
Docs
 
Documentation  
Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages   Search  

texture_multi_file.cpp

Go to the documentation of this file.
00001 
00007 /* Copyright, 2000-2002 Nevrax Ltd.
00008  *
00009  * This file is part of NEVRAX NEL.
00010  * NEVRAX NEL is free software; you can redistribute it and/or modify
00011  * it under the terms of the GNU General Public License as published by
00012  * the Free Software Foundation; either version 2, or (at your option)
00013  * any later version.
00014 
00015  * NEVRAX NEL is distributed in the hope that it will be useful, but
00016  * WITHOUT ANY WARRANTY; without even the implied warranty of
00017  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
00018  * General Public License for more details.
00019 
00020  * You should have received a copy of the GNU General Public License
00021  * along with NEVRAX NEL; see the file COPYING. If not, write to the
00022  * Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
00023  * MA 02111-1307, USA.
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 /* = 0 */) : _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         // serial the base part of ITexture.
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         // copy tex parameters
00136         (ITexture &) *tf = (ITexture &) *this; // invoke ITexture = op for basics parameters
00137         //
00138         return tf;      
00139 }
00140 
00141 
00142 } // NL3D