BorderTexture.cpp

Aller à la documentation de ce fichier.
00001 #include "BorderTexture.h"
00002 
00003 
00004 //Je dois être trop fatigué pour comprendre, il considère que je déclare et pas que je définis... bref.
00005 BorderTexture::BorderTexture()
00006     :width()
00007     ,height()
00008     ,texTop(0)
00009     ,texLeft(0)
00010     ,texBotom(0)
00011     ,texRight(0)
00012     ,texTopLeft(0)
00013     ,texTopRight(0)
00014     ,texBotomLeft(0)
00015     ,texBotomRight(0)
00016     ,init(false)
00017 {
00018 }
00019 
00020 BorderTexture::~BorderTexture()
00021 {
00022     SDL_FreeSurface(texTop);
00023     SDL_FreeSurface(texLeft);
00024     SDL_FreeSurface(texBotom);
00025     SDL_FreeSurface(texRight);
00026     SDL_FreeSurface(texTopLeft);
00027     SDL_FreeSurface(texTopRight);
00028     SDL_FreeSurface(texBotomLeft);
00029     SDL_FreeSurface(texBotomRight);
00030 }
00031 
00032 bool BorderTexture::InitTextures(char* filetexTopLeft, char* filetexTop,char* filetexTopRight,char* filetexRight,char* filetexBotomRight,char* filetexBotom,char* filetexBotomLeft,char* filetexLeft)
00033 {
00034     init=false;
00035     SDL_FreeSurface(texTop);
00036     SDL_FreeSurface(texLeft);
00037     SDL_FreeSurface(texBotom);
00038     SDL_FreeSurface(texRight);
00039     SDL_FreeSurface(texTopLeft);
00040     SDL_FreeSurface(texTopRight);
00041     SDL_FreeSurface(texBotomLeft);
00042     SDL_FreeSurface(texBotomRight);
00043     if(!(filetexTopLeft && filetexTop && filetexBotom && filetexRight && filetexTopLeft && filetexTopRight && filetexBotomLeft && filetexBotomRight))
00044     {
00045         fprintf(stderr,"%s(ligne %d): l'un d'eux est nul filetexTop(%x)|filetexLeft(%x)|filetexBotom(%x)|filetexRight(%x)|filetexTopLeft(%x)|filetexTopRight(%x)|filetexBotomLeft(%x)|filetexBotomRight(%x)\n",__FILE__,__LINE__,(unsigned int)filetexTop, (unsigned int)filetexLeft, (unsigned int)filetexBotom, (unsigned int)filetexRight, (unsigned int)filetexTopLeft, (unsigned int)filetexTopRight, (unsigned int)filetexBotomLeft, (unsigned int)filetexBotomRight);
00046         return true;
00047     }
00048     texTop=SDL_LoadBMP(filetexTop);
00049     texLeft=SDL_LoadBMP(filetexLeft);
00050     texBotom=SDL_LoadBMP(filetexBotom);
00051     texRight=SDL_LoadBMP(filetexRight);
00052     texTopLeft=SDL_LoadBMP(filetexTopLeft);
00053     texTopRight=SDL_LoadBMP(filetexTopRight);
00054     texBotomLeft=SDL_LoadBMP(filetexBotomLeft);
00055     texBotomRight=SDL_LoadBMP(filetexBotomRight);
00056     if(!(texTop && texLeft && texBotom && texRight && texTopLeft && texTopRight && texBotomLeft && texBotomRight))
00057     {
00058         fprintf(stderr,"BorderTexture::InitTextures(uchar*,uchar*,uchar*,uchar*,uchar*,uchar*,uchar*,uchar*), 2: l'un d'eux est nul texTop(%x)|texLeft(%x)|texBotom(%x)|texRight(%x)|texTopLeft(%x)|texTopRight(%x)|texBotomLeft(%x)|texBotomRight(%x)\n",(unsigned int)texTop, (unsigned int)texLeft, (unsigned int)texBotom, (unsigned int)texRight, (unsigned int)texTopLeft, (unsigned int)texTopRight, (unsigned int)texBotomLeft, (unsigned int)texBotomRight);
00059         return true;
00060     }
00061     width[0]=texTopLeft->w;
00062     width[1]=texTop->w;
00063     width[2]=texTopRight->w;
00064     width[3]=texRight->w;
00065     width[4]=texBotomRight->w;
00066     width[5]=texBotom->w;
00067     width[6]=texBotomLeft->w;
00068     width[7]=texLeft->w;
00069 
00070     height[0]=texTopLeft->h;
00071     height[1]=texTop->h;
00072     height[2]=texTopRight->h;
00073     height[3]=texRight->h;
00074     height[4]=texBotomRight->h;
00075     height[5]=texBotom->h;
00076     height[6]=texBotomLeft->h;
00077     height[7]=texLeft->h;
00078     init=true;
00079     return false;
00080 }
00081 
00082 bool BorderTexture::isInit()
00083 {
00084     return init;
00085 }
00086 
00087 bool BorderTexture::Draw(SDL_Surface *target, SDL_Rect *position)
00088 {
00089     SDL_Rect destRect;
00090     destRect.y=0;
00091     for(destRect.x=texTopLeft->w; destRect.x<position->w-texTopRight->w; destRect.x+=texTop->w)
00092         if(SDL_BlitSurface(texTop, NULL, target, &destRect))
00093         {
00094             logErr((char*)__FILE__,__LINE__,SDL_GetError());
00095             return true;
00096         }
00097 
00098     destRect.y=position->h-texBotom->h;
00099     for(destRect.x=texBotomLeft->w; destRect.x<position->w-texBotomRight->w; destRect.x+=texBotom->w)
00100         if(SDL_BlitSurface(texBotom, NULL, target, &destRect))
00101         {
00102             logErr((char*)__FILE__,__LINE__,SDL_GetError());
00103             return true;
00104         }
00105 
00106     destRect.x=0;
00107     for(destRect.y=texTopLeft->h; destRect.y<position->h-texBotomLeft->h; destRect.y+=texLeft->h)
00108         if(SDL_BlitSurface(texLeft, NULL, target, &destRect))
00109         {
00110             logErr((char*)__FILE__,__LINE__,SDL_GetError());
00111             return true;
00112         }
00113 
00114     destRect.x=position->w-texRight->w;
00115     for(destRect.y=texTopRight->h; destRect.y<position->h-texBotomRight->h; destRect.y+=texRight->h)
00116         if(SDL_BlitSurface(texRight, NULL, target, &destRect))
00117         {
00118             logErr((char*)__FILE__,__LINE__,SDL_GetError());
00119             return true;
00120         }
00121 
00122     if(SDL_BlitSurface(texTopLeft, NULL, target, NULL))
00123     {
00124         logErr((char*)__FILE__,__LINE__,SDL_GetError());
00125         return true;
00126     }
00127 
00128     destRect.y=0;
00129     destRect.x=position->w-texTopRight->w;
00130     if(SDL_BlitSurface(texTopRight, NULL, target, &destRect))
00131     {
00132         logErr((char*)__FILE__,__LINE__,SDL_GetError());
00133         return true;
00134     }
00135 
00136     destRect.x=position->w-texBotomRight->w;
00137     destRect.y=position->h-texBotomRight->h;
00138     if(SDL_BlitSurface(texBotomRight, NULL, target, &destRect))
00139     {
00140         logErr((char*)__FILE__,__LINE__,SDL_GetError());
00141         return true;
00142     }
00143 
00144     destRect.x=0;
00145     destRect.y=position->h-texBotomLeft->h;
00146     if(SDL_BlitSurface(texBotomLeft, NULL, target, &destRect))
00147     {
00148         logErr((char*)__FILE__,__LINE__,SDL_GetError());
00149         return true;
00150     }
00151     return false;
00152 }
00153 
00154 BorderTexture::BorderTexture(const BorderTexture &source)
00155     :width()
00156     ,height()
00157     ,texTop(source.texTop)
00158     ,texLeft(source.texLeft)
00159     ,texBotom(source.texBotom)
00160     ,texRight(source.texRight)
00161     ,texTopLeft(source.texTopLeft)
00162     ,texTopRight(source.texTopRight)
00163     ,texBotomLeft(source.texBotomLeft)
00164     ,texBotomRight(source.texBotomRight)
00165     ,init(source.init)
00166 {
00167     incRefcounts();
00168 }
00169 
00170 BorderTexture & BorderTexture::operator=(const BorderTexture &source)
00171 {
00172     for(int i;i<8;i++)
00173     {
00174         width[i]=source.width[i];
00175         height[i]=source.height[i];
00176     }
00177     texTop=source.texTop;
00178     texLeft=source.texLeft;
00179     texBotom=source.texBotom;
00180     texRight=source.texRight;
00181     texTopLeft=source.texTopLeft;
00182     texTopRight=source.texTopRight;
00183     texBotomLeft=source.texBotomLeft;
00184     texBotomRight=source.texBotomRight;
00185     init=source.init;
00186 
00187     incRefcounts();
00188     return *this;
00189 }
00190 
00191 void BorderTexture::incRefcounts(void)
00192 {
00193     if(texTop)
00194         texTop->refcount++;
00195     if(texLeft)
00196         texLeft->refcount++;
00197     if(texBotom)
00198         texBotom->refcount++;
00199     if(texBotomLeft)
00200         texBotomLeft->refcount++;
00201     if(texBotomRight)
00202         texBotomRight->refcount++;
00203     if(texTop)
00204         texTop->refcount++;
00205     if(texTopLeft)
00206         texTopLeft->refcount++;
00207     if(texTopRight)
00208         texTopRight->refcount++;
00209     if(texBotom)
00210         texBotom->refcount++;
00211     if(texRight)
00212         texRight->refcount++;
00213 }

Généré le Sun Nov 15 16:53:06 2009 pour PFen par  doxygen 1.6.1