cstool/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 <stdarg.h> 00024 #include "csutil/csobject.h" 00025 #include "itexture/iproctex.h" 00026 #include "iengine/texture.h" 00027 #include "iutil/eventh.h" 00028 #include "ivideo/graph2d.h" 00029 #include "ivideo/graph3d.h" 00030 #include "qint.h" 00031 00032 struct iTextureWrapper; 00033 struct iMaterialWrapper; 00034 struct iEngine; 00035 00036 struct iObjectRegistry; 00037 struct iTextureManager; 00038 struct iTextureWrapper; 00039 00040 class ProcEventHandler; 00041 00046 class csProcTexture : public csObject 00047 { 00048 friend struct csProcTexCallback; 00049 friend class ProcEventHandler; 00050 00051 private: 00052 // Setup the procedural event handler (used for updating visible 00053 // proc textures). 00054 static iEventHandler* SetupProcEventHandler (iObjectRegistry* object_reg); 00055 csRef<iEventHandler> proceh; 00056 00057 protected: 00058 // Will be set to true as soon as pt is initialized. 00059 bool ptReady; 00060 00061 // Flags uses for the texture. 00062 int texFlags; 00063 00064 // Texture wrapper. 00065 iTextureWrapper* tex; 00066 // Dimensions of texture. 00067 int mat_w, mat_h; 00068 csRef<iGraphics3D> g3d; 00069 csRef<iGraphics2D> g2d; 00070 iObjectRegistry* object_reg; 00071 bool anim_prepared; 00072 00073 bool key_color; 00074 int key_red, key_green, key_blue; 00075 00076 // If true (default) then proc texture will register a callback 00077 // so that the texture is automatically updated (Animate is called) 00078 // whenever it is used. 00079 bool use_cb; 00080 // always animate, even if not visible 00081 bool always_animate; 00082 // Are we visible? Can be 'false' if animated w/ 'always animate'. 00083 bool visible; 00084 00085 bool GetAlwaysAnimate (); 00086 void SetAlwaysAnimate (bool enable); 00087 00088 struct eiTextureWrapper : public iTextureWrapper 00089 { 00090 SCF_DECLARE_EMBEDDED_IBASE(csProcTexture); 00091 virtual iObject *QueryObject(); 00092 virtual iTextureWrapper *Clone () const; 00093 virtual void SetImageFile (iImage *Image); 00094 virtual iImage* GetImageFile (); 00095 virtual void SetTextureHandle (iTextureHandle *tex); 00096 virtual iTextureHandle* GetTextureHandle (); 00097 virtual void SetKeyColor (int red, int green, int blue); 00098 virtual void GetKeyColor (int &red, int &green, int &blue); 00099 virtual void SetFlags (int flags); 00100 virtual int GetFlags (); 00101 virtual void Register (iTextureManager *txtmng); 00102 virtual void SetUseCallback (iTextureCallback* callback); 00103 virtual iTextureCallback* GetUseCallback (); 00104 virtual void Visit (); 00105 virtual bool IsVisitRequired () const; 00106 virtual void SetKeepImage (bool k); 00107 virtual bool KeepImage () const; 00108 } scfiTextureWrapper; 00109 friend struct eiTextureWrapper; 00110 00111 struct eiProcTexture : public iProcTexture 00112 { 00113 SCF_DECLARE_EMBEDDED_IBASE(csProcTexture); 00114 00115 virtual bool GetAlwaysAnimate (); 00116 virtual void SetAlwaysAnimate (bool enable); 00117 } scfiProcTexture; 00118 friend struct eiProcTexture; 00119 00120 public: 00121 // The current time the previous time the callback was called. 00122 // This is used to detect if the callback is called multiple times 00123 // in one frame. 00124 csTicks last_cur_time; 00125 00126 private: 00127 static void ProcCallback (iTextureWrapper* txt, void* data); 00128 00129 public: 00130 SCF_DECLARE_IBASE_EXT (csObject); 00131 00132 csProcTexture (); 00133 virtual ~csProcTexture (); 00134 00135 iGraphics3D* GetG3D () { return g3d; } 00136 iGraphics2D* GetG2D () { return g2d; } 00137 00145 void DisableAutoUpdate () { use_cb = false; } 00146 00161 virtual bool Initialize (iObjectRegistry* object_reg); 00162 00172 iMaterialWrapper* Initialize (iObjectRegistry* object_reg, iEngine* engine, 00173 iTextureManager* txtmgr, const char* name); 00174 00179 virtual bool PrepareAnim (); 00180 00182 void SetKeyColor (int red, int green, int blue) 00183 { 00184 key_color = true; 00185 key_red = red; 00186 key_green = green; 00187 key_blue = blue; 00188 } 00189 00194 virtual void Animate (csTicks current_time) = 0; 00195 00197 virtual void GetDimension (int &w, int &h) 00198 { w = mat_w; h = mat_h; } 00199 00200 static int GetRandom (int max) 00201 { 00202 return int ((float(max)*rand()/(RAND_MAX+1.0))); 00203 } 00204 00206 iTextureWrapper* GetTextureWrapper () 00207 { return &scfiTextureWrapper; /*return tex;*/ } 00208 }; 00209 00210 00211 #endif // __CS_PROCTEX_H__ 00212
Generated for Crystal Space by doxygen 1.2.18