-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFramework.h
254 lines (203 loc) · 6.1 KB
/
Framework.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
/*******************************************************************************
CommanderTux
Penguin In Space
Released under the GNU Public License
2005 by Andr� Schnabel ([email protected])
*******************************************************************************/
// Framework.h
// This similiar to an engine
#ifndef FRAMEWORK_H
#define FRAMEWORK_H
#include <SDL.h>
#include <SDL_image.h>
#include <SDL_ttf.h>
#ifndef NO_SOUND
#include <SDL_mixer.h>
#endif
// this is only for old compilers that don't understand the full standard
// VS6 users have to enable this!!!
#define CSTYLE 0
#if CSTYLE == 1
#include <stdlib.h>
#include <stdio.h>
#include <string.h> // for memcpy!
#include <time.h> // time() for srand
#include <math.h>
#else
#include <cstdlib>
#include <cstdio>
#include <cstring> // for memcpy!
#include <ctime> // time() for srand
#include <cmath>
using namespace std;
// VS6 users have to enable CSTYLE!
#endif
#include "Defines.h"
#include "Filenames.h"
#include "LinkedList.h"
struct SFramework_Setup;
SFramework_Setup ParseArgs( int argc, char *argv[], bool *stop );
struct SFramework_Setup
{
bool doublebuf, fullscreen;
int scr_w, scr_h, scr_bpp;
Uint32 scr_flags;
const char *caption;
bool editor, duel;
SFramework_Setup()
{
scr_w = SCR_W;
scr_h = SCR_H;
scr_bpp = 16;
scr_flags = SDL_WINDOW_OPENGL;
doublebuf = true;
fullscreen = false;
caption = "Framework";
editor = duel = false;
}
};
// Loaded structure, so we only shutdown things that are already loaded!
struct SFramework_Loaded
{
bool sdl, vid, snd, ttf;
bool everything;
SFramework_Loaded()
{ sdl = vid = snd = ttf = everything = false; }
};
// Error messages
typedef enum
{
ERR_SDL,
ERR_VID,
ERR_SND,
ERR_IMG
} Err_Msg;
// Font sizes
typedef enum
{
F_SIZE_SMALL,
F_SIZE_MEDIUM,
F_SIZE_BIG,
F_SIZE_BIGGEST
} Font_Size;
// SDL colors
struct SDL_Colors
{
SDL_Color magenta, black, white;
SDL_Color red, green, blue;
SDL_Color bright_blue, gray;
SDL_Color yellow;
};
// Unsigned int 32bit colors
struct Uint32_Colors
{
Uint32 magenta, black, white;
Uint32 red, green, blue;
Uint32 bright_blue, gray;
Uint32 yellow;
};
// Colors
typedef enum
{
COLOR_MAGENTA,
COLOR_BLACK,
COLOR_WHITE,
COLOR_RED,
COLOR_GREEN,
COLOR_BLUE,
COLOR_BRIGHT_BLUE,
COLOR_GRAY,
COLOR_YELLOW
} Color;
class CFramework
{
public:
CFramework( SFramework_Setup *setup = NULL );
~CFramework();
void SetVideoMode();
void SetVideoMode( int w, int h );
void SetCaption();
void Error( Err_Msg msg );
SDL_Texture * LoadImage(const char *filename, bool withColorKey = true );
SDL_Surface *GetScreen();
void SetScreen( SDL_Surface *screen );
SDL_Renderer *GetRenderer() {
return m_renderer;
}
SFramework_Loaded *GetLoaded();
SFramework_Setup *GetSetup();
void Lock( SDL_Surface *surf );
void Unlock( SDL_Surface *surf );
void LockScreen() { Lock( m_screen ); }
void UnlockScreen() { Unlock( m_screen ); }
void DrawPixel( int x, int y, Color color );
void DrawGrid( int grid_w, int grid_h, int size_w, int size_h );
void Draw(SDL_Texture *surf );
void Draw(SDL_Texture *surf, int x, int y );
void Draw(SDL_Texture *surf, SDL_Rect *target_rect );
void Draw(SDL_Texture *surf, SDL_Rect *src_rect, SDL_Rect *target_rect );
void DrawText( const char *text, int x, int y, Color color, Font_Size size );
SDL_Texture *DrawTextOnSurface( const char *text, SDL_Color color, Font_Size size );
void DrawNumber( int num, int x, int y, Color color, Font_Size size );
void DrawShadowText( const char *text, int x, int y, Color shadow_color, Color color, Font_Size size );
void DrawShadowNumber( int num, int x, int y, Color shadow_color, Color color, Font_Size size );
Uint32 GetTicks();
void SetAlpha(SDL_Texture *surf, Uint8 alpha );
void SetColorKey(SDL_Texture *surf, Color colorkey );
void FillRect( SDL_Surface *surf, SDL_Rect *rect, Color color );
Uint32 GetColorUint32( Color color );
SDL_Color GetColorSDLColor( Color color );
bool Coll( SDL_Rect *rect1, SDL_Rect *rect2 );
void ReverseDirection( Direction *dir );
void ReverseBool( bool *var )
{
if( *var )
*var = false;
else
*var = true;
}
void MakeScreenshot( const char *filename );
// Never forget to delete the given buffer
// after you are done
char *NumToText( int num )
{
char *buffer = new char [256];
sprintf( buffer, "%d", num );
return buffer;
}
void Fullscreen();
void Windowed();
void ShowCursor( bool value )
{
if( value )
SDL_ShowCursor( SDL_ENABLE );
else
SDL_ShowCursor( SDL_DISABLE );
}
void SetCaption( const char *caption )
{
m_setup->caption = caption;
SDL_SetWindowTitle(m_window, caption);
}
int GetTextureWidth(SDL_Texture *tex) const {
int w;
SDL_QueryTexture(tex, nullptr, nullptr, &w, nullptr);
return w;
}
int GetTextureHeight(SDL_Texture *tex) const {
int h;
SDL_QueryTexture(tex, nullptr, nullptr, nullptr, &h);
return h;
}
private:
SDL_Renderer *m_renderer;
SDL_Window *m_window;
SDL_Surface *m_screen;
TTF_Font *m_font_small, *m_font_medium, *m_font_big, *m_font_biggest;
SFramework_Setup *m_setup;
SFramework_Loaded m_loaded;
SDL_Colors m_sdl_colors;
Uint32_Colors m_uint32_colors;
};
extern CFramework *g_framework;
#endif