pixelblock.h

00001 /*--License:
00002         Kyra Sprite Engine
00003         Copyright Lee Thomason (Grinning Lizard Software) 2001-2005
00004         www.grinninglizard.com/kyra
00005         www.sourceforge.net/projects/kyra
00006 
00007         Kyra is provided under the LGPL. 
00008         
00009         I kindly request you display a splash screen (provided in the HTML documentation)
00010         to promote Kyra and acknowledge the software and everyone who has contributed to it, 
00011         but it is not required by the license.
00012 
00013 --- LGPL License --
00014 
00015     This library is free software; you can redistribute it and/or
00016     modify it under the terms of the GNU Lesser General Public
00017     License as published by the Free Software Foundation; either
00018     version 2.1 of the License, or (at your option) any later version.
00019 
00020     This library is distributed in the hope that it will be useful,
00021     but WITHOUT ANY WARRANTY; without even the implied warranty of
00022     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00023     Lesser General Public License for more details.
00024 
00025     You should have received a copy of the GNU Lesser General Public
00026     License along with this library; if not, write to the Free Software
00027     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00028 
00029         The full text of the license can be found in lgpl.txt
00030 */
00031 
00032 #ifndef KYRA_PIXELBLOCK_INCLUDED
00033 #define KYRA_PIXELBLOCK_INCLUDED
00034 
00035 
00036 #include "../../grinliz/gltypes.h"
00037 #include "../../grinliz/gldebug.h"
00038 #include "../engine/krmath.h"
00039 #include "SDL.h"
00040 #include "painter.h"
00041 #include "ogltexture.h"
00042 
00043 
00044 class LinearMemoryPool;
00045 
00046 
00047 /*      A block of memory that is a framebuffer. Used by the canvas
00048         resource and tiles. 
00049 */
00050 
00051 class KrPixelBlock
00052 {
00053   public:
00054         KrPixelBlock();
00055         ~KrPixelBlock();
00056 
00057         /*  The draw function is modified to accomidate both
00058                 the tile and the canvas.
00059 
00060                 @param paintInfo        The target surface information.
00061                 @param x                        The target x, ignoring clipping.
00062                 @param y                        The target y, ignoring clipping.
00063                 @param invert           If true, the PixelBlock will draw upside down.
00064                                                         Used for the tile.
00065                 @param clipping         The clipping rectangle. Can be null.
00066         */
00067         void Draw( KrPaintInfo* paintInfo,
00068                            const KrMatrix2& matrix,
00069                            bool invert,
00070                            const KrColorTransform& cForm,
00071                            const grinliz::Rectangle2I& clipping,
00072                            int quality );       
00073 
00074         // Reads the block from a stream.
00075         bool Read( SDL_RWops* data );
00076 
00077         // The encoder uses this to create the block.
00078         bool Create( KrPaintInfo* surface, 
00079                                  int x, int y, int width, int height );
00080 
00081         // Creates an uninitialized pixel block.
00082         bool Create( int width, int height, bool alphaSupport );
00083 
00084         // Writes the block to the stream.
00085         bool Write( SDL_RWops* stream );
00086 
00087         int Width()     const   { return size.x; }      
00088         int Height() const      { return size.y; }      
00089         bool Alpha() const      { return (flags & ALPHA) != 0; }
00090 
00091         /*  Can be used to read or write the pixel block. The Tile uses
00092                 Pixels to do specialized drawing. The Canvas uses this to 
00093                 write to the pixel buffer.
00094         */
00095         KrRGBA* Pixels()        { return block; }
00096 
00097         // Convenience access for the tiles:
00098         KrRGBA* LowerLeftPixels()       { return block + (size.y-1) * size.x; }
00099         KrRGBA* LowerRightPixels()      { return block + (size.y-1) * size.x + size.x - 1; }
00100         KrRGBA* UpperRightPixels()      { return block + size.x - 1; }
00101 
00102         // Count all the parts of this object. Used by the encoder.
00103         void CountComponents( U32* numRGBA );
00104 
00105         void CalculateBounds( const KrMatrix2& xForm, grinliz::Rectangle2I* bounds ) const;
00106 
00107 //      static void SetMemoryPool( LinearMemoryPool* _memoryPool )      { memoryPool = _memoryPool; }
00108 
00109         #ifdef DEBUG
00110                 static U32 numRGBA;
00111         #endif
00112         
00113         // Needs to be called by Refresh, or when the pixel block data changes.
00114         void LoadNewTexture();
00115 
00116         void DrawOpenGL(                KrPaintInfo* paintInfo,
00117                                                         const KrMatrix2& matrix,
00118                                                         const KrColorTransform& cForm,
00119                                                         const grinliz::Rectangle2I& clipping,
00120                                                         int rotation );
00121 
00122         // Normally, you would never call these directly, they are
00123         // called through "Draw". However, sometimes it's nice to 
00124         // be able to get to a specific one.
00125         void DrawScaled(                KrPaintInfo* paintInfo,
00126                                                         const KrMatrix2& xForm,
00127                                                         const KrColorTransform& cForm,
00128                                                         const grinliz::Rectangle2I& clipping,
00129                                                         int quality,
00130                                                         bool invert );
00131         void DrawScaledFast(    KrPaintInfo* paintInfo,
00132                                                         const KrMatrix2& xForm,
00133                                                         const KrColorTransform& cForm,
00134                                                         const grinliz::Rectangle2I& clipping,
00135                                                         bool invert );
00136         void DrawScaledDown(    KrPaintInfo* paintInfo,
00137                                                         const KrMatrix2& xForm,
00138                                                         const KrColorTransform& cForm,
00139                                                         const grinliz::Rectangle2I& clipping );
00140         void DrawScaledLinear(  KrPaintInfo* paintInfo,
00141                                                         const KrMatrix2& xForm,
00142                                                         const KrColorTransform& cForm,
00143                                                         const grinliz::Rectangle2I& clipping );
00144 
00145   protected:
00146         enum {
00147                 ALPHA           = 0x01,
00148                 MEMORYPOOL      = 0x02,
00149         };
00150 
00151 //      static LinearMemoryPool* memoryPool;
00152         U32                     flags;                          // U32 LE
00153         grinliz::Vector2I       size;           // S32 x 2
00154         KrRGBA*         block;
00155         KrTexture*      texture;
00156 };
00157 
00158 
00159 #endif

Generated on Thu Jul 20 20:45:32 2006 for Kyra by  doxygen 1.4.7