enable fonts to be loaded when windows has been installed other than default location
This commit is contained in:
18
SDLHelpers.h
18
SDLHelpers.h
@@ -8,6 +8,10 @@
|
||||
#include <iostream>
|
||||
#include <cmath>
|
||||
|
||||
#ifdef SDL_PLATFORM_WINDOWS
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
static const char *font_paths[] = {"C:/windows/fonts/", "/usr/share/fonts/TTF/", "./"};
|
||||
static const short font_path_count = 3;
|
||||
|
||||
@@ -31,12 +35,24 @@ static SDL_Color getColor(Uint8 r, Uint8 g, Uint8 b) {
|
||||
static TTF_Font *openFont(std::vector<std::string> fonts, int size) {
|
||||
TTF_Font *font = NULL;
|
||||
for (int x = 0; x < fonts.size(); x++) {
|
||||
#ifdef SDL_PLATFORM_WINDOWS
|
||||
TCHAR windir[MAX_PATH];
|
||||
GetWindowsDirectory(windir, MAX_PATH);
|
||||
std::string windir_s(windir);
|
||||
windir_s.append("/fonts/");
|
||||
windir_s.append(fonts[x]);
|
||||
font = TTF_OpenFont(windir_s.c_str(), size);
|
||||
if (font) {
|
||||
return font;
|
||||
}
|
||||
#endif
|
||||
for (int y = 0; y < font_path_count; y++) {
|
||||
std::string val(font_paths[y]);
|
||||
val.append(fonts[x]);
|
||||
font = TTF_OpenFont(val.c_str(), size);
|
||||
if (font)
|
||||
if (font) {
|
||||
return font;
|
||||
}
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
|
||||
Reference in New Issue
Block a user