Hosting courtesy of Sourceforge

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

draw.h

Go to the documentation of this file.
00001 //
00002 //      Copyright (C) 2002 Robert Renaud
00003 //
00004 //      This program is free software; you can redistribute it and/or
00005 //      modify it under the terms of the GNU General Public License
00006 //      as published by the Free Software Foundation; either version 2
00007 //      of the License, or (at your option) any later version.
00008 //
00009 //      This program is distributed in the hope that it will be useful,
00010 //      but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 //      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
00012 //
00013 //      See the GNU General Public License for more details.
00014 //
00015 //      You should have received a copy of the GNU General Public License
00016 //      along with this program; if not, write to the Free Software
00017 //      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00018 //
00019 
00020 #ifndef DRAW_H_
00021 #define DRAW_H_
00022 
00023 #include "../Config.h"
00024 #include "GraphicsDebug.h"
00025 #include "ImageManager.h"
00026 #include "../Parse/Parse.h"
00027 #include "../Util/GeneralException.h"
00028 
00029 #include <string>
00030 #include <vector>
00031 
00032 #include "SDL.h"
00033 
00034 using namespace std;
00035 namespace Graphics {
00036 
00040         class Drawable {
00041         public:
00043                 virtual void draw(SDL_Surface* screen)=0;
00044                 virtual ~Drawable() { }
00045         };
00046 
00050         class DrawableAt {
00051         public:
00057                 virtual void drawAt(SDL_Surface* screen, SDL_Rect* loc)=0;
00058                 virtual ~DrawableAt() { }
00059         };
00060 
00064         class AbstractImage : public DrawableAt {
00065         public:
00066                 virtual void drawAt(SDL_Surface* screen, SDL_Rect* loc)=0;
00067                 virtual void readFromFile(const string& filename)=0;
00068                 virtual void setTransparency(Uint32 SDL_Flags)=0;
00069                 virtual ~AbstractImage() { }
00070                 virtual AbstractImage* dynCopyImage()=0;
00071         };
00072         
00074         class SingleFrameImage: public AbstractImage {
00075         public:
00076                 SingleFrameImage();
00077                 SingleFrameImage(const string& BMP_filename, Uint32 SDL_Flags=0);
00078                 virtual void readFromFile(const string& BMP_filename);
00079                 virtual void drawAt(SDL_Surface* screen, SDL_Rect* loc);
00080                 virtual void setTransparency(Uint32 SDL_Flags);
00081                 virtual AbstractImage* dynCopyImage();
00082         protected:
00083                 SDL_Surface* image;
00084         };
00085         
00094         class AnimatedImage: public AbstractImage {
00095         public:
00096                 AnimatedImage();
00097                 AnimatedImage(const string& ANI_filename, Uint32 transparencyFlags=0);
00098                 virtual void readFromFile(const string& ANI_filename);
00099                 virtual void setTransparency(Uint32 SDL_Flags);
00100                 virtual void drawAt(SDL_Surface* screen, SDL_Rect* loc);
00101                 virtual AbstractImage* dynCopyImage();
00102         protected:
00103                 size_t nextFrameIndex;
00104                 size_t numFrames;
00105                 size_t maxUpdates;
00106                 size_t curUpdates;
00107                 vector<SDL_Surface*> frameVec;
00108         };
00109 
00111         class ImageFrame: public DrawableAt {
00112         public: 
00113                 
00117                 ImageFrame(DrawableAt* imageToFrame, Uint32 pix = 0x3255123, Uint8 borderWidth =3);     
00118                 ~ImageFrame();
00121                 virtual void drawAt(SDL_Surface* screen, SDL_Rect* loc);
00122         private:
00123                 DrawableAt* framedImage;
00124                 Uint32 borderColor;
00125                 Uint8 borderWidth;
00126         };
00127 
00133         /*      Thought about ways to get rid of this class, in favor of StdRead, but couldn't get around
00134         dynamic allocation problem*/
00135         class ReadImage: public Parse::ParseAction {
00136         public:
00141                 ReadImage(AbstractImage*& imgPointer);
00142 
00144                 virtual void getValue(std::istream &input);
00145         protected:
00146                 AbstractImage*& imgPointerRef;
00147         };
00148         
00162         AbstractImage* dynGenerateImage(const string& filename);
00163         
00164         /*
00165          * The following pixel-manipulation functions are by Sam Lantinga,
00166          * from the documentation distributed with SDL v1.2.3.
00167          * ...Just putting them in here for easy access.
00168          *                              --Chris Peterson
00169          */
00170 
00171 
00176         Uint32 getpixel(SDL_Surface *surface, int x, int y);
00177 
00184         void putpixel(SDL_Surface *surface, int x, int y, Uint32 pixel);
00185 
00186     /*  Makes the top left pixel on a surface into its transparency key.
00187         Returns the pixel that was used as the colorkey.*/
00188         Uint32 makeTopLeftPixelTrans( SDL_Surface* lpSurface );
00189         
00190         Uint8 calcRedComp(SDL_PixelFormat* format,Uint32 pixel);
00191         Uint8 calcGreenComp(SDL_PixelFormat* format, Uint32 pixel);
00192         Uint8 calcBlueComp(SDL_PixelFormat* format, Uint32 pixel);
00193         
00194 }; // namespace Graphics
00195 
00196 #endif // ifndef DRAW_H_

Generated on Tue May 21 07:26:51 2002 for BomberLAN by doxygen1.2.12 written by Dimitri van Heesch, © 1997-2001