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