CrystalSpace

Public API Reference

Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

proctex.h

00001 /*
00002     Copyright (C) 2000-2001 by Jorrit Tyberghein
00003     Copyright (C) 2000 by Samuel Humphreys
00004 
00005     This library is free software; you can redistribute it and/or
00006     modify it under the terms of the GNU Library General Public
00007     License as published by the Free Software Foundation; either
00008     version 2 of the License, or (at your option) any later version.
00009 
00010     This library 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 GNU
00013     Library General Public License for more details.
00014 
00015     You should have received a copy of the GNU Library General Public
00016     License along with this library; if not, write to the Free
00017     Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00018 */
00019 
00020 #ifndef __CS_PROCTEX_H__
00021 #define __CS_PROCTEX_H__
00022 
00023 #include "csextern.h"
00024 
00025 #include "csutil/csobject.h"
00026 #include "csutil/ref.h"
00027 #include "itexture/iproctex.h"
00028 #include "iengine/texture.h"
00029 
00030 
00031 struct iEngine;
00032 struct iEventHandler;
00033 struct iGraphics2D;
00034 struct iGraphics3D;
00035 struct iMaterialWrapper;
00036 struct iObjectRegistry;
00037 struct iTextureManager;
00038 struct iTextureWrapper;
00039 
00040 class csProcTexEventHandler;
00041 
00042 SCF_VERSION (iProcTexCallback, 0, 0, 1);
00043 
00047 struct iProcTexCallback : public iBase
00048 {
00050   virtual iProcTexture* GetProcTexture() const = 0;
00051 };
00052 
00057 class CS_CRYSTALSPACE_EXPORT csProcTexture : public csObject
00058 {
00059   friend struct csProcTexCallback;
00060   friend class csProcTexEventHandler;
00061 
00062 private:
00063   // Setup the procedural event handler (used for updating visible
00064   // proc textures).
00065   static iEventHandler* SetupProcEventHandler (iObjectRegistry* object_reg);
00066   csRef<iEventHandler> proceh;
00067 
00068 protected:
00069   // Will be set to true as soon as pt is initialized.
00070   bool ptReady;
00071 
00072   // Flags uses for the texture.
00073   int texFlags;
00074 
00075   // Texture wrapper.
00076   iTextureWrapper* tex;
00077   // Dimensions of texture.
00078   int mat_w, mat_h;
00079   csRef<iImage> proc_image;
00080   csRef<iGraphics3D> g3d;
00081   csRef<iGraphics2D> g2d;
00082   iObjectRegistry* object_reg;
00083   bool anim_prepared;
00084 
00085   bool key_color;
00086   int key_red, key_green, key_blue;
00087 
00088   // If true (default) then proc texture will register a callback
00089   // so that the texture is automatically updated (Animate is called)
00090   // whenever it is used.
00091   bool use_cb;
00092   // always animate, even if not visible
00093   bool always_animate;
00094   // Are we visible? Can be 'false' if animated w/ 'always animate'.
00095   bool visible;
00096 
00097   bool GetAlwaysAnimate () const;
00098   void SetAlwaysAnimate (bool enable);
00099 
00100   struct eiTextureWrapper : public iTextureWrapper
00101   {
00102     SCF_DECLARE_EMBEDDED_IBASE(csProcTexture);
00103     virtual iObject *QueryObject();
00104     virtual iTextureWrapper *Clone () const;
00105     virtual void SetImageFile (iImage *Image);
00106     virtual iImage* GetImageFile ();
00107     virtual void SetTextureHandle (iTextureHandle *tex);
00108     virtual iTextureHandle* GetTextureHandle ();
00109     virtual void SetKeyColor (int red, int green, int blue);
00110     virtual void GetKeyColor (int &red, int &green, int &blue) const;
00111     virtual void SetFlags (int flags);
00112     virtual int GetFlags () const;
00113     virtual void Register (iTextureManager *txtmng);
00114     virtual void SetUseCallback (iTextureCallback* callback);
00115     virtual iTextureCallback* GetUseCallback () const;
00116     virtual void Visit ();
00117     virtual bool IsVisitRequired () const;
00118     virtual void SetKeepImage (bool k);
00119     virtual bool KeepImage () const;
00120     virtual void SetTextureClass (const char* className);
00121     virtual const char* GetTextureClass ();
00122   } scfiTextureWrapper;
00123   friend struct eiTextureWrapper;
00124 
00125   struct eiProcTexture : public iProcTexture
00126   {
00127     SCF_DECLARE_EMBEDDED_IBASE(csProcTexture);
00128 
00129     virtual bool GetAlwaysAnimate () const;
00130     virtual void SetAlwaysAnimate (bool enable);
00131     virtual iTextureFactory* GetFactory();
00132   } scfiProcTexture;
00133   friend struct eiProcTexture;
00134 
00135 public:
00136   // The current time the previous time the callback was called.
00137   // This is used to detect if the callback is called multiple times
00138   // in one frame.
00139   csTicks last_cur_time;
00140 
00141 private:
00142   static void ProcCallback (iTextureWrapper* txt, void* data);
00143 
00145   csRef<iTextureFactory> parent;
00146 
00147 public:
00148   SCF_DECLARE_IBASE_EXT (csObject);
00149 
00150   csProcTexture (iTextureFactory* p = 0, iImage* image = 0);
00151   virtual ~csProcTexture ();
00152 
00153   iGraphics3D* GetG3D () { return g3d; }
00154   iGraphics2D* GetG2D () { return g2d; }
00155 
00163   void DisableAutoUpdate () { use_cb = false; }
00164 
00177   virtual bool Initialize (iObjectRegistry* object_reg);
00178 
00187   iMaterialWrapper* Initialize (iObjectRegistry* object_reg, iEngine* engine,
00188         iTextureManager* txtmgr, const char* name);
00189 
00193   virtual bool PrepareAnim ();
00194 
00196   void SetKeyColor (int red, int green, int blue)
00197   {
00198     key_color = true;
00199     key_red = red;
00200     key_green = green;
00201     key_blue = blue;
00202   }
00203 
00208   virtual void Animate (csTicks current_time) = 0;
00209 
00211   virtual void GetDimension (int &w, int &h) const
00212   { w = mat_w; h = mat_h; }
00213 
00214   static int GetRandom (int max)
00215   {
00216     return int ((float(max)*rand()/(RAND_MAX+1.0)));
00217   }
00218 
00220   iTextureWrapper* GetTextureWrapper ()
00221   { return &scfiTextureWrapper; }
00222 
00223 };
00224 
00225 #endif // __CS_PROCTEX_H__

Generated for Crystal Space by doxygen 1.4.4