X-Git-Url: https://git.ucc.asn.au/?p=progcomp2012.git;a=blobdiff_plain;f=home%2Fprogcomp%2Fjudge%2Fmanager%2Fgraphics.h;fp=home%2Fprogcomp%2Fjudge%2Fmanager%2Fgraphics.h;h=f81bdb3b50329e41f17482a43080e3f9a7c24af0;hp=0000000000000000000000000000000000000000;hb=e3b15cd5dea739f7523920d83bda592db95a7b93;hpb=7f7bc05439b70b3139086086608996de3c9ae2ed diff --git a/home/progcomp/judge/manager/graphics.h b/home/progcomp/judge/manager/graphics.h new file mode 100644 index 0000000..f81bdb3 --- /dev/null +++ b/home/progcomp/judge/manager/graphics.h @@ -0,0 +1,148 @@ +#ifndef GRAPHICS_H +#define GRAPHICS_H + +#include +#include + + +#include +#include + + +typedef SDL_Surface Screen; +typedef SDL_Rect Rectangle; + + +typedef short unsigned int SUint; + +class Texture; +class Font; + + + +class Graphics +{ + public: + + class Colour + { + public: + Colour(float red=0, float green=0, float blue=0, float alpha=0) : r(red), g(green), b(blue), a(alpha) {} + Colour(const Colour & cpy) : r(cpy.r), g(cpy.g), b(cpy.b), a(cpy.a) {} + + Colour & operator=(const Colour & s) {r = s.r; g = s.g; b = s.b; a = s.a; return *this;} + bool operator==(const Colour & s) const {return (r == s.r && g == s.g && b == s.b && a == s.a);} + bool operator!=(const Colour & s) const {return !operator==(s);} + float r; + float g; + float b; + float a; + + }; + static int ScreenWidth() {return screenWidth;} + static int ScreenHeight() {return screenHeight;} + + static void Initialise(const char * caption, int width=640, int height=480); + static void Destroy(); + + static SDL_Surface * LoadTextureBMP(const char * file); + static void SaveTextureBMP(SDL_Surface * tex, const char * file); + + static void ClearScreen(); + static void UpdateScreen(); + static void DrawGrid(int gridWidth, int gridHeight, Colour colour); + static Uint8 MakeColour(int R, int G, int B, int Alpha = 0); + static Colour ConvertColour(Uint8 colour); + + static void DrawTexture(SDL_Surface * src, int destX, int destY, int srcX=0, int srcY=0, int width=-1, int height=-1); + static void DrawTexture(SDL_Surface * src, int destX, int destY, double rotate, double scale); + static void DrawPixel(int x, int y, Colour colour); + + static Colour GetPixel(int x, int y); + static void DrawLine(int x1, int y1, int x2, int y2, Colour colour, double scale=1.0); + static void DrawLineDashed(int x1, int y1, int x2, int y2, Colour colour, double scale=1.0); + static void DrawRectangle(int x1, int y1, int x2, int y2, Colour colour, double scale=1.0); + + static void GetColourData(SDL_Surface * src, std::vector * R, std::vector * G, std::vector * B, std::vector * A = NULL); + static void GetColourData(SDL_Surface * src, std::vector > * R, std::vector > * G, std::vector > * B, std::vector > * A = NULL); + + static void DrawColourData(int destX, int destY, std::vector * R, std::vector * G, std::vector * B, std::vector * A = NULL) {DrawColourData(screen, destX, destY, R, G, B, A);} + + static void DrawColourData(int destX, int destY, std::vector > * R, std::vector > * G, std::vector > * B, std::vector > * A = NULL) {DrawColourData(screen, destX, destY, R, G, B, A);} + + static SDL_Surface * TextureFromColours(std::vector * R, std::vector * G, std::vector * B, std::vector * A = NULL); + static SDL_Surface * TextureFromColours(std::vector > * R, std::vector > * G, std::vector > * B, std::vector > * A = NULL); + + static void Wait(int n) {SDL_Delay(n);} + + template + class TextureManager + { + public: + TextureManager() {} + virtual ~TextureManager() {} + + virtual Texture & operator[](const T & at) = 0; + }; + + static bool Initialised() {return initialised;} + + protected: + static void DrawColourData(SDL_Surface * dest, int destX, int destY, std::vector * R, std::vector * G, std::vector * B, std::vector * A = NULL); + static void DrawColourData(SDL_Surface * dest, int destX, int destY, std::vector > * R, std::vector > * G, std::vector > * B, std::vector > * A = NULL); + static void DrawTexture(SDL_Surface * dest, SDL_Surface * src, int srcX, int srcY, int destX, int destY, int width, int height); + static void DrawPixel(SDL_Surface * dest, int x, int y, Colour colour); + static Colour GetPixel(SDL_Surface * dest, int x, int y); + static void DrawLine(SDL_Surface * dest, int x1, int y1, int x2, int y2, Colour colour); + + private: + Graphics() {} + ~Graphics() {} + static std::list allTextures; + static Screen * screen; + + static int screenWidth; + static int screenHeight; + static bool initialised; + + +}; +typedef Graphics::Colour Colour; + +class Texture +{ + public: + Texture(const char * fileName, bool newDrawCentred = true); + virtual ~Texture(); + + void Draw(int x, int y, double angle=0, double scale=1); + void DrawColour(int x, int y, double angle, double scale, Colour colour); + + int width() const {return surface->w;} + int height() const {return surface->h;} + protected: + SDL_Surface * surface; + GLuint texture; + + private: + bool drawCentred; + +}; + +class Font : private Texture +{ + public: + Font(const char * fileName, int newWidth, int newHeight); + virtual ~Font(); + + void DrawTextColour(const char * string, int x, int y, double angle, double scale, Colour colour); + void DrawText(const char * string, int x, int y, double angle=0, double scale=1); + private: + int width; + int height; +}; + + +#endif //GRAPHICS_H + +//EOF