Main Page | Class Hierarchy | Class List | File List | Class Members | Related Pages

D:/Programming/GUI Editor (Source)/Texture.cpp

00001 #include "stdafx.h" 00002 #include "Texture.h" 00003 00004 CTexture::CTexture() 00005 { 00006 SetEntityType(Entity_Texture); 00007 00008 m_pBitmap = NULL; 00009 m_Mask = tRGBA(-1, -1, -1, -1); 00010 } 00011 00012 CTexture::~CTexture() 00013 { 00014 Destroy(); 00015 } 00016 00017 UINT CTexture::Create() 00018 { 00019 00020 return 0; 00021 } 00022 00023 int CTexture::LoadXML(TiXmlNode *pDataNode, CString strFilename) 00024 { 00025 TiXmlElement* pXMLElement = NULL; 00026 const char *pcValue = NULL; 00027 00028 int iRetValue = CXMLResource::LoadXML(pDataNode, strFilename); // LoadXML the data of derivative 00029 if(iRetValue !=1) 00030 return iRetValue; 00031 00032 pXMLElement = m_pXMLElement; 00033 00034 if(stricmp(pXMLElement->pcValue(), "Texture") !=0) 00035 return 0; 00036 00037 if(pXMLElement !=NULL) 00038 { 00039 pcValue = pXMLElement->Attribute("Mask"); 00040 if(pcValue !=NULL) 00041 { 00042 int Color[3] = {0,0,0}; 00043 sscanf(pcValue, "%d,%d,%d", &Color[0], &Color[1], &Color[2]); 00044 m_Mask.R = (float)Color[0]; m_Mask.G = (float)Color[1]; m_Mask.B = (float)Color[2]; 00045 00046 pcValue = NULL; 00047 } 00048 00049 pcValue = pXMLElement->Attribute("Image"); 00050 if(pcValue !=NULL) 00051 { 00052 if(LoadImage(GetFullPath(pcValue))) 00053 { 00054 m_strTextureFilename = pcValue; 00055 return 1; 00056 } 00057 } 00058 } 00059 else 00060 return LoadImage(strFilename); 00061 00062 00063 return 0; 00064 } 00065 00066 int CTexture::LoadImage(CString strFilename) 00067 { 00068 FREE_IMAGE_FORMAT FileType; 00069 00070 FileType = FreeImage_GetFileType(strFilename.GetBuffer());// Get filetype 00071 if(FileType == FIF_UNKNOWN) 00072 return 0; 00073 00074 m_pBitmap = FreeImage_Load(FileType, strFilename.GetBuffer());// LoadXML image 00075 if(m_pBitmap !=NULL) 00076 { 00077 m_strTextureFilename = strFilename; 00078 return 1; 00079 } 00080 00081 return 0; 00082 } 00083 00084 int CTexture::SaveXML(TiXmlNode *pDataNode, CString strFilename) 00085 { 00086 TiXmlElement *pSaveElement = NULL; 00087 TiXmlDocument Doc; 00088 00089 if(pDataNode !=NULL) 00090 pSaveElement = pDataNode->ToElement(); 00091 else if(m_pXMLElement !=NULL) 00092 pSaveElement = m_pXMLElement; 00093 else 00094 pSaveElement = new TiXmlElement("Texture"); 00095 00096 char pcValue[256] = ""; 00097 00098 if(GetTextureFilename() !="") 00099 pSaveElement->SetAttribute("Image", GetTextureFilename().GetBuffer()); 00100 00101 if(GetName() !="") 00102 pSaveElement->SetAttribute("strName", GetName().GetBuffer()); 00103 00104 if(m_Mask.R !=-1 && m_Mask.G !=-1 && m_Mask.B !=-1) 00105 { 00106 int Color[3] = {(int)m_Mask.R, (int)m_Mask.G, (int)m_Mask.B}; 00107 sprintf(pcValue, "%d,%d,%d", Color[0], Color[1], Color[2]); 00108 00109 pSaveElement->SetAttribute("Mask", pcValue); 00110 memset(pcValue, 256, 0); 00111 } 00112 00113 if(pDataNode == NULL) 00114 { 00115 if(strFilename == "") 00116 return 0; 00117 00118 Doc.InsertEndChild(*pSaveElement); 00119 SAFEDEL(pSaveElement) 00120 return Doc.SaveFile(strFilename.GetBuffer()); 00121 } 00122 else 00123 { 00124 if(strFilename == "") 00125 return 1; 00126 00127 Doc.InsertEndChild(*pSaveElement); 00128 return Doc.SaveFile(strFilename.GetBuffer()); 00129 } 00130 00131 return 0; 00132 } 00133 00134 UINT CTexture::GetDepth() 00135 { 00136 return FreeImage_GetBPP(m_pBitmap); 00137 } 00138 00139 UINT CTexture::GetWidth() 00140 { 00141 return FreeImage_GetWidth(m_pBitmap); 00142 } 00143 00144 UINT CTexture::GetHeight() 00145 { 00146 return FreeImage_GetHeight(m_pBitmap); 00147 } 00148 00149 FIBITMAP *CTexture::GetBitmap() 00150 { 00151 return m_pBitmap; 00152 } 00153 00154 bool CTexture::IsMasked() 00155 { 00156 if(m_Mask.R !=-1.0f && m_Mask.G !=-1.0f && m_Mask.B !=-1.0f) 00157 return true; 00158 00159 return false; 00160 } 00161 00162 tRGBA& CTexture::GetMask() 00163 { 00164 return m_Mask; 00165 } 00166 00167 void CTexture::SetMask(tRGBA Mask) 00168 { 00169 m_Mask = Mask; 00170 } 00171 00172 00173 void CTexture::Bind() 00174 { 00175 00176 } 00177 00178 void CTexture::GetPixel(tRGBA *pPixel, UINT x, UINT y) 00179 { 00180 if(pPixel == NULL) 00181 return; 00182 00183 RGBQUAD Pixel; 00184 00185 if(m_pBitmap !=NULL) 00186 { 00187 FreeImage_GetPixelColor(m_pBitmap, x, y, &Pixel); 00188 00189 pPixel->R = Pixel.rgbRed; 00190 pPixel->G = Pixel.rgbGreen; 00191 pPixel->B = Pixel.rgbBlue; 00192 pPixel->A = Pixel.rgbReserved; 00193 } 00194 } 00195 00196 void CTexture::SetPixel(UINT x, UINT y, tRGBA color) 00197 { 00198 RGBQUAD Pixel; 00199 00200 if(m_pBitmap !=NULL) 00201 { 00202 Pixel.rgbRed = color.R; 00203 Pixel.rgbGreen = color.G; 00204 Pixel.rgbBlue = color.B; 00205 00206 FreeImage_SetPixelColor(m_pBitmap, x, y, &Pixel); 00207 } 00208 } 00209 00210 CString& CTexture::GetTextureFilename() 00211 { 00212 return m_strTextureFilename; 00213 } 00214 00215 void CTexture::Release() 00216 { 00217 00218 } 00219 00220 void CTexture::Destroy() 00221 { 00222 if(m_pBitmap !=NULL) 00223 { 00224 FreeImage_Unload(m_pBitmap); 00225 m_pBitmap = NULL; 00226 } 00227 } 00228 00229 bool CTexture::IsOfType(eEntityType eType) 00230 { 00231 if(eType == Entity_Texture) 00232 return true; 00233 00234 return CXMLResource::IsOfType(eType); 00235 }

Generated on Sun Jul 17 21:34:28 2005 for OpenGL GUI by doxygen 1.3.8