CrystalSpace

Public API Reference

Main Page   Modules   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages  

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   csRef<iImage> image;
00053   bool keep_image;
00055   csRef<iTextureHandle> handle;
00056   // key color
00057   int key_col_r, key_col_g, key_col_b;
00059   int flags;
00060 
00061   // The callback which is called just before texture is used.
00062   iTextureCallback* use_callback;
00063 
00064   // update our key color with that from the handle
00065   void UpdateKeyColorFromHandle ()
00066   {
00067     if (handle && handle->GetKeyColor ())
00068     {
00069       uint8 r, g, b;
00070       handle->GetKeyColor (r, g, b);
00071       SetKeyColor ((int)r, (int)g, (int)b);
00072     }
00073     else
00074       key_col_r = -1;
00075   }
00076 
00077   // update our key color with that from the image
00078   void UpdateKeyColorFromImage ()
00079   {
00080     if(image->HasKeycolor ())
00081       image->GetKeycolor( key_col_r, key_col_g, key_col_b );
00082     else
00083       key_col_r = -1;
00084   }
00085 
00086 private:
00088   virtual ~csTextureWrapper ();
00089 
00090 public:
00091 
00093   csTextureWrapper (iImage* Image);
00095   csTextureWrapper (iTextureHandle *ith);
00097   csTextureWrapper (csTextureWrapper &);
00098 
00103   void SetImageFile (iImage *Image);
00105   iImage* GetImageFile () { return image; }
00106 
00112   void SetTextureHandle (iTextureHandle *tex);
00114   iTextureHandle* GetTextureHandle () { return handle; }
00115 
00117   void SetKeyColor (int red, int green, int blue);
00119   void GetKeyColor (int &red, int &green, int &blue)
00120   { red = key_col_r; green = key_col_g; blue = key_col_b; }
00121 
00123   void SetFlags (int flags) { csTextureWrapper::flags = flags; }
00125   int GetFlags () { return flags; }
00126 
00128   void Register (iTextureManager *txtmng);
00129 
00135   void SetUseCallback (iTextureCallback* callback)
00136   {
00137     SCF_SET_REF (use_callback, callback);
00138   }
00139 
00144   iTextureCallback* GetUseCallback ()
00145   {
00146     return use_callback;
00147   }
00148 
00154   void Visit ()
00155   {
00156     if (use_callback)
00157       use_callback->UseTexture (&scfiTextureWrapper);
00158   }
00159 
00160   bool IsVisitRequired () const
00161   {
00162     return use_callback != 0;
00163   }
00164 
00165 
00166   SCF_DECLARE_IBASE_EXT (csObject);
00167 
00168   //-------------------- iTextureWrapper implementation -----------------------
00169   struct TextureWrapper : public iTextureWrapper
00170   {
00171     SCF_DECLARE_EMBEDDED_IBASE (csTextureWrapper);
00172 
00173     virtual iObject *QueryObject();
00174     virtual iTextureWrapper *Clone () const
00175     { return &(new csTextureWrapper (*scfParent))->scfiTextureWrapper; }
00176     virtual void SetImageFile (iImage *Image);
00177     virtual iImage* GetImageFile ();
00178     virtual void SetTextureHandle (iTextureHandle *tex);
00179     virtual iTextureHandle* GetTextureHandle ()
00180     {
00181       return scfParent->GetTextureHandle ();
00182     }
00183     virtual void SetKeyColor (int red, int green, int blue);
00184     virtual void GetKeyColor (int &red, int &green, int &blue);
00185     virtual void SetFlags (int flags);
00186     virtual int GetFlags ();
00187     virtual void Register (iTextureManager *txtmng);
00188     virtual void SetUseCallback (iTextureCallback* callback);
00189     virtual iTextureCallback* GetUseCallback ();
00190     virtual void Visit ()
00191     {
00192       scfParent->Visit ();
00193     }
00194     virtual bool IsVisitRequired () const
00195     {
00196       return scfParent->IsVisitRequired ();
00197     }
00198     virtual void SetKeepImage (bool k) { scfParent->keep_image = k; }
00199     virtual bool KeepImage () const { return scfParent->keep_image; }
00200   } scfiTextureWrapper;
00201   friend struct TextureWrapper;
00202 };
00203 
00207 class csTextureList : public csRefArrayObject<iTextureWrapper>
00208 {
00209 public:
00211   csTextureList ();
00212   virtual ~csTextureList () { }
00213 
00215   iTextureWrapper *NewTexture (iImage *image);
00216 
00221   iTextureWrapper *NewTexture (iTextureHandle *ith);
00222 
00223   SCF_DECLARE_IBASE;
00224 
00225   //-------------------- iTextureList implementation -------------------------
00226   class TextureList : public iTextureList
00227   {
00228   public:
00229     SCF_DECLARE_EMBEDDED_IBASE (csTextureList);
00230 
00231     virtual iTextureWrapper *NewTexture (iImage *image);
00232     virtual iTextureWrapper *NewTexture (iTextureHandle *ith);
00233     virtual int GetCount () const;
00234     virtual iTextureWrapper *Get (int n) const;
00235     virtual int Add (iTextureWrapper *obj);
00236     virtual bool Remove (iTextureWrapper *obj);
00237     virtual bool Remove (int n);
00238     virtual void RemoveAll ();
00239     virtual int Find (iTextureWrapper *obj) const;
00240     virtual iTextureWrapper *FindByName (const char *Name) const;
00241   } scfiTextureList;
00242 };
00243 
00244 #endif // __CS_TEXTURE_H__

Generated for Crystal Space by doxygen 1.2.14