]> git.mxchange.org Git - quix0rs-blobwars.git/blob - src/CGraphics.h
Fix color key and alpha blending.
[quix0rs-blobwars.git] / src / CGraphics.h
1 /*
2 Copyright (C) 2004-2011 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 void SDL_SetAlpha(SDL_Surface *surface, uint8_t value);
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
32                 List spriteList;
33
34                 int fontSize;
35                 
36                 int waterAnim;
37                 int slimeAnim;
38                 int lavaAnim;
39
40                 int currentLoading;
41
42                 int screenShotNumber;
43                 char screenshot[100];
44                 char chatString[1024];
45                 
46                 SDL_Surface *medalMessage;
47                 int medalMessageTimer;
48                 int medalType;
49
50                 SDL_Surface *fadeBlack;
51                 SDL_Surface *infoMessage;
52
53         public:
54                 struct SurfaceCache {
55                         char *text;
56                         SDL_Surface *surface;
57                         SurfaceCache(): text(NULL), surface(NULL) {}    
58                 };
59
60                 bool takeRandomScreenShots;
61
62                 SDL_Window *window;
63                 SDL_Renderer *renderer;
64                 SDL_Texture *texture;
65                 SDL_Surface *screen, *background;
66                 SDL_Surface *tile[MAX_TILES];
67                 
68                 SDL_Surface *medal[4];
69                 SDL_Surface *license[2];
70                 
71                 SDL_Surface *infoBar;
72
73                 int red, yellow, green, darkGreen, skyBlue, blue, cyan, white, lightGrey, grey, darkGrey, black;
74
75         Graphics();
76         void free();
77         void destroy();
78         void registerEngine(Engine *engine);
79         void mapColors();
80         Sprite *getSpriteHead();
81         void setTransparent(SDL_Surface *sprite);
82         void updateScreen();
83         bool canShowMedalMessage() const;
84         void delay(int time);
85         void RGBtoHSV(float r, float g, float b, float *h, float *s, float *v);
86         void HSVtoRGB(float *r, float *g, float *b, float h, float s, float v);
87         SDL_Surface *loadImage(const char *filename, bool srcalpha = false);
88         SDL_Surface *loadImage(const char *filename, int hue, int sat, int value);
89         SDL_Surface *quickSprite(const char *name, SDL_Surface *image);
90         void fade(int amount);
91         void fadeToBlack();
92         void loadMapTiles(const char *baseDir);
93         void loadFont(int i, const char *filename, int pixelSize);
94         Sprite *addSprite(const char *name);
95         Sprite *getSprite(const char *name, bool required);
96         void animateSprites();
97         int getWaterAnim() const;
98         int getSlimeAnim() const;
99         int getLavaAnim() const;
100         int getLavaAnim(int current);
101         void loadBackground(const char *filename);
102         void putPixel(int x, int y, Uint32 pixel, SDL_Surface *dest);
103         Uint32 getPixel(SDL_Surface *surface, int x, int y);
104         void drawLine(float startX, float startY, float endX, float endY, int color, SDL_Surface *dest);
105         void blit(SDL_Surface *image, int x, int y, SDL_Surface *dest, bool centered);
106         void drawBackground();
107         void drawBackground(SDL_Rect *r);
108         void drawRect(int x, int y, int w, int h, int color, SDL_Surface *dest);
109         void drawRect(int x, int y, int w, int h, int color, int borderColor, SDL_Surface *dest);
110         void setFontColor(int red, int green, int blue, int red2, int green2, int blue2);
111         void setFontSize(int size);
112         SDL_Surface *getString(const char *in, bool transparent);
113         void drawString(const char *in, int x, int y, int alignment, SDL_Surface *dest);
114         void drawString(const char *in, int x, int y, int alignment, SDL_Surface *dest, SurfaceCache &cache);
115         void clearChatString();
116         void createChatString(const char *in);
117         void showMedalMessage(int type, const char *in);
118         void drawChatString(SDL_Surface *surface, int y);
119         void drawWidgetRect(int x, int y, int w, int h);
120         SDL_Surface *createSurface(int width, int height);
121         SDL_Surface *alphaRect(int width, int height, Uint8 red, Uint8 green, Uint8 blue);
122         void colorize(SDL_Surface *image, int red, int green, int blue);
123         void lock(SDL_Surface *surface);
124         void unlock(SDL_Surface *surface);
125         void resetLoading();
126         void showLoading(int amount, int max);
127         void showErrorAndExit(const char *error, const char *param);
128         void showLicenseErrorAndExit();
129         void showRootWarning();
130
131 };