Main Page   Class Hierarchy   Compound List   File List   Compound Members  

painter.h

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 SURFACE_INCLUDED
00070 #define SURFACE_INCLUDED
00071 
00072 #pragma warning( disable : 4530 )
00073 #pragma warning( disable : 4786 )
00074 #include <string>
00075 
00076 #include "SDL.h"
00077 #include "../util/gltypes.h"
00078 #include "color.h"
00079 #include "../engine/krmath.h"
00080 #include "../engine/kyrabuild.h"
00081 
00082 struct KrPaintInfo;
00083 class KrTexture;
00084 
00085  
00091 class KrPainter
00092 {
00093   public:
00094         KrPainter( SDL_Surface* _surface );
00095         KrPainter( KrPaintInfo* _info );
00096 
00097         ~KrPainter();
00098 
00103         void SetPixel( int x, int y, const KrRGBA& color );
00104 
00106         void SetPixel( void* target, U8 red, U8 green, U8 blue, U8 alpha );
00107 
00109         void DrawBox(   int x, int y, int w, int h,
00110                                         U8 red, U8 green, U8 blue );
00111 
00113         void DrawBox(   int x, int y, int w, int h,
00114                                         const KrRGBA* colors, int nColors );
00115 
00117         void DrawFilledBox(     int x, int y, int w, int h,
00118                                                 U8 red, U8 green, U8 blue );
00119 
00121         void DrawVLine( int x, int y, int h, 
00122                                         U8 red, U8 green, U8 blue );
00123 
00125         void DrawVLine( int x, int y, int h, 
00126                                         const KrRGBA* colors, int nColors );
00127 
00128 
00130         void DrawHLine( int x, int y, int h, 
00131                                         U8 red, U8 green, U8 blue );            
00132 
00134         void DrawHLine( int x, int y, int h, 
00135                                         const KrRGBA* colors, int nColors );            
00136 
00137         /*  Given the starting location, and a maximum width,
00138                 returns the number of consectutive transparent pixels.
00139         */
00140         int CalcTransparentRun( int xmin, int xmax, int y );
00141 
00142         /*  Given the starting location, and a maximum width,
00143                 returns the number of consectutive transparent pixels.
00144         */
00145         int CalcTransparentColumn( int ymin, int ymax, int x );
00146 
00147         /*  Given the starting location, and a maximum width,
00148                 returns the number of consectutive pixels which are
00149                 not transparent.
00150         */
00151         int CalcNotTransparentRun( int xmin, int xmax, int y );
00152 
00153         /*  Given the starting location, and a maximum width,
00154                 returns the number of consectutive pixels which are
00155                 not transparent.
00156         */
00157         int CalcOpaqueRun( int xmin, int xmax, int y );
00158 
00159         /*  Given the starting location, and a maximum width,
00160                 returns the number of consectutive pixels which are
00161                 not transparent.
00162         */
00163         int CalcTranslucentRun( int xmin, int xmax, int y );
00164 
00165         /*      Finds a pixel of a given color.
00166                 x, y:   where to start looking
00167                 dx, dy: the step to travel. (1,1) would be a diagonal to the upper left
00168                 color:  the pixel color to look for
00169                 useAlpha: if true, will use the alpha channel as part of the comparison
00170                 invert: flip the logic. Find the first pixel that is NOT == color
00171 
00172                 returns: -1 if not found, or the number of steps taken if the pixel was found.
00173         */
00174         int FindPixel( int x, int y, int dx, int dy, KrRGBA color, bool useAlpha, bool invert = false );
00175 
00180         void BreakPixel( int x, int y, U8* r, U8* g, U8* b, U8* a );
00181 
00186         void BreakPixel( int x, int y, KrRGBA* rgba )   { BreakPixel( x, y, &rgba->c.red, &rgba->c.green, &rgba->c.blue, &rgba->c.alpha ); }
00187 
00188   private:
00189         SDL_Surface* surface;
00190 };
00191 
00192 
00193 typedef void (*KrPaintFunc)(    KrPaintInfo* info, 
00194                                                                 void* target, 
00195                                                                 KrRGBA* source, 
00196                                                                 int nPixel, 
00197                                                                 const KrColorTransform cform );
00198 
00199 typedef void (*KrPaintFuncRotated)( KrPaintInfo* info, 
00200                                                                     void*               target,
00201                                                                         KrRGBA* source,
00202                                                                         int sPitch,
00203                                                                         int nPixel );
00204 
00205 
00206 struct KrPaintInfo
00207 {
00208         // Initialize to paint to a surface:
00209         KrPaintInfo( SDL_Surface* screen );
00210 
00211         // Initialize to paint to a block of KrRGBA:
00212         KrPaintInfo( KrRGBA* memory, int width, int height );
00213 
00214         ~KrPaintInfo()  { if ( needToFreeSurface ) SDL_FreeSurface( surface ); }
00215 
00216         // Based on the cform and the source alpha,
00217         // get the correct Bltter. 'sourceAlpha' should be true
00218         // if there can be alpha anywhere in the source.
00219         KrPaintFunc GetBlitter( bool sourceAlpha, 
00220                                                         const KrColorTransform cform );
00221 
00222         // Like get blitter, for openGl. Sets up the texture and color of the poly.
00223         void SetOpenGLTextureMode(      bool sourceAlpha,
00224                                                                 const KrColorTransform cform,
00225                                                                 bool isScaled,
00226                                                                 KrTexture* texture );
00227 
00228         void GetBlitterName( KrPaintFunc func, std::string* name );
00229 
00230         bool OpenGL()   { return openGL; }
00231 
00232         int width;
00233         int height;
00234         int pitch;
00235         int bytesPerPixel;
00236         void* pixels;
00237         bool openGL;
00238 
00239         // Copies of the SDL stuff to avoid dereferencing in the blitters
00240         // 32 and 16 bit modes.
00241         U8  redShift;
00242         U8  greenShift;
00243         U8  blueShift;
00244         U8  alphaShift;
00245 
00246         U32     redMask;                
00247         U32     greenMask;              
00248         U32     blueMask;
00249         U32 alphaMask;          
00250         
00251         U8  redLoss;
00252         U8      greenLoss;
00253         U8  blueLoss;
00254         U8      alphaLoss;
00255         
00256         // 24 bit mode.
00257         U8      redByte;
00258         U8      greenByte;
00259         U8      blueByte;
00260 
00261         KrPaintFunc Paint_Simple_NoAlpha;
00262         KrPaintFunc Paint_Color_NoAlpha;
00263         KrPaintFunc Paint_Alpha_NoAlpha;
00264         KrPaintFunc Paint_Full_NoAlpha;
00265 
00266         KrPaintFunc Paint_Simple_Alpha;
00267         KrPaintFunc Paint_Color_Alpha;
00268         KrPaintFunc Paint_Alpha_Alpha;
00269         KrPaintFunc Paint_Full_Alpha;
00270 
00271         KrPaintFuncRotated PaintRotated_Simple_NoAlpha;
00272 
00273         SDL_Surface*    surface;
00274 
00275   private:
00276         bool needToFreeSurface;
00277         void InitCopies();
00278 };
00279 
00280 // Format:
00281 // KrPaint #Bits Target Source
00282 //
00283 // where Target can be:
00284 //              Simple: no color transform
00285 //              Color:  color transform, but alpha==255
00286 //              Alpha:  no RGB transform, but has alpha
00287 //              Full:   RGB and alpha transform
00288 //
00289 // where Source image can be:
00290 //              NoAlpha: all alpha values in source == 255
00291 //              Alpha: some alpha values are not 255
00292 //
00293 
00294 void KrPaint32_Simple_NoAlpha( KrPaintInfo* info, void* target, KrRGBA* source, int nPixel, const KrColorTransform cform );
00295 void KrPaint32B_Simple_NoAlpha( KrPaintInfo* info, void* target, KrRGBA* source, int nPixel, const KrColorTransform cform );
00296 
00297 void KrPaint32_Color_NoAlpha(  KrPaintInfo* info, void* target, KrRGBA* source, int nPixel, const KrColorTransform cform );
00298 void KrPaint32_Alpha_NoAlpha( KrPaintInfo* info, void* target, KrRGBA* source, int nPixel, const KrColorTransform cform );
00299 void KrPaint32_Full_NoAlpha( KrPaintInfo* info, void* target, KrRGBA* source, int nPixel, const KrColorTransform cform );
00300 void KrPaint32_Simple_Alpha(   KrPaintInfo* info, void* target, KrRGBA* source, int nPixel, const KrColorTransform cform );
00301 void KrPaint32_Color_Alpha( KrPaintInfo* info, void* target, KrRGBA* source, int nPixel, const KrColorTransform cform );
00302 void KrPaint32_Alpha_Alpha( KrPaintInfo* info, void* target, KrRGBA* source, int nPixel, const KrColorTransform cform );
00303 void KrPaint32_Full_Alpha( KrPaintInfo* info, void* target, KrRGBA* source, int nPixel, const KrColorTransform cform );
00304 
00305 void KrPaintRGBA_Simple_NoAlpha( KrPaintInfo* info, void* target, KrRGBA* source, int nPixel, const KrColorTransform cform );
00306 void KrPaintRGBA_Color_NoAlpha(  KrPaintInfo* info, void* target, KrRGBA* source, int nPixel, const KrColorTransform cform );
00307 void KrPaintRGBA_Alpha_NoAlpha( KrPaintInfo* info, void* target, KrRGBA* source, int nPixel, const KrColorTransform cform );
00308 void KrPaintRGBA_Full_NoAlpha( KrPaintInfo* info, void* target, KrRGBA* source, int nPixel, const KrColorTransform cform );
00309 void KrPaintRGBA_Simple_Alpha(   KrPaintInfo* info, void* target, KrRGBA* source, int nPixel, const KrColorTransform cform );
00310 void KrPaintRGBA_Color_Alpha( KrPaintInfo* info, void* target, KrRGBA* source, int nPixel, const KrColorTransform cform );
00311 void KrPaintRGBA_Alpha_Alpha( KrPaintInfo* info, void* target, KrRGBA* source, int nPixel, const KrColorTransform cform );
00312 void KrPaintRGBA_Full_Alpha( KrPaintInfo* info, void* target, KrRGBA* source, int nPixel, const KrColorTransform cform );
00313 
00314 void KrPaint24_Simple_NoAlpha( KrPaintInfo* info, void* target, KrRGBA* source, int nPixel, const KrColorTransform cform );
00315 void KrPaint24_Color_NoAlpha(  KrPaintInfo* info, void* target, KrRGBA* source, int nPixel, const KrColorTransform cform );
00316 void KrPaint24_Alpha_NoAlpha( KrPaintInfo* info, void* target, KrRGBA* source, int nPixel, const KrColorTransform cform );
00317 void KrPaint24_Full_NoAlpha( KrPaintInfo* info, void* target, KrRGBA* source, int nPixel, const KrColorTransform cform );
00318 void KrPaint24_Simple_Alpha(   KrPaintInfo* info, void* target, KrRGBA* source, int nPixel, const KrColorTransform cform );
00319 void KrPaint24_Color_Alpha( KrPaintInfo* info, void* target, KrRGBA* source, int nPixel, const KrColorTransform cform );
00320 void KrPaint24_Alpha_Alpha( KrPaintInfo* info, void* target, KrRGBA* source, int nPixel, const KrColorTransform cform );
00321 void KrPaint24_Full_Alpha( KrPaintInfo* info, void* target, KrRGBA* source, int nPixel, const KrColorTransform cform );
00322 
00323 void KrPaint16_Simple_NoAlpha( KrPaintInfo* info, void* target, KrRGBA* source, int nPixel, const KrColorTransform cform );
00324 void KrPaint16_Color_NoAlpha(  KrPaintInfo* info, void* target, KrRGBA* source, int nPixel, const KrColorTransform cform );
00325 void KrPaint16_Alpha_NoAlpha( KrPaintInfo* info, void* target, KrRGBA* source, int nPixel, const KrColorTransform cform );
00326 void KrPaint16_Full_NoAlpha( KrPaintInfo* info, void* target, KrRGBA* source, int nPixel, const KrColorTransform cform );
00327 void KrPaint16_Simple_Alpha(   KrPaintInfo* info, void* target, KrRGBA* source, int nPixel, const KrColorTransform cform );
00328 void KrPaint16_Color_Alpha( KrPaintInfo* info, void* target, KrRGBA* source, int nPixel, const KrColorTransform cform );
00329 void KrPaint16_Alpha_Alpha( KrPaintInfo* info, void* target, KrRGBA* source, int nPixel, const KrColorTransform cform );
00330 void KrPaint16_Full_Alpha( KrPaintInfo* info, void* target, KrRGBA* source, int nPixel, const KrColorTransform cform );
00331 
00332 void KrPaintRGBARotated_Simple_NoAlpha( KrPaintInfo* info, 
00333                                                                                 void*           target,
00334                                                                                 KrRGBA* source,
00335                                                                                 int sPitch,
00336                                                                                 int nPixel );
00337 void KrPaint32Rotated_Simple_NoAlpha( KrPaintInfo* info, 
00338                                                                           void*         target,
00339                                                                           KrRGBA*       source,
00340                                                                           int sPitch,
00341                                                                           int nPixel );
00342 void KrPaint24Rotated_Simple_NoAlpha( KrPaintInfo* info, 
00343                                                                           void*         target,
00344                                                                           KrRGBA*       source,
00345                                                                           int sPitch,
00346                                                                           int nPixel );
00347 void KrPaint16Rotated_Simple_NoAlpha( KrPaintInfo* info, 
00348                                                                           void*         target,
00349                                                                           KrRGBA*       source,
00350                                                                           int sPitch,
00351                                                                           int nPixel );
00352 
00353 #endif
00354 

Generated on Mon Sep 15 12:01:11 2003 for Kyra by doxygen1.2.11.1 written by Dimitri van Heesch, © 1997-2001