Google

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       uint8 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);
00090   csTextureWrapper (csTextureWrapper &);
00091 
00096   void SetImageFile (iImage *Image);
00098   iImage* GetImageFile () { return image; }
00099 
00105   void SetTextureHandle (iTextureHandle *tex);
00107   iTextureHandle* GetTextureHandle () { return handle; }
00108 
00110   void SetKeyColor (int red, int green, int blue);
00112   void GetKeyColor (int &red, int &green, int &blue)
00113   { red = key_col_r; green = key_col_g; blue = key_col_b; }
00114 
00116   void SetFlags (int flags) { csTextureWrapper::flags = flags; }
00118   int GetFlags () { return flags; }
00119 
00121   void Register (iTextureManager *txtmng);
00122 
00128   void SetUseCallback (iTextureCallback* callback)
00129   {
00130     SCF_SET_REF (use_callback, callback);
00131   }
00132 
00137   iTextureCallback* GetUseCallback ()
00138   {
00139     return use_callback;
00140   }
00141 
00147   void Visit ()
00148   {
00149     if (use_callback)
00150       use_callback->UseTexture (&scfiTextureWrapper);
00151   }
00152 
00153   SCF_DECLARE_IBASE_EXT (csObject);
00154 
00155   //-------------------- iTextureWrapper implementation -----------------------
00156   struct TextureWrapper : public iTextureWrapper
00157   {
00158     SCF_DECLARE_EMBEDDED_IBASE (csTextureWrapper);
00159 
00160     virtual csTextureWrapper *GetPrivateObject()
00161     {return scfParent;}
00162 
00163     virtual iObject *QueryObject();
00164     virtual iTextureWrapper *Clone () const
00165     { return &(new csTextureWrapper (*scfParent))->scfiTextureWrapper; }
00166     virtual void SetImageFile (iImage *Image);
00167     virtual iImage* GetImageFile ();
00168     virtual void SetTextureHandle (iTextureHandle *tex);
00169     virtual iTextureHandle* GetTextureHandle ();
00170     virtual void SetKeyColor (int red, int green, int blue);
00171     virtual void GetKeyColor (int &red, int &green, int &blue);
00172     virtual void SetFlags (int flags);
00173     virtual int GetFlags ();
00174     virtual void Register (iTextureManager *txtmng);
00175     virtual void SetUseCallback (iTextureCallback* callback);
00176     virtual iTextureCallback* GetUseCallback ();
00177     virtual void Visit ();
00178   } scfiTextureWrapper;
00179   friend struct TextureWrapper;
00180 };
00181 
00182 // helper for the texture list
00183 CS_DECLARE_OBJECT_VECTOR (csTextureListHelper, iTextureWrapper);
00184 
00188 class csTextureList : public csTextureListHelper
00189 {
00190 public:
00192   csTextureList ();
00193 
00195   iTextureWrapper *NewTexture (iImage *image);
00196 
00201   iTextureWrapper *NewTexture (iTextureHandle *ith);
00202 
00203   SCF_DECLARE_IBASE;
00204 
00205   //-------------------- iTextureList implementation -------------------------
00206   class TextureList : public iTextureList
00207   {
00208   public:
00209     SCF_DECLARE_EMBEDDED_IBASE (csTextureList);
00210 
00211     virtual iTextureWrapper *NewTexture (iImage *image);
00212     virtual iTextureWrapper *NewTexture (iTextureHandle *ith);
00213     virtual int GetCount () const;
00214     virtual iTextureWrapper *Get (int n) const;
00215     virtual int Add (iTextureWrapper *obj);
00216     virtual bool Remove (iTextureWrapper *obj);
00217     virtual bool Remove (int n);
00218     virtual void RemoveAll ();
00219     virtual int Find (iTextureWrapper *obj) const;
00220     virtual iTextureWrapper *FindByName (const char *Name) const;
00221   } scfiTextureList;
00222 };
00223 
00224 #endif // __CS_TEXTURE_H__

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