Main Page   Namespace List   Class Hierarchy   Compound List   File List   Compound Members   File Members  

sprite.h

Go to the documentation of this file.
00001 /*
00002         $Id: sprite.h,v 1.1 2001/03/06 15:09:12 mbn Exp $
00003 
00004         ------------------------------------------------------------------------
00005         ClanLib, the platform independent game SDK.
00006 
00007         This library is distributed under the GNU LIBRARY GENERAL PUBLIC LICENSE
00008         version 2. See COPYING for details.
00009 
00010         For a total list of contributers see CREDITS.
00011 
00012         ------------------------------------------------------------------------
00013 
00014         File purpose:
00015                 Simple sprite support.
00016 
00017 */
00018 
00020 
00021 #ifndef header_sprite
00022 #define header_sprite
00023 
00024 #include "generic_surfaceprovider.h"
00025 #include "../../Core/IOData/inputsource.h"
00026 #include "../../Core/IOData/inputsource_provider.h"
00027 
00028 /*
00029 CreateError(CL_Error_ClanLib_Sprite, CL_Error_ClanLib, "ClanLib sprite error")
00030 CreateError(CL_Error_ClanLib_Sprite_Load, CL_Error_ClanLib_Sprite, "Error while loading sprite")
00031 */
00032 class CL_SpriteProvider : public CL_SurfaceProvider_Generic
00033 //: ClanLib datafile sprite. Used to load surfaces stored in ClanLib's datafile 
00034 //: sprite format.
00035 {
00036 protected:
00037         std::string surface_id;
00038         CL_InputSourceProvider *provider;
00039         void *surface_data;
00040         int width, height, no_sprs, transcol;
00041         CL_Palette *palette;
00042         unsigned int red_mask, green_mask, blue_mask, alpha_mask;
00043         unsigned int bpp;
00044         bool m_is_indexed;
00045 
00046         void load_data();
00047 
00048 public:
00049         static CL_Surface *create(const char *surface_id, CL_InputSourceProvider *datafile);
00050         //: Loads the sprite 'surface_id' from the inputsource provider 'datafile'. 
00051         //: Creates a surface using this sprite (surfaceprovider) and returns it.
00052         //: <br>
00053         //: This function is a easier way of typing: <br>
00054         //: CL_Surface::create(new CL_Sprite(surface_id, datafile), true);
00055 
00056         CL_SpriteProvider(const char *surface_id, CL_InputSourceProvider *datafile);
00057         //: Constructs a surface provider that represents the sprite 'surface_id' 
00058         //: from the inputsource provider 'datafile'.
00059 
00060         virtual ~CL_SpriteProvider();
00061 
00062         virtual unsigned int get_width() const;
00063         //: Returns the width of the sprite.
00064 
00065         virtual unsigned int get_height() const;
00066         //: Returns the height of the sprite.
00067 
00068         virtual unsigned int get_pitch() const;
00069         //: Returns the pitch of the sprite.
00070         
00071         virtual unsigned int get_num_frames() const;
00072         //: Returns the number of subsprites in this sprite.
00073         
00074         virtual CL_Palette *get_palette() const;
00075         //: Returns the palette used by the surface. NULL if the system palette is 
00076         //: used.
00077 
00078         virtual bool uses_src_colorkey() const;
00079         virtual unsigned int get_src_colorkey() const;
00080         //: Returns the transparency color used, or -1 if none.
00081         
00082         virtual unsigned int get_red_mask() const;
00083         virtual unsigned int get_green_mask() const;
00084         virtual unsigned int get_blue_mask() const;
00085         virtual unsigned int get_alpha_mask() const;
00086         virtual unsigned int get_depth() const;
00087         virtual bool is_indexed() const;
00088         
00089         virtual void *get_data() const;
00090         //: Returns a pointer to the sprites image data. Can only be called between 
00091         //: lock() and unlock().
00092 
00093         virtual void perform_lock();
00094         //: Locks the surface provider. This causes the sprite to retrieve its 
00095         //: surface data from the datafile.
00096         
00097         virtual void perform_unlock();
00098         //: Unlocks the surface provider. The sprite releases its surface data when
00099         //: it is called.
00100 };
00101 /*
00102 class CL_SpriteTexture : public CL_TextureProvider
00103 //: ClanLib datafile texture. Used to load textures stored in ClanLib's datafile 
00104 //: sprite format.
00105 {
00106 protected:
00107         std::string surface_id;
00108         CL_InputSourceProvider *provider;
00109         void *surface_data;
00110         int width, height, no_sprs, transcol;
00111         CL_Palette *palette;
00112         EPixelFormat pixelformat;
00113 
00114         void load_data();
00115 
00116 public:
00117         static CL_Texture *load(char *surface_id, CL_InputSourceProvider *datafile);
00118         //: Loads the texture 'surface_id' from the inputsource provider 'datafile'. 
00119         //: Creates a texture using this sprite (textureprovider) and returns it.
00120         //: <br>
00121         //: This function is a easier way of typing: <br>
00122         //: <code>CL_Texture::create(new CL_SpriteTexture(surface_id, datafile), true);</code>
00123 
00124         CL_SpriteTexture(char *surface_id, CL_InputSourceProvider *datafile);
00125         //: Constructs a texture provider that represents the sprite 'surface_id' 
00126         //: from the inputsource provider 'datafile'.
00127 
00128         virtual ~CL_SpriteTexture();
00129 
00130         virtual unsigned int get_width();
00131         //: Returns the width of the sprite.
00132 
00133         virtual unsigned int get_height();
00134         //: Returns the height of the sprite.
00135 
00136         virtual unsigned int get_no_mipmaps() { return 1; }
00137         //: Returns the number of mipmaps in the sprite.
00138 
00139         virtual EPixelFormat get_pixel_format();
00140         //: Returns the pixel format used by the sprite.
00141 
00142         virtual CL_Palette *get_palette();
00143         //: Returns the palette used by the texture. NULL if the system palette is 
00144         //: used.
00145 
00146         virtual int get_transcol();
00147         //: Returns the transparency color used, or -1 if none.
00148 
00149         virtual void *get_data();
00150         //: Returns a pointer to the sprites image data. Can only be called between 
00151         //: lock() and unlock().
00152 
00153         virtual void lock();
00154         //: Locks the texture provider. This causes the sprite to retrieve its 
00155         //: surface data from the datafile.
00156 
00157         virtual void unlock();
00158         //: Unlocks the texture provider. The sprite releases its surface data when
00159         //: it is called.
00160 };
00161 */
00162 #endif

Generated at Wed Apr 4 19:54:03 2001 for ClanLib by doxygen1.2.6 written by Dimitri van Heesch, © 1997-2001