|
@@ -8,16 +8,6 @@
|
8
|
8
|
#include <cstdio>
|
9
|
9
|
#include <assert.h>
|
10
|
10
|
|
11
|
|
-#include "SDL_ttf.h"
|
12
|
|
-
|
13
|
|
-#ifdef __APPLE__
|
14
|
|
-#include <OpenGL/gl.h>
|
15
|
|
-#include <OpenGL/glu.h>
|
16
|
|
-#else
|
17
|
|
-#include <GL/gl.h>
|
18
|
|
-#include <GL/glu.h>
|
19
|
|
-#endif
|
20
|
|
-
|
21
|
11
|
#include "config.h"
|
22
|
12
|
#include "utils/strings.h"
|
23
|
13
|
#include "WindowSDL.h"
|
|
@@ -31,10 +21,11 @@ WindowSDL::WindowSDL() {
|
31
|
21
|
mHeight = DEFAULT_HEIGHT;
|
32
|
22
|
mFullscreen = false;
|
33
|
23
|
mMousegrab = false;
|
34
|
|
- mFont = NULL;
|
35
|
|
- mFontInit = false;
|
36
|
24
|
mWindow = NULL;
|
37
|
25
|
mGLContext = NULL;
|
|
26
|
+ mFontInit = false;
|
|
27
|
+ mFontName = NULL;
|
|
28
|
+ mFont = NULL;
|
38
|
29
|
|
39
|
30
|
#ifdef WIN32
|
40
|
31
|
setDriver("libGL32.dll");
|
|
@@ -49,14 +40,17 @@ WindowSDL::~WindowSDL() {
|
49
|
40
|
SDL_Quit();
|
50
|
41
|
}
|
51
|
42
|
|
|
43
|
+ if (mFont)
|
|
44
|
+ TTF_CloseFont(mFont);
|
|
45
|
+
|
52
|
46
|
if (mFontInit)
|
53
|
47
|
TTF_Quit();
|
54
|
48
|
|
55
|
49
|
if (mDriver)
|
56
|
50
|
delete [] mDriver;
|
57
|
51
|
|
58
|
|
- if (mFont)
|
59
|
|
- delete [] mFont;
|
|
52
|
+ if (mFontName)
|
|
53
|
+ delete [] mFontName;
|
60
|
54
|
}
|
61
|
55
|
|
62
|
56
|
void WindowSDL::setDriver(const char *driver) {
|
|
@@ -215,19 +209,25 @@ void WindowSDL::setFont(const char *font) {
|
215
|
209
|
assert(font[0] != '\0');
|
216
|
210
|
assert(mFontInit == false);
|
217
|
211
|
|
218
|
|
- mFont = fullPath(font, 0);
|
|
212
|
+ mFontName = fullPath(font, 0);
|
219
|
213
|
}
|
220
|
214
|
|
221
|
215
|
int WindowSDL::initializeFont() {
|
222
|
216
|
assert(mFontInit == false);
|
223
|
|
- assert(mFont != NULL);
|
224
|
|
- assert(mFont[0] != '\0');
|
|
217
|
+ assert(mFontName != NULL);
|
|
218
|
+ assert(mFontName[0] != '\0');
|
225
|
219
|
|
226
|
220
|
if (TTF_Init() != 0) {
|
227
|
221
|
printf("Could not initialize SDL-TTF!\n");
|
228
|
222
|
return -1;
|
229
|
223
|
}
|
230
|
224
|
|
|
225
|
+ mFont = TTF_OpenFont(mFontName, 24);
|
|
226
|
+ if (mFont == NULL) {
|
|
227
|
+ printf("TTF_OpenFont Error: %s\n", TTF_GetError());
|
|
228
|
+ return -2;
|
|
229
|
+ }
|
|
230
|
+
|
231
|
231
|
mFontInit = true;
|
232
|
232
|
return 0;
|
233
|
233
|
}
|
|
@@ -237,6 +237,34 @@ void WindowSDL::writeString(WindowString *s) {
|
237
|
237
|
assert(s->text != NULL);
|
238
|
238
|
assert(mInit == true);
|
239
|
239
|
|
|
240
|
+ SDL_Color color;
|
|
241
|
+ color.r = s->color[0];
|
|
242
|
+ color.g = s->color[1];
|
|
243
|
+ color.b = s->color[2];
|
|
244
|
+
|
|
245
|
+ SDL_Surface *surface = TTF_RenderUTF8_Blended(mFont, s->text, color);
|
|
246
|
+ if (surface == NULL) {
|
|
247
|
+ printf("TTF_RenderUTF8_Blended Error: %s\n", TTF_GetError());
|
|
248
|
+ return;
|
|
249
|
+ }
|
|
250
|
+
|
|
251
|
+ SDL_Surface *window = SDL_GetWindowSurface(mWindow);
|
|
252
|
+ if (window == NULL) {
|
|
253
|
+ printf("SDL_GetWindowSurface Error: %s\n", SDL_GetError());
|
|
254
|
+ return;
|
|
255
|
+ }
|
|
256
|
+
|
|
257
|
+ SDL_Rect destination;
|
|
258
|
+ destination.x = s->x;
|
|
259
|
+ destination.y = s->y;
|
|
260
|
+ destination.w = (int)((float)surface->w * s->scale);
|
|
261
|
+ destination.h = (int)((float)surface->h * s->scale);
|
|
262
|
+
|
|
263
|
+ if (SDL_BlitScaled(surface, NULL, window, &destination) != 0) {
|
|
264
|
+ printf("SDL_BlitScaled Error: %s\n", SDL_GetError());
|
|
265
|
+ return;
|
|
266
|
+ }
|
240
|
267
|
|
|
268
|
+ SDL_FreeSurface(surface);
|
241
|
269
|
}
|
242
|
270
|
|