Main Page | Modules | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members | Related Pages
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 "itexture/itexfact.h" 00033 #include "csqint.h" 00034 00035 struct iMaterialWrapper; 00036 struct iEngine; 00037 00038 struct iObjectRegistry; 00039 struct iTextureManager; 00040 struct iTextureWrapper; 00041 00042 class ProcEventHandler; 00043 00044 SCF_VERSION (iProcTexCallback, 0, 0, 1); 00045 00049 struct iProcTexCallback : public iBase 00050 { 00052 virtual iProcTexture* GetProcTexture() const = 0; 00053 }; 00054 00059 class CS_CSTOOL_EXPORT csProcTexture : public csObject 00060 { 00061 friend struct csProcTexCallback; 00062 friend class ProcEventHandler; 00063 00064 private: 00065 // Setup the procedural event handler (used for updating visible 00066 // proc textures). 00067 static iEventHandler* SetupProcEventHandler (iObjectRegistry* object_reg); 00068 csRef<iEventHandler> proceh; 00069 00070 protected: 00071 // Will be set to true as soon as pt is initialized. 00072 bool ptReady; 00073 00074 // Flags uses for the texture. 00075 int texFlags; 00076 00077 // Texture wrapper. 00078 iTextureWrapper* tex; 00079 // Dimensions of texture. 00080 int mat_w, mat_h; 00081 csRef<iImage> proc_image; 00082 csRef<iGraphics3D> g3d; 00083 csRef<iGraphics2D> g2d; 00084 iObjectRegistry* object_reg; 00085 bool anim_prepared; 00086 00087 bool key_color; 00088 int key_red, key_green, key_blue; 00089 00090 // If true (default) then proc texture will register a callback 00091 // so that the texture is automatically updated (Animate is called) 00092 // whenever it is used. 00093 bool use_cb; 00094 // always animate, even if not visible 00095 bool always_animate; 00096 // Are we visible? Can be 'false' if animated w/ 'always animate'. 00097 bool visible; 00098 00099 bool GetAlwaysAnimate () const; 00100 void SetAlwaysAnimate (bool enable); 00101 00102 struct eiTextureWrapper : public iTextureWrapper 00103 { 00104 SCF_DECLARE_EMBEDDED_IBASE(csProcTexture); 00105 virtual iObject *QueryObject(); 00106 virtual iTextureWrapper *Clone () const; 00107 virtual void SetImageFile (iImage *Image); 00108 virtual iImage* GetImageFile (); 00109 virtual void SetTextureHandle (iTextureHandle *tex); 00110 virtual iTextureHandle* GetTextureHandle (); 00111 virtual void SetKeyColor (int red, int green, int blue); 00112 virtual void GetKeyColor (int &red, int &green, int &blue) const; 00113 virtual void SetFlags (int flags); 00114 virtual int GetFlags () const; 00115 virtual void Register (iTextureManager *txtmng); 00116 virtual void SetUseCallback (iTextureCallback* callback); 00117 virtual iTextureCallback* GetUseCallback () const; 00118 virtual void Visit (); 00119 virtual bool IsVisitRequired () const; 00120 virtual void SetKeepImage (bool k); 00121 virtual bool KeepImage () const; 00122 virtual void SetTextureClass (const char* className); 00123 virtual const char* GetTextureClass (); 00124 } scfiTextureWrapper; 00125 friend struct eiTextureWrapper; 00126 00127 struct eiProcTexture : public iProcTexture 00128 { 00129 SCF_DECLARE_EMBEDDED_IBASE(csProcTexture); 00130 00131 virtual bool GetAlwaysAnimate () const; 00132 virtual void SetAlwaysAnimate (bool enable); 00133 virtual iTextureFactory* GetFactory(); 00134 } scfiProcTexture; 00135 friend struct eiProcTexture; 00136 00137 public: 00138 // The current time the previous time the callback was called. 00139 // This is used to detect if the callback is called multiple times 00140 // in one frame. 00141 csTicks last_cur_time; 00142 00143 private: 00144 static void ProcCallback (iTextureWrapper* txt, void* data); 00145 00147 csRef<iTextureFactory> parent; 00148 00149 public: 00150 SCF_DECLARE_IBASE_EXT (csObject); 00151 00152 csProcTexture (iTextureFactory* p = 0, iImage* image = 0); 00153 virtual ~csProcTexture (); 00154 00155 iGraphics3D* GetG3D () { return g3d; } 00156 iGraphics2D* GetG2D () { return g2d; } 00157 00165 void DisableAutoUpdate () { use_cb = false; } 00166 00179 virtual bool Initialize (iObjectRegistry* object_reg); 00180 00189 iMaterialWrapper* Initialize (iObjectRegistry* object_reg, iEngine* engine, 00190 iTextureManager* txtmgr, const char* name); 00191 00195 virtual bool PrepareAnim (); 00196 00198 void SetKeyColor (int red, int green, int blue) 00199 { 00200 key_color = true; 00201 key_red = red; 00202 key_green = green; 00203 key_blue = blue; 00204 } 00205 00210 virtual void Animate (csTicks current_time) = 0; 00211 00213 virtual void GetDimension (int &w, int &h) const 00214 { w = mat_w; h = mat_h; } 00215 00216 static int GetRandom (int max) 00217 { 00218 return int ((float(max)*rand()/(RAND_MAX+1.0))); 00219 } 00220 00222 iTextureWrapper* GetTextureWrapper () 00223 { return &scfiTextureWrapper; } 00224 00225 }; 00226 00227 #endif // __CS_PROCTEX_H__
Generated for Crystal Space by doxygen 1.3.9.1