00001 #ifndef SDLMain_h
00002 #define SDLMain_h
00003
00004 #include <SDL.h>
00005 #include "CSLog.h"
00006 #include "SDL_mixer.h"
00007 #include "smpeg.h"
00008 #include <string>
00009
00010 #include "CSMessageDispatchable.h"
00011 #include "CSMessage.h"
00012
00013 #define COLOR(src, c) SDL_MapRGB(((src)->format),(((c)&0xff0000)>>16),(((c)&0xff00)>>8),(((c)&0xff)))
00014 const int NUM_UPDATE_RECTS = 500;
00015
00016 int convert(const char *start_string, int radix);
00017 int _putPixelAlpha(SDL_Surface * surface, Sint16 x, Sint16 y, Uint32 color, Uint8 alpha);
00018
00019 class SDLMain : public CSMessageDispatchable
00020 {
00021 private:
00022 SDLMessage MESSAGE_SCREEN_CHANGED;
00023 static SDLMain *mInstance;
00024 static SDL_Surface *mScreen;
00025 static SDL_Rect *mRects;
00026 static int mCurrentCount;
00027 static int mNoPages;
00028 static int mPage;
00029 static int mWidth;
00030 static int mHeight;
00031 static int mDepth;
00032 static unsigned int mMode;
00033 static bool mSDLInit;
00034
00035 static bool mIsHardware;
00036 static bool mIsDoublebuffer;
00037 static bool mIsFullscreen;
00038 static bool mIsAnyFormat;
00039 static bool mUpdateWholeScreen;
00040
00041 static unsigned int mAudioFormat;
00042 static unsigned int mAudioChannels;
00043 static unsigned int mAudioBuffers;
00044 static unsigned int mAudioRate;
00045 SDLMain();
00046
00047 public:
00048 ~SDLMain();
00049 static SDLMain *getInstance();
00050
00051 static const char *CLASS;
00052 virtual std::string getType() {return (std::string) CLASS;}
00053
00054 static inline SDL_Surface *getScreen(){return mScreen;};
00055 static void shutdown();
00056 static void shutdown(std::string, unsigned int errorNo);
00057 static void clearScreen( int red, int green, int blue );
00058
00059 static void addUpdateRect(const SDL_Rect &saveRegion);
00060 static void addUpdateRect(signed short x, signed short y, unsigned short w, unsigned short h);
00061 static int getPageNo();
00062 static int getCurrentPage();
00063 static void updateScreen();
00064 static unsigned int getMode();
00065 static int getScreenWidth() {return mWidth;}
00066 static int getScreenHeight() {return mHeight;}
00067 static int getScreenDepth() {return mDepth;}
00068 static void setScreenWidth(int w);
00069 static void setScreenHeight(int h);
00070 static void setScreenDepth(int d);
00071
00072 static bool isHardwareSurface() {return mIsHardware;}
00073 static bool isDoubleBufferSurface() {return mIsDoublebuffer;}
00074 static bool isFullscreenSurface() {return mIsFullscreen;}
00075 static bool isUseScreenAnyhowSurface() {return mIsAnyFormat;}
00076 static bool isInitialized() {return mSDLInit;}
00077
00078 static void setHardwareSurface(bool h);
00079 static void setDoubleBufferSurface(bool d);
00080 static void setFullscreenSurface(bool f);
00081 static void setUseScreenAnyhowSurface(bool a);
00082 static void toggleFullscreen();
00083 static void resetVideo();
00084 static Uint32 getPixel(SDL_Surface *Surface, Sint32 X, Sint32 Y);
00085 static void setPixel(SDL_Surface *surface, Sint32 X, Sint32 Y, Uint32 color);
00086 static void setUpdateWholeScreen(bool b) {mUpdateWholeScreen = b;}
00087
00088 static SDL_Surface *scale(SDL_Surface *surface, int width, int height);
00089 static SDL_Surface *scale(SDL_Surface *surface, int width, int divideX, int height, int divideY);
00090 static SDL_Surface *scale(SDL_Surface *surface, double factor);
00091 static int scaleX(int width, int divideX, int x);
00092 static int scaleY(int height, int divideY, int y);
00093 static int line(SDL_Surface * dst, Sint16 x1, Sint16 y1, Sint16 x2, Sint16 y2, Uint32 color);
00094 static void freeSurface(SDL_Surface *surface);
00095 static void adjustClipping(SDL_Rect &newRect, SDL_Rect &oldRect);
00096
00097
00098 static void DrawPixel(SDL_Surface *surface, Sint32 x, Sint32 y, Uint32 color)
00099 {
00100 if ((x < 0) || (x > surface->w) || (y<0) || (y>surface->h)) return;
00101 setPixel(surface, x, y, color);
00102 }
00103 static void DrawRoundRectNorth(SDL_Surface * screen, int x0, int y0, int w, int h, Uint32 color, int corner, int thickness=1)
00104 {
00105 DrawRoundRect(screen, x0, y0, w, h, color, corner, thickness, true,false,false,false);
00106 }
00107 static void DrawRoundRectSouth(SDL_Surface * screen, int x0, int y0, int w, int h, Uint32 color, int corner, int thickness=1)
00108 {
00109 DrawRoundRect(screen, x0, y0, w, h, color, corner, thickness, false,true,false,false);
00110 }
00111 static void DrawRoundRectEast(SDL_Surface * screen, int x0, int y0, int w, int h, Uint32 color, int corner, int thickness=1)
00112 {
00113 DrawRoundRect(screen, x0, y0, w, h, color, corner, thickness, false,false,true,false);
00114 }
00115 static void DrawRoundRectWest(SDL_Surface * screen, int x0, int y0, int w, int h, Uint32 color, int corner, int thickness=1)
00116 {
00117 DrawRoundRect(screen, x0, y0, w, h, color, corner, thickness, false,false,false,true);
00118 }
00119 static void DrawRoundRect(SDL_Surface * screen, SDL_Rect *rect, Uint32 color, int corner = 3, int thickness=1);
00120 static void DrawRoundRect(SDL_Surface * screen, int x0, int y0, int w, int h, Uint32 color, int corner, int thickness=1, bool north = true, bool south = true, bool east = true, bool west = true);
00121 static void DrawRoundRectFill(SDL_Surface * screen, int x0, int y0, int w, int h, Uint32 color, int corner=5);
00122 static void vertgradient(SDL_Surface * surf, SDL_Rect & gradRect, int c1, int c2, Uint8 alpha);
00123 static void horizgradient(SDL_Surface * surf, SDL_Rect & gradRect, int c1, int c2, Uint8 alpha);
00124
00125 };
00126
00127 #endif // SDLMain_h