Main Page   Class Hierarchy   Compound List   File List   Compound Members  

texture.h

00001 /*
00002     Copyright (C) 1998 by Jorrit Tyberghein
00003   
00004     This library is free software; you can redistribute it and/or
00005     modify it under the terms of the GNU Library General Public
00006     License as published by the Free Software Foundation; either
00007     version 2 of the License, or (at your option) any later version.
00008   
00009     This library is distributed in the hope that it will be useful,
00010     but WITHOUT ANY WARRANTY; without even the implied warranty of
00011     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012     Library General Public License for more details.
00013   
00014     You should have received a copy of the GNU Library General Public
00015     License along with this library; if not, write to the Free
00016     Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00017 */
00018 
00019 #ifndef __CS_TEXTURE_H__
00020 #define __CS_TEXTURE_H__
00021 
00022 #include "cstypes.h"
00023 #include "csutil/csobject.h"
00024 #include "csutil/nobjvec.h"
00025 #include "ivideo/graph2d.h"
00026 #include "ivideo/texture.h"
00027 #include "iengine/texture.h"
00028 #include "igraphic/image.h"
00029 
00030 class csTextureWrapper;
00031 struct iTextureManager;
00032 struct iTextureHandle;
00033 struct iImage;
00034 
00035 
00036 SCF_VERSION (csTextureWrapper, 0, 0, 1);
00037 
00042 class csTextureWrapper : public csObject
00043 {
00044 private:
00046   iImage* image;
00048   iTextureHandle* handle;
00049   // key color
00050   int key_col_r, key_col_g, key_col_b;
00052   int flags;
00053 
00054   // The callback which is called just before texture is used.
00055   iTextureCallback* use_callback;
00056 
00057   // update our key color with that from the handle
00058   void UpdateKeyColorFromHandle ()
00059   {
00060     if (handle && handle->GetKeyColor ())
00061     {
00062       UByte r, g, b;
00063       handle->GetKeyColor (r, g, b);
00064       SetKeyColor ((int)r, (int)g, (int)b);
00065     }
00066     else
00067       key_col_r = -1;
00068   }
00069 
00070   // update our key color with that from the image
00071   void UpdateKeyColorFromImage ()
00072   {
00073     if(image->HasKeycolor ())
00074       image->GetKeycolor( key_col_r, key_col_g, key_col_b );
00075     else
00076       key_col_r = -1;
00077   }
00078 
00079 private:
00081   virtual ~csTextureWrapper ();
00082 
00083 public:
00084 
00086   csTextureWrapper (iImage* Image);
00088   csTextureWrapper (iTextureHandle *ith);
00089 
00094   void SetImageFile (iImage *Image);
00096   iImage* GetImageFile () { return image; }
00097 
00103   void SetTextureHandle (iTextureHandle *tex);
00105   iTextureHandle* GetTextureHandle () { return handle; }
00106 
00108   void SetKeyColor (int red, int green, int blue);
00110   void GetKeyColor (int &red, int &green, int &blue)
00111   { red = key_col_r; green = key_col_g; blue = key_col_b; }
00112 
00114   void SetFlags (int flags) { csTextureWrapper::flags = flags; }
00116   int GetFlags () { return flags; }
00117 
00119   void Register (iTextureManager *txtmng);
00120 
00126   void SetUseCallback (iTextureCallback* callback)
00127   {
00128     SCF_SET_REF (use_callback, callback);
00129   }
00130 
00135   iTextureCallback* GetUseCallback ()
00136   {
00137     return use_callback;
00138   }
00139 
00145   void Visit ()
00146   {
00147     if (use_callback)
00148       use_callback->UseTexture (&scfiTextureWrapper);
00149   }
00150 
00151   SCF_DECLARE_IBASE_EXT (csObject);
00152 
00153   //-------------------- iTextureWrapper implementation -----------------------
00154   struct TextureWrapper : public iTextureWrapper
00155   {
00156     SCF_DECLARE_EMBEDDED_IBASE (csTextureWrapper);
00157 
00158     virtual csTextureWrapper *GetPrivateObject()
00159     {return scfParent;}
00160 
00161     virtual iObject *QueryObject();
00162     virtual void SetImageFile (iImage *Image);
00163     virtual iImage* GetImageFile ();
00164     virtual void SetTextureHandle (iTextureHandle *tex);
00165     virtual iTextureHandle* GetTextureHandle ();
00166     virtual void SetKeyColor (int red, int green, int blue);
00167     virtual void GetKeyColor (int &red, int &green, int &blue);
00168     virtual void SetFlags (int flags);
00169     virtual int GetFlags ();
00170     virtual void Register (iTextureManager *txtmng);
00171     virtual void SetUseCallback (iTextureCallback* callback);
00172     virtual iTextureCallback* GetUseCallback ();
00173     virtual void Visit ();
00174   } scfiTextureWrapper;
00175   friend struct TextureWrapper;
00176 };
00177 
00178 // helper for the texture list
00179 CS_DECLARE_OBJECT_VECTOR (csTextureListHelper, iTextureWrapper);
00180 
00184 class csTextureList : public csTextureListHelper
00185 {
00186 public:
00188   csTextureList ();
00189 
00191   iTextureWrapper *NewTexture (iImage *image);
00192 
00197   iTextureWrapper *NewTexture (iTextureHandle *ith);
00198 
00199   SCF_DECLARE_IBASE;
00200 
00201   //-------------------- iTextureList implementation -------------------------
00202   class TextureList : public iTextureList
00203   {
00204   public:
00205     SCF_DECLARE_EMBEDDED_IBASE (csTextureList);
00206 
00207     virtual iTextureWrapper *NewTexture (iImage *image);
00208     virtual iTextureWrapper *NewTexture (iTextureHandle *ith);
00209     virtual int GetCount () const;
00210     virtual iTextureWrapper *Get (int n) const;
00211     virtual int Add (iTextureWrapper *obj);
00212     virtual bool Remove (iTextureWrapper *obj);
00213     virtual bool Remove (int n);
00214     virtual void RemoveAll ();
00215     virtual int Find (iTextureWrapper *obj) const;
00216     virtual iTextureWrapper *FindByName (const char *Name) const;
00217   } scfiTextureList;
00218 };
00219 
00220 #endif // __CS_TEXTURE_H__

Generated for Crystal Space by doxygen 1.2.5 written by Dimitri van Heesch, ©1997-2000