CrystalSpace

Public API Reference

cstool/proctex.h

Go to the documentation of this file.
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 
00027 #include "csextern.h"
00028 
00029 #include "csutil/csobject.h"
00030 #include "csutil/ref.h"
00031 #include "csutil/scf_implementation.h"
00032 #include "itexture/iproctex.h"
00033 #include "iengine/texture.h"
00034 
00035 
00036 struct iEngine;
00037 struct iEventHandler;
00038 struct iGraphics2D;
00039 struct iGraphics3D;
00040 struct iMaterialWrapper;
00041 struct iObjectRegistry;
00042 struct iTextureManager;
00043 struct iTextureWrapper;
00044 
00045 class csProcTexEventHandler;
00046 
00050 struct iProcTexCallback : public virtual iBase
00051 {
00052   SCF_INTERFACE(iProcTexCallback, 2,0,0);
00054   virtual iProcTexture* GetProcTexture() const = 0;
00055 };
00056 
00061 class CS_CRYSTALSPACE_EXPORT csProcTexture : 
00062   public scfImplementationExt2<csProcTexture, csObject, iTextureWrapper,
00063   iProcTexture>
00064 {
00065   friend struct csProcTexCallback;
00066   friend class csProcTexEventHandler;
00067 
00068 private:
00069   // Setup the procedural event handler (used for updating visible
00070   // proc textures).
00071   static iEventHandler* SetupProcEventHandler (iObjectRegistry* object_reg);
00072   csRef<iEventHandler> proceh;
00073 
00074 protected:
00075   // Will be set to true as soon as pt is initialized.
00076   bool ptReady;
00077 
00078   // Flags uses for the texture.
00079   int texFlags;
00080 
00081   // Texture wrapper.
00082   iTextureWrapper* tex;
00083   // Dimensions of texture.
00084   int mat_w, mat_h;
00085   csRef<iImage> proc_image;
00086   csRef<iGraphics3D> g3d;
00087   csRef<iGraphics2D> g2d;
00088   iObjectRegistry* object_reg;
00089   bool anim_prepared;
00090 
00091   bool key_color;
00092   int key_red, key_green, key_blue;
00093 
00094   // If true (default) then proc texture will register a callback
00095   // so that the texture is automatically updated (Animate is called)
00096   // whenever it is used.
00097   bool use_cb;
00098   // always animate, even if not visible
00099   bool always_animate;
00100   // Are we visible? Can be 'false' if animated w/ 'always animate'.
00101   bool visible;
00102 
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 GetKeyColor (int &red, int &green, int &blue) const;
00110   virtual void SetFlags (int flags);
00111   virtual int GetFlags () const;
00112   virtual void Register (iTextureManager *txtmng);
00113   virtual void SetUseCallback (iTextureCallback* callback);
00114   virtual iTextureCallback* GetUseCallback () const;
00115   virtual void Visit ();
00116   virtual bool IsVisitRequired () const;
00117   virtual void SetKeepImage (bool k);
00118   virtual bool KeepImage () const;
00119   virtual void SetTextureClass (const char* className);
00120   virtual const char* GetTextureClass ();
00121 
00122   virtual bool GetAlwaysAnimate () const;
00123   virtual void SetAlwaysAnimate (bool enable);
00124   virtual iTextureFactory* GetFactory();
00125 
00126   virtual void UseTexture ();
00127 public:
00128   // The current time the previous time the callback was called.
00129   // This is used to detect if the callback is called multiple times
00130   // in one frame.
00131   csTicks last_cur_time;
00132 
00133 private:
00134   static void ProcCallback (iTextureWrapper* txt, void* data);
00135 
00137   csRef<iTextureFactory> parent;
00138 
00139 public:
00140   csProcTexture (iTextureFactory* p = 0, iImage* image = 0);
00141   virtual ~csProcTexture ();
00142 
00143   iGraphics3D* GetG3D () { return g3d; }
00144   iGraphics2D* GetG2D () { return g2d; }
00145 
00153   void DisableAutoUpdate () { use_cb = false; }
00154 
00166   virtual bool Initialize (iObjectRegistry* object_reg);
00167 
00176   iMaterialWrapper* Initialize (iObjectRegistry* object_reg, iEngine* engine,
00177         iTextureManager* txtmgr, const char* name);
00178 
00182   virtual bool PrepareAnim ();
00183 
00185   void SetKeyColor (int red, int green, int blue)
00186   {
00187     key_color = true;
00188     key_red = red;
00189     key_green = green;
00190     key_blue = blue;
00191     tex->SetKeyColor (red, green, blue);
00192   }
00193 
00198   virtual void Animate (csTicks current_time) = 0;
00199 
00201   virtual void GetDimension (int &w, int &h) const
00202   { w = mat_w; h = mat_h; }
00203 
00204   static int GetRandom (int max)
00205   {
00206     return int ((float(max)*rand()/(RAND_MAX+1.0)));
00207   }
00208 
00210   iTextureWrapper* GetTextureWrapper ()
00211   { return this; }
00212 
00213 };
00214 
00215 #endif // __CS_PROCTEX_H__

Generated for Crystal Space by doxygen 1.4.7