CrystalSpace

Public API Reference

Main Page   Modules   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File 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   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   SCF_DECLARE_IBASE_EXT (csObject);
00161 
00162   //-------------------- iTextureWrapper implementation -----------------------
00163   struct TextureWrapper : public iTextureWrapper
00164   {
00165     SCF_DECLARE_EMBEDDED_IBASE (csTextureWrapper);
00166 
00167     virtual csTextureWrapper *GetPrivateObject()
00168     {return scfParent;}
00169 
00170     virtual iObject *QueryObject();
00171     virtual iTextureWrapper *Clone () const
00172     { return &(new csTextureWrapper (*scfParent))->scfiTextureWrapper; }
00173     virtual void SetImageFile (iImage *Image);
00174     virtual iImage* GetImageFile ();
00175     virtual void SetTextureHandle (iTextureHandle *tex);
00176     virtual iTextureHandle* GetTextureHandle ();
00177     virtual void SetKeyColor (int red, int green, int blue);
00178     virtual void GetKeyColor (int &red, int &green, int &blue);
00179     virtual void SetFlags (int flags);
00180     virtual int GetFlags ();
00181     virtual void Register (iTextureManager *txtmng);
00182     virtual void SetUseCallback (iTextureCallback* callback);
00183     virtual iTextureCallback* GetUseCallback ();
00184     virtual void Visit ();
00185     virtual void SetKeepImage (bool k) { scfParent->keep_image = k; }
00186     virtual bool KeepImage () const { return scfParent->keep_image; }
00187   } scfiTextureWrapper;
00188   friend struct TextureWrapper;
00189 };
00190 
00194 class csTextureList : public csRefArrayObject<iTextureWrapper>
00195 {
00196 public:
00198   csTextureList ();
00199   virtual ~csTextureList () { }
00200 
00202   iTextureWrapper *NewTexture (iImage *image);
00203 
00208   iTextureWrapper *NewTexture (iTextureHandle *ith);
00209 
00210   SCF_DECLARE_IBASE;
00211 
00212   //-------------------- iTextureList implementation -------------------------
00213   class TextureList : public iTextureList
00214   {
00215   public:
00216     SCF_DECLARE_EMBEDDED_IBASE (csTextureList);
00217 
00218     virtual iTextureWrapper *NewTexture (iImage *image);
00219     virtual iTextureWrapper *NewTexture (iTextureHandle *ith);
00220     virtual int GetCount () const;
00221     virtual iTextureWrapper *Get (int n) const;
00222     virtual int Add (iTextureWrapper *obj);
00223     virtual bool Remove (iTextureWrapper *obj);
00224     virtual bool Remove (int n);
00225     virtual void RemoveAll ();
00226     virtual int Find (iTextureWrapper *obj) const;
00227     virtual iTextureWrapper *FindByName (const char *Name) const;
00228   } scfiTextureList;
00229 };
00230 
00231 #endif // __CS_TEXTURE_H__

Generated for Crystal Space by doxygen 1.2.14