00001
00002
00003
00004
00005
00006
00007
00008
00009
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #ifndef __VIDEO_H__
00029 #define __VIDEO_H__
00030
00032
00033 #include "SDL.h"
00034 #include "SDL_opengl.h"
00035 #include "guichan/image.h"
00036
00037 class CFont;
00038
00039 extern bool UseOpenGL;
00040
00041
00042 class CGraphic : public gcn::Image {
00043 protected:
00044 CGraphic() : Surface(NULL), SurfaceFlip(NULL),
00045 Width(0), Height(0), NumFrames(1), GraphicWidth(0), GraphicHeight(0),
00046 Refs(1), Resized(false),
00047 TextureWidth(0.f), TextureHeight(0.f), Textures(NULL), NumTextures(0)
00048 {
00049 }
00050 ~CGraphic() {}
00051
00052 public:
00053
00054 void DrawClip(int x, int y) const;
00055 void DrawSub(int gx, int gy, int w, int h, int x, int y) const;
00056 void DrawSubClip(int gx, int gy, int w, int h, int x, int y) const;
00057 void DrawSubTrans(int gx, int gy, int w, int h, int x, int y,
00058 unsigned char alpha) const;
00059 void DrawSubClipTrans(int gx, int gy, int w, int h, int x, int y,
00060 unsigned char alpha) const;
00061
00062
00063 void DrawFrame(unsigned frame, int x, int y) const;
00064 void DoDrawFrameClip(GLuint *textures, unsigned frame, int x, int y) const;
00065 void DrawFrameClip(unsigned frame, int x, int y) const;
00066 void DrawFrameTrans(unsigned frame, int x, int y, int alpha) const;
00067 void DrawFrameClipTrans(unsigned frame, int x, int y, int alpha) const;
00068
00069
00070 void DrawFrameX(unsigned frame, int x, int y) const;
00071 void DoDrawFrameClipX(GLuint *textures, unsigned frame, int x, int y) const;
00072 void DrawFrameClipX(unsigned frame, int x, int y) const;
00073 void DrawFrameTransX(unsigned frame, int x, int y, int alpha) const;
00074 void DrawFrameClipTransX(unsigned frame, int x, int y, int alpha) const;
00075
00076
00077 static CGraphic *New(const std::string &file, int w = 0, int h = 0);
00078 static CGraphic *ForceNew(const std::string &file, int w = 0, int h = 0);
00079
00080 CGraphic *Clone() const;
00081
00082 static void Free(CGraphic *g);
00083
00084 void Load();
00085 void Flip();
00086 void UseDisplayFormat();
00087 void Resize(int w, int h);
00088 bool TransparentPixel(int x, int y);
00089 void MakeShadow();
00090
00091 inline bool IsLoaded() const { return Surface != NULL; }
00092
00093
00094 virtual void *_getData() const { return Surface; }
00095 virtual int getWidth() const { return Width; }
00096 virtual int getHeight() const { return Height; }
00097
00098 std::string File;
00099 std::string HashFile;
00100 SDL_Surface *Surface;
00101 SDL_Surface *SurfaceFlip;
00102 int Width;
00103 int Height;
00104 int NumFrames;
00105 int GraphicWidth;
00106 int GraphicHeight;
00107 int Refs;
00108 bool Resized;
00109 GLfloat TextureWidth;
00110 GLfloat TextureHeight;
00111 GLuint *Textures;
00112 int NumTextures;
00113
00114 friend void MakeFontColorTextures(CFont *font);
00115 friend void CleanFonts(void);
00116 friend void ReloadFonts(void);
00117 };
00118
00119 class CPlayerColorGraphic : public CGraphic
00120 {
00121 protected:
00122 CPlayerColorGraphic() {
00123 memset(PlayerColorTextures, 0, sizeof(PlayerColorTextures));
00124 }
00125
00126 public:
00127 void DrawPlayerColorFrameClipX(int player, unsigned frame, int x, int y);
00128 void DrawPlayerColorFrameClip(int player, unsigned frame, int x, int y);
00129
00130 static CPlayerColorGraphic *New(const std::string &file, int w = 0, int h = 0);
00131 static CPlayerColorGraphic *ForceNew(const std::string &file, int w = 0, int h = 0);
00132
00133 GLuint *PlayerColorTextures[PlayerMax];
00134 };
00135
00137 class CColor {
00138 public:
00139 CColor(unsigned char r = 0, unsigned char g = 0, unsigned char b = 0,
00140 unsigned char a = 0) : R(r), G(g), B(b), A(a) {}
00141
00143 operator SDL_Color() const {
00144 SDL_Color c = { R, G, B, A };
00145 return c;
00146 };
00147
00148 unsigned char R;
00149 unsigned char G;
00150 unsigned char B;
00151 unsigned char A;
00152 };
00153
00154 class CUnitColors {
00155 public:
00156 CUnitColors() : Colors(NULL) {}
00157
00158 SDL_Color *Colors;
00159 };
00160
00167 typedef struct _event_callback_ {
00168
00170 void (*ButtonPressed)(unsigned buttons);
00172 void (*ButtonReleased)(unsigned buttons);
00174 void (*MouseMoved)(int x, int y);
00176 void (*MouseExit)(void);
00177
00179 void (*KeyPressed)(unsigned keycode, unsigned keychar);
00181 void (*KeyReleased)(unsigned keycode, unsigned keychar);
00183 void (*KeyRepeated)(unsigned keycode, unsigned keychar);
00184
00186 void (*NetworkEvent)(void);
00187
00188 } EventCallback;
00189
00190 #if SDL_BYTEORDER == SDL_LIL_ENDIAN
00191 #define RSHIFT 0
00192 #define GSHIFT 8
00193 #define BSHIFT 16
00194 #define ASHIFT 24
00195 #define RMASK 0x000000ff
00196 #define GMASK 0x0000ff00
00197 #define BMASK 0x00ff0000
00198 #define AMASK 0xff000000
00199 #else
00200 #define RSHIFT 24
00201 #define GSHIFT 16
00202 #define BSHIFT 8
00203 #define ASHIFT 0
00204 #define RMASK 0xff000000
00205 #define GMASK 0x00ff0000
00206 #define BMASK 0x0000ff00
00207 #define AMASK 0x000000ff
00208 #endif
00209
00210
00211 class CVideo
00212 {
00213 public:
00214 CVideo() : Width(0), Height(0), Depth(0), FullScreen(false) {}
00215
00216 void LockScreen();
00217 void UnlockScreen();
00218
00219 void ClearScreen();
00220 bool ResizeScreen(int x, int y);
00221
00222 void DrawPixelClip(Uint32 color, int x, int y);
00223 void DrawTransPixelClip(Uint32 color, int x, int y, unsigned char alpha);
00224
00225 void DrawVLine(Uint32 color, int x, int y, int height);
00226 void DrawTransVLine(Uint32 color, int x, int y, int height, unsigned char alpha);
00227 void DrawVLineClip(Uint32 color, int x, int y, int height);
00228 void DrawTransVLineClip(Uint32 color, int x, int y, int height, unsigned char alpha);
00229
00230 void DrawHLine(Uint32 color, int x, int y, int width);
00231 void DrawTransHLine(Uint32 color, int x, int y, int width, unsigned char alpha);
00232 void DrawHLineClip(Uint32 color, int x, int y, int width);
00233 void DrawTransHLineClip(Uint32 color, int x, int y, int width, unsigned char alpha);
00234
00235 void DrawLine(Uint32 color, int sx, int sy, int dx, int dy);
00236 void DrawTransLine(Uint32 color, int sx, int sy, int dx, int dy, unsigned char alpha);
00237 void DrawLineClip(Uint32 color, int sx, int sy, int dx, int dy);
00238 void DrawTransLineClip(Uint32 color, int sx, int sy, int dx, int dy, unsigned char alpha);
00239
00240 void DrawRectangle(Uint32 color, int x, int y, int w, int h);
00241 void DrawTransRectangle(Uint32 color, int x, int y, int w, int h, unsigned char alpha);
00242 void DrawRectangleClip(Uint32 color, int x, int y, int w, int h);
00243 void DrawTransRectangleClip(Uint32 color, int x, int y, int w, int h, unsigned char alpha);
00244
00245 void FillRectangle(Uint32 color, int x, int y, int w, int h);
00246 void FillTransRectangle(Uint32 color, int x, int y, int w, int h, unsigned char alpha);
00247 void FillRectangleClip(Uint32 color, int x, int y, int w, int h);
00248 void FillTransRectangleClip(Uint32 color, int x, int y, int w, int h, unsigned char alpha);
00249
00250 void DrawCircle(Uint32 color, int x, int y, int r);
00251 void DrawTransCircle(Uint32 color, int x, int y, int r, unsigned char alpha);
00252 void DrawCircleClip(Uint32 color, int x, int y, int r);
00253 void DrawTransCircleClip(Uint32 color, int x, int y, int r, unsigned char alpha);
00254
00255 void FillCircle(Uint32 color, int x, int y, int radius);
00256 void FillTransCircle(Uint32 color, int x, int y, int radius, unsigned char alpha);
00257 void FillCircleClip(Uint32 color, int x, int y, int radius);
00258 void FillTransCircleClip(Uint32 color, int x, int y, int radius, unsigned char alpha);
00259
00260 inline Uint32 MapRGB(SDL_PixelFormat *f, Uint8 r, Uint8 g, Uint8 b) {
00261 if (!UseOpenGL) {
00262 return SDL_MapRGB(f, r, g, b);
00263 } else {
00264 return MapRGBA(f, r, g, b, 0xFF);
00265 }
00266 }
00267 inline Uint32 MapRGBA(SDL_PixelFormat *f, Uint8 r, Uint8 g, Uint8 b, Uint8 a) {
00268 if (!UseOpenGL) {
00269 return SDL_MapRGBA(f, r, g, b, a);
00270 } else {
00271 return ((r << RSHIFT) | (g << GSHIFT) | (b << BSHIFT) | (a << ASHIFT));
00272 }
00273 }
00274 inline void GetRGB(Uint32 c, SDL_PixelFormat *f, Uint8 *r, Uint8 *g, Uint8 *b) {
00275 if (!UseOpenGL) {
00276 SDL_GetRGB(c, f, r, g, b);
00277 } else {
00278 *r = (c >> RSHIFT) & 0xff;
00279 *g = (c >> GSHIFT) & 0xff;
00280 *b = (c >> BSHIFT) & 0xff;
00281 }
00282 }
00283 inline void GetRGBA(Uint32 c, SDL_PixelFormat *f, Uint8 *r, Uint8 *g, Uint8 *b, Uint8 *a) {
00284 if (!UseOpenGL) {
00285 SDL_GetRGBA(c, f, r, g, b, a);
00286 } else {
00287 *r = (c >> RSHIFT) & 0xff;
00288 *g = (c >> GSHIFT) & 0xff;
00289 *b = (c >> BSHIFT) & 0xff;
00290 *a = (c >> ASHIFT) & 0xff;
00291 }
00292 }
00293
00294 int Width;
00295 int Height;
00296 int Depth;
00297 bool FullScreen;
00298 };
00299
00300 extern CVideo Video;
00301
00309 extern int VideoSyncSpeed;
00310
00311 extern int SkipFrames;
00312
00314 extern char VideoForceFullScreen;
00315
00317 extern unsigned long NextFrameTicks;
00318
00320 extern unsigned long FrameCounter;
00321
00323 extern int SlowFrameCounter;
00324
00327 extern void SetPlayersPalette(void);
00328
00330 extern SDL_Surface *TheScreen;
00331
00333 extern GLint GLMaxTextureSize;
00335 extern bool GLTextureCompressionSupported;
00337 extern bool UseGLTextureCompression;
00338
00340 extern void InitVideo(void);
00341
00343 extern int VideoValidResolution(int w, int h);
00344
00346 extern int LoadGraphicPNG(CGraphic *g);
00347
00349 extern void MakeTexture(CGraphic *graphic);
00351 extern void MakePlayerColorTexture(CPlayerColorGraphic *graphic, int player);
00352
00354 extern void FreeOpenGLGraphics();
00356 extern void ReloadGraphics();
00358 extern void ReloadOpenGL();
00359
00361 extern void SetVideoSync(void);
00362
00364 extern void InitLineDraw(void);
00365
00367 extern void Invalidate(void);
00368
00371 extern void InvalidateArea(int x, int y, int w, int h);
00372
00375 extern void SetClipping(int left, int top, int right, int bottom);
00376
00378 extern void RealizeVideoMemory(void);
00379
00381 extern void SaveScreenshotPNG(const std::string &name);
00382
00384 extern void SetCallbacks(const EventCallback *callbacks);
00386 extern const EventCallback *GetCallbacks();
00387
00389 extern void WaitEventsOneFrame();
00390
00392 extern void ToggleFullScreen(void);
00393
00395 extern void PushClipping(void);
00396
00398 extern void PopClipping(void);
00399
00401 extern unsigned long GetTicks(void);
00402
00404 extern const char *SdlKey2Str(int key);
00405
00407 extern bool SdlGetGrabMouse(void);
00409 extern void ToggleGrabMouse(int mode);
00410
00411 extern EventCallback GameCallbacks;
00412 extern EventCallback EditorCallbacks;
00413
00414 extern Uint32 ColorBlack;
00415 extern Uint32 ColorDarkGreen;
00416 extern Uint32 ColorBlue;
00417 extern Uint32 ColorOrange;
00418 extern Uint32 ColorWhite;
00419 extern Uint32 ColorGray;
00420 extern Uint32 ColorRed;
00421 extern Uint32 ColorGreen;
00422 extern Uint32 ColorYellow;
00423
00424 void DrawTexture(const CGraphic *g, GLuint *textures, int sx, int sy,
00425 int ex, int ey, int x, int y, int flip);
00426
00427 #ifdef DEBUG
00428 extern void FreeGraphics();
00429 #endif
00430
00431
00432 extern PFNGLCOMPRESSEDTEXIMAGE3DARBPROC glCompressedTexImage3DARB;
00433 extern PFNGLCOMPRESSEDTEXIMAGE2DARBPROC glCompressedTexImage2DARB;
00434 extern PFNGLCOMPRESSEDTEXIMAGE1DARBPROC glCompressedTexImage1DARB;
00435 extern PFNGLCOMPRESSEDTEXSUBIMAGE3DARBPROC glCompressedTexSubImage3DARB;
00436 extern PFNGLCOMPRESSEDTEXSUBIMAGE2DARBPROC glCompressedTexSubImage2DARB;
00437 extern PFNGLCOMPRESSEDTEXSUBIMAGE1DARBPROC glCompressedTexSubImage1DARB;
00438 extern PFNGLGETCOMPRESSEDTEXIMAGEARBPROC glGetCompressedTexImageARB;
00439
00441
00442 #endif // !__VIDEO_H__