1 /*
2 Copyright (C) 2004 Parallel Realities
3 
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License
6 as published by the Free Software Foundation; either version 2
7 of the License, or (at your option) any later version.
8 
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12 
13 See the GNU General Public License for more details.
14 
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
18 
19 */
20 
21 #include <stdarg.h>
22 
23 class Graphics {
24 
25 	private:
26 
27 		Engine *engine;
28 		SDL_Rect gRect;
29 		TTF_Font *font[5];
30 		SDL_Color fontForeground, fontBackground;
31 		SDL_Surface *fadeBlack;
32 
33 		Sprite *spriteHead;
34 		Sprite *spriteTail;
35 
36 		int fontSize;
37 
38 		int screenShotNumber;
39 		char screenshot[100];
40 
41 		char textstring[256];
42 
43 		SDL_Surface *medalMessage;
44 		float medalMessageTimer;
45 		int medalType;
46 
47 	public:
48 
49 		bool takeRandomScreenShots;
50 
51 		SDL_Surface *screen, *background, *infoBar;
52 		SDL_Surface *tile[100];
53 
54 		SDL_Surface *medal[4];
55 
56 		int red, yellow, skyBlue, blue, cyan, white, lightGrey, grey, darkGrey, black;
57 		int lightestGreen, lightGreen, green, darkGreen, darkestGreen;
58 
59 	Graphics();
60 	void free();
61 	void destroy();
62 	void mapColors();
63 	Sprite *getSpriteHead();
64 	void setTransparent(SDL_Surface *sprite);
65 	void updateScreen();
66 	bool canShowMedalMessage();
67 	void delay(int time);
68 	void clearScreen(int color);
69 	void RGBtoHSV(float r, float g, float b, float *h, float *s, float *v);
70 	void HSVtoRGB(float *r, float *g, float *b, float h, float s, float v);
71 	SDL_Surface *loadImage(const char *filename);
72 	SDL_Surface *loadImage(const char *filename, int hue, int sat, int value);
73 	SDL_Surface *quickSprite(const char *name, SDL_Surface *image);
74 	void fade(int amount);
75 	void fadeToBlack();
76 	void loadMapTiles(const char *baseDir);
77 	void loadFont(int i, const char *filename, int pointSize);
78 	Sprite *addSprite(const char *name);
79 	Sprite *getSprite(const char *name, bool required);
80 	void animateSprites();
81 	void loadBackground(const char *filename);
82 	void putPixel(int x, int y, Uint32 pixel, SDL_Surface *dest);
83 	Uint32 getPixel(SDL_Surface *surface, int x, int y);
84 	void drawLine(float startX, float startY, float endX, float endY, int color, SDL_Surface *dest);
85 	void blit(SDL_Surface *image, int x, int y, SDL_Surface *dest, bool centered);
86 	void showMedalMessage(int type, const char *in);
87 	void drawBackground();
88 	void drawBackground(SDL_Rect *r);
89 	void drawRect(int x, int y, int w, int h, int color, SDL_Surface *dest);
90 	void drawRect(int x, int y, int w, int h, int color, int borderColor, SDL_Surface *dest);
91 	void setFontColor(int red, int green, int blue, int red2, int green2, int blue2);
92 	void setFontSize(int size);
93 	SDL_Surface *getString(bool transparent, const char *in, ...);
94 	void drawString(int x, int y, int alignment, SDL_Surface *dest, const char *in, ...);
95 	void clearChatString();
96 	void createChatString(const char *in);
97 	void drawChatString();
98 	void drawWidgetRect(int x, int y, int w, int h);
99 	SDL_Surface *createSurface(int width, int height);
100 	SDL_Surface *alphaRect(int width, int height, Uint8 red, Uint8 green, Uint8 blue);
101 	void colorize(SDL_Surface *image, int red, int green, int blue);
102 	void lock(SDL_Surface *surface);
103 	void unlock(SDL_Surface *surface);
104 	void resetLoading();
105 	void showLoading(int amount, int max);
106 	void showErrorAndExit(const char *error, const char *param);
107 
registerEngine(Engine * engine)108 	const void registerEngine(Engine *engine)
109 	{
110 		this->engine = engine;
111 	}
112 
113 };
114