00001 #ifndef CSPicture_h
00002 #define CSPicture_h
00003
00004
00005
00006
00007 #include <string>
00008 #include <vector>
00009 #include "SDLMain.h"
00010 #include "CSLoadable.h"
00011 #include "CSLog.h"
00012
00013 #ifdef WIN32
00014 #pragma warning(disable : 4786 )
00015 #endif
00016
00017 class CSBitmap;
00018 class CSPicture;
00019 class CSPictureLoader;
00020 class CSPictureDirectLoader;
00021
00022 typedef std::vector<CSPicture *> CSPictures;
00023
00024
00025
00026
00027
00028
00029 class CSDisplayParams
00030 {
00031 public:
00032 int mXDisplayStart;
00033 int mYDisplayStart;
00034 int mXWorldStart;
00035 int mYWorldStart;
00036 int mXPos;
00037 int mYPos;
00038 };
00039
00040 const int RLE_YES = 1;
00041 const int RLE_NO = 0;
00042 const int RLE_PERHAPS = 2;
00043
00044
00045
00046
00047
00048
00049
00050 class CSPictureData
00051 {
00052
00053 public:
00054 SDL_Rect position;
00055 char *id;
00056 char *filename;
00057 int rleUse;
00058 int alpha;
00059
00060 CSPictureData()
00061 {
00062 rleUse = RLE_PERHAPS;
00063 id = 0;
00064 filename = 0;
00065 position.x=0;
00066 position.y=0;
00067 position.w=0;
00068 position.h=0;
00069 alpha = -1;
00070 }
00071
00072 ~CSPictureData()
00073 {
00074 if (id != 0)
00075 {
00076 free(id);
00077 id = 0;
00078 }
00079 if (filename != 0)
00080 {
00081 free(filename);
00082 filename = 0;
00083 }
00084 }
00085 };
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143 class CSPicture
00144 {
00145 friend CSPictureLoader;
00146 friend CSPictureDirectLoader;
00147 private:
00148 static CSPictures mAllPictures;
00149 static void addPicture(CSPicture *picture);
00150 static void removePicture(CSPicture *picture);
00151
00152 bool mIsDirectLoad;
00153 std::string mLoadName;
00154 int mRLEUse;
00155
00156 int mAlpha;
00157
00158
00159 SDL_Rect mUpdateRegion;
00160
00161
00162
00163 SDL_Rect mPixelPictureRegion;
00164
00165
00166
00167
00168
00169
00170
00171 SDL_Rect mPictureRegion;
00172
00173
00174
00175 unsigned int mStartPixelsX;
00176
00177
00178
00179 unsigned int mStartPixelsY;
00180
00181
00182
00183
00184 SDL_Surface *mPicture;
00185 bool mIsSolid;
00186 char *mId;
00187 char *mFileName;
00188 int mColorKey;
00189 int mR;
00190 int mG;
00191 int mB;
00192 double mFactor;
00193 int mScaledWidth;
00194 int mScaledHeight;
00195 bool mIsCreatedAsScaled;
00196 SDL_Surface *mScaledPicture;
00197
00198 unsigned char **mProjection;
00199
00200 unsigned int mPixelProjectionCount;
00201
00202 int mRLEAccelleration;
00203
00204
00205
00206 CSPicture(const std::string &filename, bool isDirectLoad = false);
00207 virtual void initialize(const CSPictureData &data, bool isDirectLoad = false);
00208 static void loadPictureData(const std::string &filename, CSPictureData &data);
00209
00210 void resetSurface();
00211
00212 SDL_Surface *convertToCurrentScreen(CSBitmap *image, SDL_Rect rect);
00213 void checkRLEAccelleration();
00214 void buildPixelProjection(CSBitmap *image, const SDL_Rect &position);
00215 void buildOptimizeData();
00216
00217 public:
00218
00219 CSPicture(const CSPicture &picture);
00220
00221
00222 virtual ~CSPicture();
00223
00224 static const char *CLASS;
00225 virtual std::string getType() {return (std::string) CLASS;}
00226
00227 void getRGB(int &r, int &b, int &g);
00228 virtual void display(CSDisplayParams *mDisplayParams);
00229 virtual void display(int x, int y);
00230 virtual void display(SDL_Surface *destination, int x, int y);
00231 unsigned int getMaxX(){return mPictureRegion.w;}
00232 unsigned int getMaxY(){return mPictureRegion.h;}
00233 unsigned int getWidth(){return mPictureRegion.w;}
00234 unsigned int getHeight(){return mPictureRegion.h;}
00235 void setSolid(bool b);
00236 bool isSolid() {return mIsSolid;}
00237 void setAlpha(int alpha);
00238 int getColorKey() {return mColorKey;}
00239 SDL_Surface *getSurface() {return mPicture;}
00240 unsigned char **getProjection() {return mProjection;}
00241 unsigned int getPixelProjectionCount()
00242 {return mPixelProjectionCount;}
00243
00244 static void resetSurfaces();
00245
00246 void scale(int width, int divideX, int height, int divideY);
00247 SDL_Surface *getScaledPicture(double factor);
00248 SDL_Surface *getScaledPicture(int w, int h);
00249 bool isTransparent(int x, int y);
00250 static CSPicture* createScaledPicture(CSPicture* picture, double factor);
00251 };
00252
00253
00254
00255
00256
00257
00258 class CSPictureLoader : public Loadable<CSPicture>
00259 {
00260 protected:
00261 virtual CSPicture *create(const std::string &filename)
00262 {
00263 return new CSPicture(filename, false);
00264 }
00265
00266 public:
00267 static CSPictureLoader INSTANCE;
00268 void scale(char *name, int width, int divideX, int height, int divideY);
00269 };
00270
00271
00272
00273
00274
00275
00276 class CSPictureDirectLoader : public Loadable<CSPicture>
00277 {
00278 protected:
00279 virtual CSPicture *create(const std::string &filename)
00280 {
00281 return new CSPicture(filename, true);
00282 }
00283
00284 public:
00285 static CSPictureDirectLoader INSTANCE;
00286 void scale(const char *name, int width, int divideX, int height, int divideY);
00287 };
00288 #endif // CSPicture_h