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

surface.h

Go to the documentation of this file.
00001 /*
00002         $Id: surface.h,v 1.1 2001/03/06 15:09:10 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 
00016 
00017 #ifndef header_surface
00018 #define header_surface
00019 
00020 class CL_DisplayCard;
00021 class CL_SurfaceProvider;
00022 class CL_Target;
00023 class CL_ResourceManager;
00024 
00025 class CL_Surface
00026 //: Image class in ClanLib.
00027 // <p>This class is used to draw 2D images onto the backbuffer or to a
00028 // <a class="CL_Target">renderer target</a>.</p>
00029 //
00030 // <p>In ClanLib, a surface is understood
00031 // to be an image represented in a form, where it is most suitable for as
00032 // fast rendering as possible. Unlike many other libraries, it is not
00033 // possible to get direct access to the surface data.</p>
00034 //
00035 // <p>A surface uses a <a class="CL_SurfaceProvider">surface provider</a> to
00036 // load its data. It is passed at creation time, and you can either roll
00037 // your own provider, or use one already available in ClanLib.</p>
00038 //
00039 // <p>It is also possible to create a surface from a resource source. This
00040 // will allow you to load an image using a resource ID instead of directly
00041 // specifying the image in your source code.</p>
00042 //
00043 // <b>Dynamic surfaces</b>
00044 //
00045 // <p>If you have an image which changes very frequently (eg. each
00046 // frame), you want to use a dynamic surface instead. The difference is that
00047 // the surface won't cache the image, and it won't convert it to another
00048 // image format more suitable for the display target. Note that this is only
00049 // faster if you change your image very frequently - otherwise a normal
00050 // surface is the best solution.</p>
00051 //
00052 // <p>When constructing your own images, you will most likely find the <a
00053 // class="CL_Canvas">canvas surface provider</a> interesting. This class
00054 // will make it easier to create a custom drawing area where you can draw
00055 // your image.</p>
00056 //
00057 // <p>All surfaceproviders is a <a class="CL_Target">renderer target</a>.
00058 // However, most of the normal surface providers are "read only", meaning
00059 // that their image data will only remain intact during a lock session. This
00060 // is because the providers consume less memory when the image is only
00061 // available, when someone needs it. Only the <a class="CL_Canvas">canvas
00062 // provider</a> will not destroy the image.</p>
00063 //
00064 // <p>A surface can blit (draw itself) itself to the backbuffer, or to a
00065 // renderer target. This means that you can use the surface to draw one
00066 // surface provider to another.</p>
00067 {
00068 public:
00070         static CL_Surface *load(
00071                 const char *resource_id,
00072                 CL_ResourceManager *manager);
00073         //: This function loads a surface from a resource file (usually a datafile).
00074 
00075         static CL_Surface *create(
00076                 CL_SurfaceProvider *provider,
00077                 bool delete_provider=false);
00078         //: This function creates a CL_Surface instance being blitted by a caching blitter.
00082 
00083         static CL_Surface *create_dynamic(
00084                 CL_SurfaceProvider *provider,
00085                 bool delete_provider=false);
00086         //: This function creates a CL_Surface instance being blitted by the dynamic (non caching) blitter.
00087         //: You don't need to call reload with dynamic surfaces as they do that by themselves. 
00091 
00093         CL_Surface();
00094         //: Empty constructor, you need to assign a surface to the
00095         //: CL_Surface object first before it becomes useable
00096 
00097         CL_Surface(
00098                 CL_SurfaceProvider *provider,
00099                 bool delete_provider = false,
00100                 bool dynamic = false,
00101                 class CL_Resource *resource = NULL);
00102         //: This function creates a CL_Surface.
00103         //  If dynamic is true, the surface will be a dynamic blitter. If false, it will be a caching blitter.
00108 
00109         CL_Surface(
00110                 const char *resource_id,
00111                 CL_ResourceManager *manager);
00112         //: Loads a surface from a resource file.
00113 
00114         CL_Surface(const CL_Surface &surface);
00115         //: Make a copy of an other surface, but share the image data.
00116 
00117         virtual ~CL_Surface();
00118 
00120         operator bool () const;
00121         //: You can use this operator to check if the surface is
00122         //: valid, to do that you write something like this: if (surf) {...}
00123 
00124         const CL_Surface& operator=(const CL_Surface& surf);
00125 
00126         void reload();
00127         //: Forces surface to reload surface data from provider.
00128 
00129         CL_SurfaceProvider *get_provider() const;
00130         //: Returns the surface provider used by this surface.
00133 
00134         void put_screen(
00135                 int x,
00136                 int y,
00137                 int spr_no=0,
00138                 CL_DisplayCard *card=NULL);
00139         //: Draws the surface onto the backbuffer.
00144 
00145         void put_screen(
00146                 int x,
00147                 int y,
00148                 float scale_x,
00149                 float scale_y,
00150                 int spr_no=0,
00151                 CL_DisplayCard *card=NULL);
00152         //: Draws the surface onto the backbuffer - scaling it to a specified size.
00159 
00160         void put_screen(
00161                 int x,
00162                 int y,
00163                 int size_x,
00164                 int size_y,
00165                 int spr_no=0,
00166                 CL_DisplayCard *card=NULL);
00167         //: Draws the surface onto the backbuffer - scaling it to a specified size.
00174 
00175         void put_target(
00176                 int x,
00177                 int y,
00178                 int spr_no,
00179                 CL_Target *target);
00180         //: Draws the surface to a target.
00185 
00186         unsigned int get_width() const;
00187         //: Returns the width of the surface
00188 
00189         unsigned int get_height() const;
00190         //: Returns the height of the surface
00191 
00192         unsigned int get_num_frames() const;
00193         //: Returns the number of frames/subsprites in the surface
00194 
00195         bool is_video(CL_DisplayCard *card = NULL) const;
00196         //: returns true if in videomemory 
00197         //: on the specified card (null = current dispcard).
00198         
00199         bool is_loaded(CL_DisplayCard *card = NULL) const;
00200         //: returns true if loaded in either video- or system-memory
00201 
00202         bool convert_video(CL_DisplayCard *card = NULL);
00203         //: returns true if successfully loaded into videomemory, or already there
00204 
00205         bool convert_system(CL_DisplayCard *card = NULL);
00206         //: convert surface to system memory - never fails! (or serious heap usage!)
00207 
00208         void flush(CL_DisplayCard *card = NULL);
00209         //: completely flushes surface (removes from video/system-memory)
00210 
00212         CL_Surface(class CL_Surface_Generic *impl);
00213         class CL_Surface_Generic *impl;
00214 };
00215 
00216 #endif

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