CrystalSpace

Public API Reference

Main Page   Modules   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

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 "qint.h"
00026 
00027 struct iTextureWrapper;
00028 struct iMaterialWrapper;
00029 struct iEngine;
00030 
00031 struct iObjectRegistry;
00032 struct iGraphics2D;
00033 struct iGraphics3D;
00034 struct iTextureManager;
00035 struct iTextureWrapper;
00036 struct iEventHandler;
00037 
00042 class csProcTexture : public csObject
00043 {
00044   friend struct ProcCallback;
00045 
00046 private:
00047   // Setup the procedural event handler (used for updating visible
00048   // proc textures).
00049   static iEventHandler* SetupProcEventHandler (iObjectRegistry* object_reg);
00050   csRef<iEventHandler> proceh;
00051 
00052 protected:
00053   // Will be set to true as soon as pt is initialized.
00054   bool ptReady;
00055 
00056   // Flags uses for the texture.
00057   int texFlags;
00058 
00059   // Texture wrapper.
00060   iTextureWrapper* tex;
00061   // Dimensions of texture.
00062   int mat_w, mat_h;
00063   csRef<iGraphics3D> g3d;
00064   csRef<iGraphics2D> g2d;
00065   iObjectRegistry* object_reg;
00066   bool anim_prepared;
00067 
00068   bool key_color;
00069   int key_red, key_green, key_blue;
00070 
00071   // If true (default) then proc texture will register a callback
00072   // so that the texture is automatically updated (Animate is called)
00073   // whenever it is used.
00074   bool use_cb;
00075 
00076 public:
00077   // The current time the previous time the callback was called.
00078   // This is used to detect if the callback is called multiple times
00079   // in one frame.
00080   csTicks last_cur_time;
00081 
00082 private:
00083   static void ProcCallback (iTextureWrapper* txt, void* data);
00084 
00085 public:
00086   csProcTexture ();
00087   virtual ~csProcTexture ();
00088 
00089   iGraphics3D* GetG3D () { return g3d; }
00090   iGraphics2D* GetG2D () { return g2d; }
00091 
00099   void DisableAutoUpdate () { use_cb = false; }
00100 
00115   virtual bool Initialize (iObjectRegistry* object_reg);
00116 
00126   iMaterialWrapper* Initialize (iObjectRegistry* object_reg, iEngine* engine,
00127         iTextureManager* txtmgr, const char* name);
00128 
00133   virtual bool PrepareAnim ();
00134 
00136   void SetKeyColor (int red, int green, int blue)
00137   {
00138     key_color = true;
00139     key_red = red;
00140     key_green = green;
00141     key_blue = blue;
00142   }
00143 
00148   virtual void Animate (csTicks current_time) = 0;
00149 
00151   iTextureWrapper* GetTextureWrapper () { return tex; }
00152 
00154   virtual void GetDimension (int &w, int &h)
00155   { w = mat_w; h = mat_h; }
00156 
00157   static int GetRandom (int max)
00158   {
00159     return int ((float(max)*rand()/(RAND_MAX+1.0)));
00160   }
00161 };
00162 
00163 
00164 #endif // __CS_PROCTEX_H__
00165 

Generated for Crystal Space by doxygen 1.2.14