Planeshift

texfactory.h

Go to the documentation of this file.
00001 /*
00002  * texfactory.h by Keith Fulton <[email protected]>
00003  *
00004  * Copyright (C) 2002 Atomic Blue ([email protected], http://www.atomicblue.org) 
00005  *
00006  *
00007  * This program is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU General Public License
00009  * as published by the Free Software Foundation (version 2 of the License)
00010  * This program is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  * GNU General Public License for more details.
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program; if not, write to the Free Software
00016  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00017  *
00018  */
00019 #ifndef __TEXFACT_H__
00020 #define __TEXFACT_H__
00021 
00022 #include <csutil/parray.h>
00023 #include <igraphic/image.h>
00024 #include <iutil/objreg.h>
00025 
00026 #include "util/psxmlparser.h"
00027 
00028 
00029 class psImageRegion;
00030 
00041 class psTextureFactory
00042 {
00043 protected:
00044 
00045     iObjectRegistry* object_reg;
00046 
00047     csPDelArray<psImageRegion>  regions;    // List of psImageRegions, loaded from racelib.xml file.
00048     csPDelArray<iImage>         imagecache; // List of iImage's, loaded on demand and saved in a list for future use
00049 
00054     bool LoadRace(iDocumentNode * raceNode);
00055 
00060     psImageRegion *GetRegion(const char *race,const char *part);
00061 
00068     csPtr<iImage> GetImage(const char *race,const char *filename);
00069 
00070 public:
00071 
00072     psTextureFactory();
00073     ~psTextureFactory();
00074 
00079     bool Initialize(iObjectRegistry* object_reg,const char *xmlfilename);
00080 
00087     csPtr<iImage> CreateTextureImage(const char *xmlspec);
00088 };
00089 
00090 
00095 struct psScanline
00096 {
00097     int x1,x2,y;
00098 
00099     psScanline() { x1=x2=y=0; }
00100 
00101     psScanline(int l,int r, int h)
00102     {
00103         x1=l;
00104         x2=r;
00105         y=h;
00106     };
00107 };
00108 
00109 
00110 
00118 class psImageRegion
00119 {
00120 protected:
00121     csPDelArray<psScanline> scanlines;
00122 
00123 public:
00124     csString race;
00125     csString part;
00126 
00127     psImageRegion(const char *racename,const char *partname);
00128     psImageRegion() { };
00129     
00130     ~psImageRegion();
00131 
00136     bool CreateRegion(iDocumentNode* node);
00137     void AddScanline( psScanline* line ) { scanlines.Push(line); }
00138 
00139     psScanline* GetLine(int x);
00140 
00145     bool CreateRectRegion(int left, int top, int right, int bottom);
00146 
00154     void OverlayRegion(iImage *dest, iImage *src,int bitmode=0);
00155 };
00156 
00159 #endif
00160