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