9 #include <SDL/SDL_opengl.h>
11 typedef SDL_Surface Screen;
12 typedef SDL_Rect Rectangle;
13 typedef short unsigned int SUint;
14 typedef unsigned char Uint8;
37 Colour(float red=0, float green=0, float blue=0, float alpha=0) : r(red), g(green), b(blue), a(alpha) {}
38 Colour(const Colour & cpy) : r(cpy.r), g(cpy.g), b(cpy.b), a(cpy.a) {}
40 Colour & operator=(const Colour & s) {r = s.r; g = s.g; b = s.b; a = s.a; return *this;}
41 bool operator==(const Colour & s) const {return (r == s.r && g == s.g && b == s.b && a == s.a);}
42 bool operator!=(const Colour & s) const {return !operator==(s);}
49 static int ScreenWidth() {return screenWidth;}
50 static int ScreenHeight() {return screenHeight;}
52 static void Initialise(const char * caption, int width=640, int height=480);
53 static void Destroy();
55 static SDL_Surface * LoadTextureBMP(const char * file);
56 static void SaveTextureBMP(SDL_Surface * tex, const char * file);
58 static void ClearScreen();
59 static void UpdateScreen();
60 static void DrawGrid(int gridWidth, int gridHeight, Colour colour);
61 static Uint8 MakeColour(int R, int G, int B, int Alpha = 0);
62 static Colour ConvertColour(Uint8 colour);
64 static void DrawTexture(SDL_Surface * src, int destX, int destY, int srcX=0, int srcY=0, int width=-1, int height=-1);
65 static void DrawTexture(SDL_Surface * src, int destX, int destY, double rotate, double scale);
66 static void DrawPixel(int x, int y, Colour colour);
68 static Colour GetPixel(int x, int y);
69 static void DrawLine(int x1, int y1, int x2, int y2, Colour colour, double scale=1.0);
70 static void DrawLineDashed(int x1, int y1, int x2, int y2, Colour colour, double scale=1.0);
71 static void DrawRectangle(int x1, int y1, int x2, int y2, Colour colour, double scale=1.0);
73 static void GetColourData(SDL_Surface * src, std::vector<SUint> * R, std::vector<SUint> * G, std::vector<SUint> * B, std::vector<SUint> * A = NULL);
74 static void GetColourData(SDL_Surface * src, std::vector<std::vector<SUint> > * R, std::vector<std::vector<SUint> > * G, std::vector<std::vector<SUint> > * B, std::vector<std::vector<SUint> > * A = NULL);
76 static void DrawColourData(int destX, int destY, std::vector<SUint> * R, std::vector<SUint> * G, std::vector<SUint> * B, std::vector<SUint> * A = NULL) {DrawColourData(screen, destX, destY, R, G, B, A);}
78 static void DrawColourData(int destX, int destY, std::vector<std::vector<SUint> > * R, std::vector<std::vector<SUint> > * G, std::vector<std::vector<SUint> > * B, std::vector<std::vector<SUint> > * A = NULL) {DrawColourData(screen, destX, destY, R, G, B, A);}
80 static SDL_Surface * TextureFromColours(std::vector<SUint> * R, std::vector<SUint> * G, std::vector<SUint> * B, std::vector<SUint> * A = NULL);
81 static SDL_Surface * TextureFromColours(std::vector<std::vector<SUint> > * R, std::vector<std::vector<SUint> > * G, std::vector<std::vector<SUint> > * B, std::vector<std::vector<SUint> > * A = NULL);
83 static void Wait(int n);
90 virtual ~TextureManager() {}
92 virtual Texture & operator[](const T & at) = 0;
95 static bool Initialised() {return initialised;}
98 static void DrawColourData(SDL_Surface * dest, int destX, int destY, std::vector<SUint> * R, std::vector<SUint> * G, std::vector<SUint> * B, std::vector<SUint> * A = NULL);
99 static void DrawColourData(SDL_Surface * dest, int destX, int destY, std::vector<std::vector<SUint> > * R, std::vector<std::vector<SUint> > * G, std::vector<std::vector<SUint> > * B, std::vector<std::vector<SUint> > * A = NULL);
100 static void DrawTexture(SDL_Surface * dest, SDL_Surface * src, int srcX, int srcY, int destX, int destY, int width, int height);
101 static void DrawPixel(SDL_Surface * dest, int x, int y, Colour colour);
102 static Colour GetPixel(SDL_Surface * dest, int x, int y);
103 static void DrawLine(SDL_Surface * dest, int x1, int y1, int x2, int y2, Colour colour);
108 static std::list<SDL_Surface*> allTextures;
109 static Screen * screen;
111 static int screenWidth;
112 static int screenHeight;
113 static bool initialised;
117 typedef Graphics::Colour Colour;
122 Texture(const char * fileName, bool newDrawCentred = true);
125 void Draw(int x, int y, double angle=0, double scale=1);
126 void DrawColour(int x, int y, double angle, double scale, Colour colour);
128 int width() const {return surface->w;}
129 int height() const {return surface->h;}
132 SDL_Surface * surface;
140 class Font : private Texture
143 Font(const char * fileName, int newWidth, int newHeight);
146 void DrawTextColour(const char * string, int x, int y, double angle, double scale, Colour colour);
147 void DrawText(const char * string, int x, int y, double angle=0, double scale=1);
156 #endif //BUILD_GRAPHICS