Commit 57715eca authored by David Bruce's avatar David Bruce

removal of rest of traces of SDL_ttf from files other than SDL_extras.c/.h



git-svn-id: svn://svn.debian.org/svn/tux4kids/tuxtype/trunk@923 47d30e19-490b-0410-9d18-e851f4e465b3
parent e6928592
03 Mar 2009 (svn.debian.org/tux4kids - revision 923)
[ David Bruce <davidstuartbruce@gmail.com> ]
- Text drawing -
22 Feb 2009 svn revision 903
[ David Bruce <davidstuartbruce@gmail.com> ]
- lots of general code cleanup to eliminate most of the compiler warnings,
......
......@@ -585,19 +585,20 @@ SDL_Surface* zoom(SDL_Surface* src, int new_w, int new_h)
//#undef HAVE_LIBSDL_PANGO
#define MAX_FONT_SIZE 40
#define MAX_FONT_SIZE 72
/*-- file-scope variables and local file prototypes for SDL_Pango-based code: */
#ifdef HAVE_LIBSDL_PANGO
#include "SDL_Pango.h"
SDLPango_Context* context = NULL;
static int current_pango_font_size = 0;
static SDLPango_Matrix* SDL_Colour_to_SDLPango_Matrix(const SDL_Color* cl);
static int Set_SDL_Pango_Font_Size(int size);
/*-- file-scope variables and local file prototypes for SDL_ttf-based code: */
#else
#include "SDL_ttf.h"
/* We cache fonts here once loaded to improve performance: */
TTF_Font* font_list[MAX_FONT_SIZE] = {NULL};
TTF_Font* font_list[MAX_FONT_SIZE + 1] = {NULL};
static void free_font_list(void);
static TTF_Font* get_font(int size);
static TTF_Font* load_font(const char* font_name, int font_size);
......@@ -606,14 +607,6 @@ static TTF_Font* load_font(const char* font_name, int font_size);
void reset_DPI_SDLPango_Context(float dpi_x, float dpi_y)
{
#ifdef HAVE_LIBSDL_PANGO
SDLPango_SetDpi(context, dpi_x, dpi_y);
#endif
}
/* "Public" functions called from other files that use either */
/*SDL_Pango or SDL_ttf: */
......@@ -623,15 +616,11 @@ void reset_DPI_SDLPango_Context(float dpi_x, float dpi_y)
int Setup_SDL_Text(void)
{
#ifdef HAVE_LIBSDL_PANGO
char buf[64];
LOG("Setup_SDL_Text() - using SDL_Pango\n");
SDLPango_Init();
snprintf(buf, 64, "[%s][][%d]", DEFAULT_FONT_NAME, DEFAULT_MENU_FONT_SIZE);
context = SDLPango_CreateContext_GivenFontDesc(buf);
if (!context)
if (!Set_SDL_Pango_Font_Size(DEFAULT_MENU_FONT_SIZE))
{
fprintf(stderr, "\nError: I could not set SDL_Pango context\n");
return 0;
......@@ -684,27 +673,27 @@ SDL_Surface* BlackOutline(const char* t, int font_size, const SDL_Color* c)
#ifdef HAVE_LIBSDL_PANGO
if (!context)
{
fprintf(stderr, "BlackOutline(): invalid SDL_Pango context - returning.");
fprintf(stderr, "BlackOutline(): invalid SDL_Pango context - returning.\n");
return NULL;
}
#else
TTF_Font* font = get_font(DEFAULT_FONT_NAME, size);
TTF_Font* font = get_font(font_size);
if (!font)
{
fprintf(stderr, "BlackOutline(): could not load needed font - returning.");
fprintf(stderr, "BlackOutline(): could not load needed font - returning.\n");
return NULL;
}
#endif
if (!t || !c)
{
fprintf(stderr, "BlackOutline(): invalid ptr parameter, returning.");
fprintf(stderr, "BlackOutline(): invalid ptr parameter, returning.\n");
return NULL;
}
if (t[0] == '\0')
{
fprintf(stderr, "BlackOutline(): empty string, returning");
fprintf(stderr, "BlackOutline(): empty string, returning\n");
return NULL;
}
......@@ -715,6 +704,7 @@ DEBUGCODE
}
#ifdef HAVE_LIBSDL_PANGO
Set_SDL_Pango_Font_Size(font_size);
SDLPango_SetDefaultColor(context, MATRIX_TRANSPARENT_BACK_BLACK_LETTER);
SDLPango_SetText(context, t, -1);
black_letters = SDLPango_CreateSurfaceDraw(context);
......@@ -831,20 +821,46 @@ SDL_Surface* BlackOutline_w(const wchar_t* t, int font_size, const SDL_Color* c,
return BlackOutline(tmp, font_size, c);
}
/* This (fast) function just returns a non-outlined surf */
/* using either SDL_Pango or SDL_ttf */
SDL_Surface* SimpleText(const char *t, int size, SDL_Color* col)
{
SDL_Surface* surf = NULL;
if (!t||!col)
return NULL;
/* When SDL_Pango is used, the ttf font sizes are ignored */
/* by BlackOutline(), so we adjust dpi to scale the fonts: */
/* HACK this isn't quite the intended use of SDLPango_SetDpi() */
void ScaleDPIforFS(void)
{
#ifdef HAVE_LIBSDL_PANGO
if (!context)
{
fprintf(stderr, "SimpleText() - context not valid!\n");
return NULL;
}
else
{
SDLPango_Matrix colormatrix =
{
col->r, col->r, 0, 0,
col->g, col->g, 0, 0,
col->b, col->b, 0, 0,
0, 255, 0, 0,
};
Set_SDL_Pango_Font_Size(size);
SDLPango_SetDefaultColor(context, &colormatrix );
SDLPango_SetText(context, t, -1);
surf = SDLPango_CreateSurfaceDraw(context);
}
#else
{
float dpi_x, dpi_y;
dpi_x = dpi_y = 125 * ((float)screen->h/(float)480);
reset_DPI_SDLPango_Context(dpi_x, dpi_y);
TTF_Font* font = get_font(size);
if (!font)
return NULL;
surf = TTF_RenderUTF8_Blended(font, t, *col);
}
#endif
return surf;
}
......@@ -856,7 +872,37 @@ void ScaleDPIforFS(void)
#ifdef HAVE_LIBSDL_PANGO
/* Local functions when using SDL_Pango: */
/* Local functions when using SDL_Pango: ------------------------------- */
/* FIXME the '0.7' a few lines down is to compensate for the larger font size */
/* that SDL_Pango generates relative to a TTF_Font of the same numerical size - */
/* this was picked by trial and error, ought to understand this better - DSB */
static int Set_SDL_Pango_Font_Size(int size)
{
/* Do nothing unless we need to change size: */
if (size == current_pango_font_size)
return 1;
else
{
char buf[64];
DEBUGCODE { fprintf(stderr, "Setting font size to %d\n", size); }
if(context != NULL)
SDLPango_FreeContext(context);
context = NULL;
snprintf(buf, sizeof(buf), "%s %d", DEFAULT_FONT_NAME, (int)(size * 0.7));
context = SDLPango_CreateContext_GivenFontDesc(buf);
}
if (!context)
return 0;
else
{
current_pango_font_size = size;
return 1;
}
}
SDLPango_Matrix* SDL_Colour_to_SDLPango_Matrix(const SDL_Color *cl)
{
......@@ -911,12 +957,19 @@ static void free_font_list(void)
/* font in memory once loaded until cleanup. */
static TTF_Font* get_font(int size)
{
if (size < 0 || size > MAX_FONT_SIZE)
if (size < 0)
{
fprintf(stderr, "Error - requested font size %d is invalid\n", size);
fprintf(stderr, "Error - requested font size %d is negative\n", size);
return NULL;
}
if (size > MAX_FONT_SIZE)
{
fprintf(stderr, "Error - requested font size %d exceeds max = %d, resetting.\n",
size, MAX_FONT_SIZE);
size = MAX_FONT_SIZE;
}
if(font_list[size] == NULL)
font_list[size] = load_font(DEFAULT_FONT_NAME, size);
return font_list[size];
......
......@@ -17,7 +17,6 @@
#include "../config.h"
#include "SDL.h"
#include "SDL_ttf.h"
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
......@@ -43,22 +42,13 @@ void SwitchScreenMode(void);
int WaitForKeypress(void);
SDL_Surface* Blend(SDL_Surface *S1, SDL_Surface *S2,float gamma);
SDL_Surface* zoom(SDL_Surface * src, int new_w, int new_h);
void ScaleDPIforFS(void);
void ResetDPI(void);
/* These functions are the only code in the program that directly use SDL_Pango */
/* If SDL_Pango not available, they fall back to SDL_ttf or do nothing, */
/* as appropriate. */
SDL_Surface* BlackOutline(const char* t, int font_size, const SDL_Color* c);
SDL_Surface* BlackOutline_w(const wchar_t* t, int font_size, const SDL_Color* c, int length);
void reset_DPI_SDLPango_Context(float dpi_x, float dpi_y);
/*Text rendering functions: */
int Setup_SDL_Text(void);
void Cleanup_SDL_Text(void);
//SDL_Surface* BlackOutline(const char* t, int size, SDL_Color* c);
//SDL_Surface* SimpleText(const char *t, int size, SDL_Color* col);
SDL_Surface* BlackOutline(const char* t, int font_size, const SDL_Color* c);
SDL_Surface* BlackOutline_w(const wchar_t* t, int font_size, const SDL_Color* c, int length);
SDL_Surface* SimpleText(const char *t, int size, SDL_Color* col);
//SDL_Surface* SimpleTextWithOffset(const char *t, int size, SDL_Color* col, int *glyph_offset);
#endif
......@@ -276,7 +276,6 @@ int GetIndex(wchar_t uni_char)
fprintf(stderr, "GetIndex - Unicode char '%C' not found in list.\n", uni_char);
return -1;
}
fprintf(stderr, "Done with GetIndex()\n");
return i;
}
......@@ -1178,8 +1177,9 @@ void GenerateKeyboard(SDL_Surface* keyboard)
int col;
char row;
int render = 1;
Uint16 t[2];
TTF_Font* smallfont = NULL;
wchar_t t[2];
char buf[8];
// TTF_Font* smallfont = NULL;
DEBUGCODE { printf("Entering GenerateKeyboard\n"); }
......@@ -1189,12 +1189,12 @@ void GenerateKeyboard(SDL_Surface* keyboard)
return;
}
smallfont = LoadFont(settings.theme_font_name, 15);
if(!smallfont)
{
DEBUGCODE { printf("Error loading font\n"); }
return;
}
// smallfont = LoadFont(settings.theme_font_name, 15);
// if(!smallfont)
// {
// DEBUGCODE { printf("Error loading font\n"); }
// return;
// }
/* to give us a null-terminated string: */
t[1] = '\0';
......@@ -1211,14 +1211,16 @@ void GenerateKeyboard(SDL_Surface* keyboard)
t[0] = keyboard_list[i].unicode_value;
sscanf(keyboard_list[i].keyname,"%c%d",&row,&col);
/* NOTE these values have been tweaked to better center the */
/* characters on the key images - DSB. */
switch(row)
{
case 'A': new.y += 6; new.x += 13; break;
case 'B': new.y += 36; new.x += 23; break;
case 'C': new.y += 66; new.x += 33; break;
case 'A': new.y += 6; new.x += 12; break;
case 'B': new.y += 39; new.x += 23; break;
case 'C': new.y += 69; new.x += 33; break;
// case 'D': new.y += 96; new.x += 23; break;
case 'D': new.y += 96; new.x += 54; break;
case 'E': new.y += 126; break;
case 'D': new.y += 99; new.x += 54; break;
case 'E': new.y += 129; break;
default: render = 0; break;
}
......@@ -1237,9 +1239,9 @@ void GenerateKeyboard(SDL_Surface* keyboard)
}
DEBUGCODE { printf("Making %d : %C\n",i,keyboard_list[i].unicode_value); }
//tmp=BlackOutline_Unicode(t, smallfont, &black);
tmp = TTF_RenderUNICODE_Blended((TTF_Font*)smallfont, t, black);
ConvertToUTF8(t, buf, 8);
tmp = SimpleText(buf, 15, &black);
// tmp = TTF_RenderUNICODE_Blended((TTF_Font*)smallfont, t, black);
if(tmp == NULL)
{
fprintf(stderr, "Error Making %d : %C\n", i, keyboard_list[i].unicode_value);
......@@ -1248,7 +1250,7 @@ void GenerateKeyboard(SDL_Surface* keyboard)
SDL_BlitSurface(tmp, NULL, keyboard, &new);
}
//Know this is safe - if NULL would have returned above:
TTF_CloseFont(smallfont);
// TTF_CloseFont(smallfont);
DEBUGCODE { printf("Leaving GenerateKeyboard\n"); }
}
......
......@@ -67,7 +67,6 @@ int PlayLaserGame(int diff_level);
int CheckFile(const char* file);
sprite* FlipSprite(sprite* in, int X, int Y);
void FreeSprite(sprite* gfx);
TTF_Font* LoadFont(const char* fontfile, int fontsize);
SDL_Surface* LoadImage(const char* datafile, int mode);
int LoadBothBkgds(const char* datafile);
SDL_Surface* CurrentBkgd(void);
......
......@@ -65,19 +65,7 @@
#include "SDL.h"
#include "SDL_image.h"
#include "SDL_mixer.h"
#include "SDL_ttf.h"
//#include <SDL/SDL.h>
//#include <SDL/SDL_image.h>
//#include <SDL/SDL_mixer.h>
//#include <SDL/SDL_ttf.h>
//#include "i18n.h"
//#include <libintl.h>
//#define _(String) gettext(String)
//#define gettext_noop(String) (String)
/* NOTE only SDL_extras.c/.h now knows about SDL_ttf or SDL_Pango. */
#endif // __GLOBALS_H__
......
......@@ -116,71 +116,6 @@ int max(int n1, int n2)
/* FIXME need code to search for font paths on different platforms */
TTF_Font* LoadFont(const char* font_name, int font_size )
{
TTF_Font* loaded_font = NULL;
char fn[FNLEN];
/* try to find font in default data dir: */
sprintf(fn, "%s/fonts/%s", settings.default_data_path, font_name );
DEBUGCODE { fprintf(stderr, "LoadFont(): looking for %s using data paths\n", fn); }
/* try to load the font, if successful, return font*/
loaded_font = TTF_OpenFont(fn, font_size);
if (loaded_font != NULL)
return loaded_font;
/* HACK hard-coded for Debian (and current exact font names): */
if (strncmp(font_name, "AndikaDesRevG.ttf", FNLEN ) == 0)
sprintf(fn, "/usr/share/fonts/truetype/ttf-sil-andika/AndikaDesRevG.ttf");
else if (strncmp(font_name, "DoulosSILR.ttf", FNLEN ) == 0)
sprintf(fn, "/usr/share/fonts/truetype/ttf-sil-doulos/DoulosSILR.ttf");
else if (strncmp(font_name, "Kedage-n.ttf", FNLEN ) == 0)
sprintf(fn, "/usr/share/fonts/truetype/ttf-kannada-fonts/Kedage-n.ttf");
else if (strncmp(font_name, "lohit_bn.ttf", FNLEN ) == 0)
sprintf(fn, "/usr/share/fonts/truetype/ttf-bengali-fonts/lohit_bn.ttf");
else if (strncmp(font_name, "lohit_gu.ttf", FNLEN ) == 0)
sprintf(fn, "/usr/share/fonts/truetype/ttf-indic-fonts-core/lohit_gu.ttf");
else if (strncmp(font_name, "lohit_hi.ttf", FNLEN ) == 0)
sprintf(fn, "/usr/share/fonts/truetype/ttf-indic-fonts-core/lohit_hi.ttf");
else if (strncmp(font_name, "lohit_pa.ttf", FNLEN ) == 0)
sprintf(fn, "/usr/share/fonts/truetype/ttf-indic-fonts-core/lohit_pa.ttf");
else if (strncmp(font_name, "lohit_ta.ttf", FNLEN ) == 0)
sprintf(fn, "/usr/share/fonts/truetype/ttf-indic-fonts-core/lohit_ta.ttf");
else if (strncmp(font_name, "Rachana_w01.ttf", FNLEN ) == 0)
sprintf(fn, "/usr/share/fonts/truetype/ttf-malayalam-fonts/Rachana_w01.ttf");
else if (strncmp(font_name, "utkal.ttf", FNLEN ) == 0)
sprintf(fn, "/usr/share/fonts/truetype/ttf-indic-fonts-core/utkal.ttf");
else if (strncmp(font_name, "Vemana.ttf", FNLEN ) == 0)
sprintf(fn, "/usr/share/fonts/truetype/ttf-indic-fonts-core/Vemena.ttf");
DEBUGCODE { fprintf(stderr, "LoadFont(): looking for %s\n in OS' font path\n", fn); }
/* try to load the font, if successful, return font*/
loaded_font = TTF_OpenFont(fn, font_size);
if (loaded_font != NULL)
return loaded_font;
/* We could not find desired font. If we were looking for something other */
/* than default (Andika) font, print warning and try to load default font: */
if (strncmp(font_name, DEFAULT_FONT_NAME, FNLEN ) != 0)
{
fprintf(stderr, "Warning - could not load desired font: %s\n", font_name);
fprintf(stderr, "Trying to load default instead: %s\n", DEFAULT_FONT_NAME);
return LoadFont(DEFAULT_FONT_NAME, font_size);
}
else /* Default failed also - bummer! */
{
fprintf(stderr, "LoadFont(): Error - couldn't load either selected or default font\n");
return NULL;
}
}
/***********************
LoadImage : Load an image and set transparent if requested
************************/
......@@ -424,10 +359,12 @@ Mix_Chunk* LoadSound(const char* datafile )
{
sprintf(fn , "%s/sounds/%s", settings.default_data_path, datafile);
tempChunk = Mix_LoadWAV(fn);
return tempChunk;
if (tempChunk)
return tempChunk;
}
// We never want to get here...
return tempChunk;
fprintf(stderr, "LoadSound() - could not load %s\n", datafile);
return NULL;
}
......
......@@ -843,16 +843,6 @@ static void calc_font_sizes(void)
fontsize = (screen->h)/28;
medfontsize = fontsize * 1.5;
bigfontsize = fontsize * 4;
/* When SDL_Pango is used, the above font sizes are ignored */
/* by BlackOutline(), so we adjust dpi to scale the fonts: */
/* HACK this isn't quite the intended use of SDLPango_SetDpi() */
/* NOTE this code has no effect if SDL_Pango not being used */
{
float dpi_x, dpi_y;
dpi_x = dpi_y = 125 * ((float)screen->h/(float)480);
reset_DPI_SDLPango_Context(dpi_x, dpi_y);
}
}
static int practice_load_media(void)
......@@ -898,13 +888,12 @@ static int practice_load_media(void)
errors_label_srfc = BlackOutline(_("Errors"), fontsize, &yellow);
accuracy_label_srfc = BlackOutline(_("Accuracy"), fontsize, &yellow);
/* Get out if anything failed to load: */
/* Get out if anything failed to load (except sounds): */
if (load_failed
||!hands
||!CurrentBkgd()
||!tux_win
||!tux_stand
||!wrong
||!keyboard
||!hand_shift[0]
||!hand_shift[1]
......@@ -945,8 +934,6 @@ static void print_load_results(void)
{ LOG("tux_win did not load\n");}
if (!tux_stand)
{ LOG("tux_stand did not load\n");}
if (!wrong)
{ LOG("wrong did not load\n");}
if (!keyboard)
{ LOG("keyboard did not load\n");}
if (!hand_shift[0])
......@@ -1188,10 +1175,6 @@ static void practice_unload_media(void)
if (wrong)
Mix_FreeChunk(wrong);
wrong = NULL;
/* Set the dpi back to default as our SDL_Pango font-scaling hack: */
/* NOTE this is a no-op if we aren't using SDL_Pango */
reset_DPI_SDLPango_Context(125, 125);
}
......@@ -1287,7 +1270,7 @@ static int find_next_wrap(const wchar_t* wstr, int font_size, int width)
{
wchar_t buf[MAX_PHRASE_LENGTH];
char UTF8buf[MAX_PHRASE_LENGTH];
SDL_Surface* s = NULL;
int word_end = -1;
int prev_word_end = -1;
......@@ -1295,7 +1278,6 @@ static int find_next_wrap(const wchar_t* wstr, int font_size, int width)
int phr_length = 0;
int test_w = 0; /* The width in pixels of the SDL-rendered string */
/* FIXME get rid of this once overhaul done: */
TTF_Font* font = LoadFont(DEFAULT_FONT_NAME , font_size);
LOG("Entering find__next_wrap\n");
......@@ -1306,12 +1288,6 @@ static int find_next_wrap(const wchar_t* wstr, int font_size, int width)
return -1;
}
if (!font)
{
fprintf(stderr, "find_next_wrap() - error - invalid font argument\n");
return -1;
}
DOUT(width);
DEBUGCODE{ fprintf(stderr, "wstr = %S\n", wstr);}
......@@ -1352,12 +1328,17 @@ static int find_next_wrap(const wchar_t* wstr, int font_size, int width)
/* Need to convert to UTF8 because couldn't get UNICODE version to work: */
ConvertToUTF8(buf, UTF8buf, MAX_PHRASE_LENGTH);
/* Now check width of string: */
if (-1 == TTF_SizeUTF8((TTF_Font*)font, UTF8buf, &test_w, NULL))
s = SimpleText(UTF8buf, font_size, &white);
if (!s)
{
/* An error occurred: */
return -1;
}
test_w = s->w;
SDL_FreeSurface(s);
s = NULL;
DOUT(test_w);
DOUT(width);
/* If we've gone past the width, the previous space was the wrap point, */
......
......@@ -1038,18 +1038,18 @@ static void run_script(void)
case itemTEXT:
{
TTF_Font* myFont;
// TTF_Font* myFont;
SDL_Surface* img;
SDL_Color* col;
int shown, toshow, w, h; // used to wrap text
int shown, toshow; // used to wrap text
char tmp[FNLEN]; // used to hold temp text for wrapping
/* --- create font & render text --- */
if (curItem->size > 0)
myFont = LoadFont(settings.theme_font_name, (int)curItem->size);
else
myFont = LoadFont(settings.theme_font_name, 24); // default size is 24
// if (curItem->size > 0)
// myFont = LoadFont(settings.theme_font_name, (int)curItem->size);
// else
// myFont = LoadFont(settings.theme_font_name, 24); // default size is 24
if (curItem->color)
col = curItem->color;
......@@ -1079,15 +1079,19 @@ static void run_script(void)
continue;
tmp[toshow] = 0;
TTF_SizeText(myFont, tmp, &w, &h);
if (w + 20 < screen->w)
ok = 1;
img = SimpleText(tmp, (int)curItem->size, col);
if (img)
{
if (img->w + 20 < screen->w)
ok = 1;
SDL_FreeSurface(img);
img = NULL;
}
}
shown += toshow + 1;
img = TTF_RenderUTF8_Blended(myFont, tmp, *col);
img = SimpleText(tmp, (int)curItem->size, col);
if (img)
{
......@@ -1122,13 +1126,12 @@ static void run_script(void)
}
/* --- and blit! --- */
SDL_BlitSurface( img, NULL, screen, &loc );
SDL_FreeSurface( img );
SDL_BlitSurface(img, NULL, screen, &loc);
SDL_FreeSurface(img);
}
} while (shown + 1 < strlen(curItem->data));
TTF_CloseFont(myFont);
break;
}
......
......@@ -157,39 +157,45 @@ void GraphicsInit(void)
LibInit : Init the SDL
library
*****************************/
void LibInit(Uint32 lib_flags)
/* NOTE lib_flags is *always* SDL_INIT_VIDEO|SDL_INIT_AUDIO - maybe we */
/* should just simplify all this: */
void LibInit(lib_flags)
{
LOG( "LibInit():\n-About to init SDL Library\n" );
if (SDL_Init(lib_flags) < 0)
/* FIXME this looks wrong - if no sys_sound, we don't init video??? */
if (settings.sys_sound) {
if (SDL_Init(SDL_INIT_VIDEO) < 0) {
fprintf(stderr, "Couldn't initialize SDL: %s\n",
SDL_GetError());
exit(2);
} else {
LOG( "Couldn't initialize SDL Sound\n" );
settings.sys_sound = 0;
}
}
// atexit(SDL_Quit); // fire and forget...
LOG( "-SDL Library init'd successfully\n" );
/* FIXME should read settings before we do this: */
if (settings.sys_sound)
{
if (Mix_OpenAudio(22050, AUDIO_S16, 1, 2048) == -1)
{
fprintf( stderr, "Warning: couldn't set 22050 Hz 8-bit audio\n - Reasons: %s\n", SDL_GetError());
settings.sys_sound=0;
}
else
LOG("Mix_OpenAudio() successful\n");
}
LOG( "LibInit():\n-About to init SDL Library\n" );
/* FIXME this looks wrong - if SDL_Init() fails, we try other subsystem??? */
if (SDL_Init(lib_flags) < 0)
/* FIXME this looks wrong - if no sys_sound, we don't init video??? */
if (settings.sys_sound)
{
if (SDL_Init(SDL_INIT_VIDEO) < 0)
{
fprintf(stderr, "Couldn't initialize SDL: %s\n",
SDL_GetError());
exit(2);
}
else
{
LOG( "Couldn't initialize SDL Sound\n" );
settings.sys_sound = 0;
}
}
// atexit(SDL_Quit); // fire and forget...
LOG( "-SDL Library init'd successfully\n" );
/* FIXME should read settings before we do this: */
if (settings.sys_sound)
{
if (Mix_OpenAudio(22050, AUDIO_S16, 1, 2048) == -1)
{
fprintf( stderr, "Warning: couldn't set 22050 Hz 8-bit audio\n - Reasons: %s\n", SDL_GetError());
settings.sys_sound=0;
}
else
LOG("Mix_OpenAudio() successful\n");
}
LOG( "-about to init SDL text library (SDL_ttf or SDL_Pango\n" );
......@@ -198,15 +204,13 @@ void LibInit(Uint32 lib_flags)
fprintf( stderr, "Couldn't initialize desired SDL text libary\n" );
exit(2);
}
/* FIXME get rid of this as soon as text overhaul done: */
TTF_Init();
// atexit(TTF_Quit);
SDL_EnableKeyRepeat( 0, SDL_DEFAULT_REPEAT_INTERVAL );
/* Need this to get Unicode values from keysyms: */
SDL_EnableUNICODE(1);
SDL_EnableKeyRepeat( 0, SDL_DEFAULT_REPEAT_INTERVAL );
/* Need this to get Unicode values from keysyms: */
SDL_EnableUNICODE(1);
LOG( "LibInit():END\n" );
LOG( "LibInit():END\n" );
}
/* Load the settings from a file... make sure to update SaveSettings if you change
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment