cstool/proctex.h Source File (Crystal Space 2.0 Public API Reference)

| ## Public API Reference

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

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 "csutil/sysfunc.h"
    00028 #include "csextern.h"
    00029
    00030 #include "csutil/csobject.h"
    00031 #include "csutil/ref.h"
    00032 #include "csutil/scf_implementation.h"
    00033 #include "csutil/threadmanager.h"
    00034 #include "itexture/iproctex.h"
    00035 #include "itexture/itexfact.h"
    00036 #include "iengine/texture.h"
    00037 #include "iengine/engine.h"
    00038 #include "igraphic/image.h"
    00039 #include "iutil/event.h"
    00040 #include "iutil/eventh.h"
    00041 #include "iutil/selfdestruct.h"
    00042 #include "ivideo/graph2d.h"
    00043
    00044
    00045 struct iEngine;
    00046 struct iGraphics3D;
    00047 struct iMaterialWrapper;
    00048 struct iObjectRegistry;
    00049 struct iTextureManager;
    00050 struct iTextureWrapper;
    00051
    00052 class csProcTexEventHandler;
    00053
    00057 struct iProcTexCallback : public virtual iBase
    00058 {
    00059   SCF_INTERFACE(iProcTexCallback, 2,0,0);
    00061   virtual iProcTexture* GetProcTexture() const = 0;
    00062 };
    00063
    00068 class CS_CRYSTALSPACE_EXPORT csProcTexture :
    00069   public scfImplementationExt3<csProcTexture, csObject, iTextureWrapper,
    00070   iProcTexture, iSelfDestruct>, public ThreadedCallable<csProcTexture>
    00071 {
    00072   friend struct csProcTexCallback;
    00073   friend class csProcTexEventHandler;
    00074
    00075 private:
    00076   // Setup the procedural event handler (used for updating visible
    00077   // proc textures).
    00078   THREADED_CALLABLE_DECL1(csProcTexture, SetupProcEventHandler, csThreadReturn, iObjectRegistry*, object_reg, HIGH, false, false);
    00079   csRef<iEventHandler> proceh;
    00080
    00081 protected:
    00082   // Will be set to true as soon as pt is initialized.
    00083   bool ptReady;
    00084
    00085   // Flags uses for the texture.
    00086   int texFlags;
    00087
    00088   // Texture wrapper.
    00089   csRef<iTextureWrapper> tex;
    00090   // Dimensions of texture.
    00091   int mat_w, mat_h;
    00092   csRef<iImage> proc_image;
    00093   csRef<iGraphics3D> g3d;
    00094   csRef<iGraphics2D> g2d;
    00095   iObjectRegistry* object_reg;
    00096   csRef<iEngine> engine;
    00097   bool anim_prepared;
    00098
    00099   bool key_color;
    00100   int key_red, key_green, key_blue;
    00101
    00102   // If true (default) then proc texture will register a callback
    00103   // so that the texture is automatically updated (Animate is called)
    00104   // whenever it is used.
    00105   bool use_cb;
    00106   // always animate, even if not visible
    00107   bool always_animate;
    00108   // Are we visible? Can be 'false' if animated w/ 'always animate'.
    00109   bool visible;
    00110
    00117   virtual iTextureWrapper* CreateTexture (iObjectRegistry* object_reg);
    00118
    00119   virtual iObject *QueryObject();
    00120   virtual iTextureWrapper *Clone () const;
    00121   virtual void SetImageFile (iImage *Image);
    00122   virtual iImage* GetImageFile ();
    00123   virtual void SetTextureHandle (iTextureHandle *tex);
    00124   virtual iTextureHandle* GetTextureHandle ();
    00125   virtual void GetKeyColor (int &red, int &green, int &blue) const;
    00126   virtual void SetFlags (int flags);
    00127   virtual int GetFlags () const;
    00128   virtual void Register (iTextureManager *txtmng);
    00129   virtual void SetUseCallback (iTextureCallback* callback);
    00130   virtual iTextureCallback* GetUseCallback () const;
    00131   virtual void Visit ();
    00132   virtual bool IsVisitRequired () const;
    00133   virtual void SetKeepImage (bool k);
    00134   virtual bool KeepImage () const;
    00135   virtual void SetTextureClass (const char* className);
    00136   virtual const char* GetTextureClass ();
    00137
    00138   virtual bool GetAlwaysAnimate () const;
    00139   virtual void SetAlwaysAnimate (bool enable);
    00140   virtual iTextureFactory* GetFactory();
    00141
    00142   virtual void UseTexture ();
    00143 public:
    00144   // The current time the previous time the callback was called.
    00145   // This is used to detect if the callback is called multiple times
    00146   // in one frame.
    00147   csTicks last_cur_time;
    00148
    00149 private:
    00150   static void ProcCallback (iTextureWrapper* txt, void* data);
    00151
    00153   csRef<iTextureFactory> parent;
    00154
    00155 public:
    00156   csProcTexture (iTextureFactory* p = 0, iImage* image = 0);
    00157   virtual ~csProcTexture ();
    00158
    00159   iGraphics3D* GetG3D () const { return g3d; }
    00160   iGraphics2D* GetG2D () const { return g2d; }
    00161   iObjectRegistry* GetObjectRegistry () const { return object_reg; }
    00162
    00170   void DisableAutoUpdate () { use_cb = false; }
    00171
    00183   virtual bool Initialize (iObjectRegistry* object_reg);
    00184
    00193   iMaterialWrapper* Initialize (iObjectRegistry* object_reg, iEngine* engine,
    00194         iTextureManager* txtmgr, const char* name);
    00195
    00199   virtual bool PrepareAnim ();
    00200
    00202   void SetKeyColor (int red, int green, int blue)
    00203   {
    00204     key_color = true;
    00205     key_red = red;
    00206     key_green = green;
    00207     key_blue = blue;
    00208     tex->SetKeyColor (red, green, blue);
    00209   }
    00210
    00215   virtual void Animate (csTicks current_time) = 0;
    00216
    00218   virtual void GetDimension (int &w, int &h) const
    00219   { w = mat_w; h = mat_h; }
    00220
    00221   static int GetRandom (int max)
    00222   {
    00223     return int ((float(max)*rand()/(RAND_MAX+1.0)));
    00224   }
    00225
    00227   iTextureWrapper* GetTextureWrapper ()
    00228   { return this; }
    00229
    00231   virtual void SelfDestruct ();
    00232
    00233 };
    00234
    00235 #endif // __CS_PROCTEX_H__