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

canvas.h

Go to the documentation of this file.
00001 /*
00002         $Id: canvas.h,v 1.4 2001/03/08 15:17:07 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                 Empty space dynamic surface provider header file
00016 
00017 */
00018 
00020 
00021 #ifndef header_canvas
00022 #define header_canvas
00023 
00024 #include "generic_surfaceprovider.h"
00025 #include "../../Core/System/cl_assert.h"
00026 
00027 class CL_Canvas : public CL_SurfaceProvider
00028 //: Empty surfaceprovider to be used as a rendering target.
00029 // <p>CL_Canvas is a surface provider useful to create images at
00030 // run-time.</p>
00031 //
00032 // <p>When constructed, the surface provider will contain an empty image
00033 // buffer of the specified dimensions. It is then the intention that the
00034 // game fills the buffer with data.</p>
00035 //
00036 // <p>There are three ways to do this (and you can mix them as you
00037 // please):</p>
00038 //
00039 // <ul>
00040 // <li>Lock() the provider, and then call get_data() to get a pointer to the
00041 // image buffer. Party on it. And then finally unlock() the provider.</li>
00042 //
00043 // <li>Use the drawing primitives available in CL_Target. This includes line
00044 // drawing, fill rects and clipping.</li>
00045 //
00046 // <li>Use the put_target() function in CL_Surface (create the image from
00047 // other surfaces).</li>
00048 // </ul>
00049 {
00050 public:
00051         static CL_Surface *create(
00052                 int width,
00053                 int height,
00054                 int no_sprs = 1,
00055                 int red_mask   = 0xff000000,
00056                 int green_mask = 0x00ff0000,
00057                 int blue_mask  = 0x0000ff00,
00058                 int alpha_mask = 0x000000ff,
00059                 bool use_transcol = false,
00060                 unsigned int transcol = 0)
00061         {
00062                 return CL_Surface::create(
00063                         new CL_Canvas(
00064                                 width,
00065                                 height,
00066                                 no_sprs,
00067                                 red_mask,
00068                                 green_mask, 
00069                                 blue_mask,
00070                                 alpha_mask,
00071                                 use_transcol,
00072                                 transcol),
00073                         true);
00074         }
00075         //: Creates the surface.
00085 
00086         // has to be blitted by the dynamic blitter at the moment
00087         CL_Canvas(
00088                 int width,
00089                 int height,
00090                 int no_sprs = 1,
00091                 int red_mask   = 0xff000000,
00092                 int green_mask = 0x00ff0000,
00093                 int blue_mask  = 0x0000ff00, 
00094                 int alpha_mask = 0x000000ff,
00095                 bool use_transcol = false,
00096                 unsigned int transcol = 0)
00097         {
00098                 this->width = width;
00099                 this->height = height;
00100                 this->no_sprs = no_sprs;
00101                 this->transcol = transcol;
00102                 this->red_mask = red_mask;
00103                 this->green_mask = green_mask;
00104                 this->blue_mask = blue_mask;
00105                 this->alpha_mask = alpha_mask;
00106                 this->use_transcol = use_transcol;
00107                 
00108                 bpp = get_depth();
00109                 
00110                 data = new unsigned char[width * height * no_sprs * get_bytes_per_pixel()]; 
00111 //              bzero(data, width * height * no_sprs * bpp);
00112         }  
00113         //: Constructs the Canvas.
00123 
00124 
00125 
00126         virtual ~CL_Canvas() 
00127         { 
00128                 delete[] data; 
00129 //              if (palette!=NULL) delete palette;
00130         }
00131         //: Deletes the DynamicProvider and deletes the data
00132         //: which was allocated in the constructor
00133 
00134         virtual unsigned int get_width() const { return width; }
00135         //: Returns the width of the surface
00136 
00137         virtual unsigned int get_height() const { return height; }
00138         //: Returns  the height of the surface
00139 
00140         virtual unsigned int get_num_frames() const { return no_sprs; }
00141         //: Returns the number of frames (sprites) for this surface     
00142 
00143         virtual unsigned int get_red_mask() const { return red_mask; }
00144         //: Returns the bit mask for red 
00145 
00146         virtual unsigned int get_green_mask() const { return green_mask; }
00147         //: Returns the bit mask for green
00148 
00149         virtual unsigned int get_blue_mask() const { return blue_mask; }
00150         //: Returns the bit mask for blue
00151 
00152         virtual unsigned int get_alpha_mask() const { return alpha_mask; }
00153         //: Returns the bit mask for the alpha 
00154 
00155         virtual unsigned int get_pitch() const { return ((bpp+7)/8)*get_width(); }
00156         //: returns the pitch of the surface
00157 
00158         virtual bool is_indexed() const { return false; }
00159         //: returns true if the surface uses indexed colors
00160         //: which is currently not supported (it always
00161         //: returns false)
00162 
00163         virtual void set_palette(CL_Palette* palette) { ; }
00164         //: CL_Canvas doesn't work with PAL8
00165 
00166         virtual CL_Palette *get_palette() const { return NULL; }
00167         //: CL_Canvas doesn't work with PAL8
00168         //retval! NULL
00169 
00170         virtual void set_src_colorkey(unsigned int transcol) { this->transcol = transcol; }
00171         //: Sets the transparent color
00172 
00173         virtual bool uses_src_colorkey() const { return use_transcol; }
00174         virtual unsigned int get_src_colorkey() const { return transcol; }
00175         //: Returns the transparent color, which was set in the constructor
00176 
00177         virtual void *get_data() const { cl_assert(data!=NULL); return data; }
00178         //: Returns the pointer to the surface data, where you
00179         //: can copy your data to. It should be
00180         //: only called between lock() and unlock(). 
00181 
00182         virtual void lock() { }
00183         //: Locks the surface so that writing to the surface
00184         //: may occur.
00185 
00186         virtual void unlock() { }
00187         //: Unlocks the surface.
00188         //: ( Call Unlock when all writing to the surface is done )
00189 
00190 
00191 private:
00192 //      CL_Palette* palette;
00193         int width, height, no_sprs, transcol;
00194         int red_mask, green_mask, blue_mask, alpha_mask;
00195         EPixelFormat pixelformat;
00196         unsigned char *data;
00197         int bpp;
00198         bool use_transcol;
00199 };
00200 
00201 #endif

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