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 "itexture/itexfact.h" 00034 #include "iengine/texture.h" 00035 #include "igraphic/image.h" 00036 #include "iutil/event.h" 00037 #include "iutil/eventh.h" 00038 #include "ivideo/graph2d.h" 00039 00040 00041 struct iEngine; 00042 struct iGraphics3D; 00043 struct iMaterialWrapper; 00044 struct iObjectRegistry; 00045 struct iTextureManager; 00046 struct iTextureWrapper; 00047 00048 class csProcTexEventHandler; 00049 00053 struct iProcTexCallback : public virtual iBase 00054 { 00055 SCF_INTERFACE(iProcTexCallback, 2,0,0); 00057 virtual iProcTexture* GetProcTexture() const = 0; 00058 }; 00059 00064 class CS_CRYSTALSPACE_EXPORT csProcTexture : 00065 public scfImplementationExt2<csProcTexture, csObject, iTextureWrapper, 00066 iProcTexture> 00067 { 00068 friend struct csProcTexCallback; 00069 friend class csProcTexEventHandler; 00070 00071 private: 00072 // Setup the procedural event handler (used for updating visible 00073 // proc textures). 00074 static iEventHandler* SetupProcEventHandler (iObjectRegistry* object_reg); 00075 csRef<iEventHandler> proceh; 00076 00077 protected: 00078 // Will be set to true as soon as pt is initialized. 00079 bool ptReady; 00080 00081 // Flags uses for the texture. 00082 int texFlags; 00083 00084 // Texture wrapper. 00085 iTextureWrapper* tex; 00086 // Dimensions of texture. 00087 int mat_w, mat_h; 00088 csRef<iImage> proc_image; 00089 csRef<iGraphics3D> g3d; 00090 csRef<iGraphics2D> g2d; 00091 iObjectRegistry* object_reg; 00092 bool anim_prepared; 00093 00094 bool key_color; 00095 int key_red, key_green, key_blue; 00096 00097 // If true (default) then proc texture will register a callback 00098 // so that the texture is automatically updated (Animate is called) 00099 // whenever it is used. 00100 bool use_cb; 00101 // always animate, even if not visible 00102 bool always_animate; 00103 // Are we visible? Can be 'false' if animated w/ 'always animate'. 00104 bool visible; 00105 00112 virtual iTextureWrapper* CreateTexture (iObjectRegistry* object_reg); 00113 00114 virtual iObject *QueryObject(); 00115 virtual iTextureWrapper *Clone () const; 00116 virtual void SetImageFile (iImage *Image); 00117 virtual iImage* GetImageFile (); 00118 virtual void SetTextureHandle (iTextureHandle *tex); 00119 virtual iTextureHandle* GetTextureHandle (); 00120 virtual void GetKeyColor (int &red, int &green, int &blue) const; 00121 virtual void SetFlags (int flags); 00122 virtual int GetFlags () const; 00123 virtual void Register (iTextureManager *txtmng); 00124 virtual void SetUseCallback (iTextureCallback* callback); 00125 virtual iTextureCallback* GetUseCallback () const; 00126 virtual void Visit (); 00127 virtual bool IsVisitRequired () const; 00128 virtual void SetKeepImage (bool k); 00129 virtual bool KeepImage () const; 00130 virtual void SetTextureClass (const char* className); 00131 virtual const char* GetTextureClass (); 00132 00133 virtual bool GetAlwaysAnimate () const; 00134 virtual void SetAlwaysAnimate (bool enable); 00135 virtual iTextureFactory* GetFactory(); 00136 00137 virtual void UseTexture (); 00138 public: 00139 // The current time the previous time the callback was called. 00140 // This is used to detect if the callback is called multiple times 00141 // in one frame. 00142 csTicks last_cur_time; 00143 00144 private: 00145 static void ProcCallback (iTextureWrapper* txt, void* data); 00146 00148 csRef<iTextureFactory> parent; 00149 00150 public: 00151 csProcTexture (iTextureFactory* p = 0, iImage* image = 0); 00152 virtual ~csProcTexture (); 00153 00154 iGraphics3D* GetG3D () { return g3d; } 00155 iGraphics2D* GetG2D () { return g2d; } 00156 00164 void DisableAutoUpdate () { use_cb = false; } 00165 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 tex->SetKeyColor (red, green, blue); 00203 } 00204 00209 virtual void Animate (csTicks current_time) = 0; 00210 00212 virtual void GetDimension (int &w, int &h) const 00213 { w = mat_w; h = mat_h; } 00214 00215 static int GetRandom (int max) 00216 { 00217 return int ((float(max)*rand()/(RAND_MAX+1.0))); 00218 } 00219 00221 iTextureWrapper* GetTextureWrapper () 00222 { return this; } 00223 00224 }; 00225 00226 #endif // __CS_PROCTEX_H__
Generated for Crystal Space 1.4.1 by doxygen 1.7.1