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