00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
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
00134
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
00166
00167
00168
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
00187
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 };
00195
00196 #endif // ifndef DRAW_H_