From: Matthew Mondor Date: Mon, 8 Jan 2007 11:46:57 +0000 (+0000) Subject: *** empty log message *** X-Git-Tag: pgsql-branch-merge~36 X-Git-Url: http://git.pulsar-zone.net/?a=commitdiff_plain;h=540930230707b79a7fe2ad4db505dd6927953062;p=mmondor.git *** empty log message *** --- diff --git a/mmsoftware/paradise_adventure/src/main.c b/mmsoftware/paradise_adventure/src/main.c index 2ed4518..9a90954 100644 --- a/mmsoftware/paradise_adventure/src/main.c +++ b/mmsoftware/paradise_adventure/src/main.c @@ -1,4 +1,4 @@ -/* $Id: main.c,v 1.8 2007/01/08 10:46:16 mmondor Exp $ */ +/* $Id: main.c,v 1.9 2007/01/08 11:46:57 mmondor Exp $ */ /* * Copyright (c) 2006, Matthew Mondor @@ -17,6 +17,7 @@ #include #include #include +#include /* APPLICATION HEADERS */ #include @@ -27,11 +28,19 @@ /* DEFINITIONS */ +#define FADEOUT_DELAY 1000 + struct scene { const char *img, *mus; int vol; }; +struct font { + const char *name; + int pt; + TTF_Font *fnt; +}; + /* PRIVATE PROTOTYPES */ @@ -42,6 +51,9 @@ static void screen_draw(void); static void scene_switch(const char *, const char *, int); static void scene_next(void); +static void fonts_load(void); +static TTF_Font *font_next(void); + /* PUBLIC GLOBALS */ @@ -69,6 +81,20 @@ static const struct scene scenes[] = { }; static int curscene = 0; +static struct font fonts[] = { + { "celtic", 14, NULL }, + { "charming", 20, NULL }, + { "darkcrystal", 12, NULL }, + { "deloise", 18, NULL }, /* nice */ + { "ironcarved", 16, NULL }, + { "oldroman", 12, NULL }, + { "santana", 14, NULL }, + { "script", 18, NULL }, /* nice */ + { NULL, 0, NULL } +}; +static int curfont = 0; +static SDL_Color fontcol = { 0x00, 0x00, 0x00 }; + /* PRIVATE FUNCTIONS */ @@ -122,6 +148,11 @@ main(int argc, char **argv) (void) Mix_AllocateChannels(4); (void) Mix_ReserveChannels(2); + /* + * TTF + */ + fonts_load(); + /* XXX */ screen_draw(); scene_next(); @@ -154,8 +185,8 @@ main(int argc, char **argv) } /* Fadeout music */ - (void) Mix_FadeOutMusic(2000); - SDL_Delay(2000); + (void) Mix_FadeOutMusic(FADEOUT_DELAY); + SDL_Delay(FADEOUT_DELAY); exit(EXIT_SUCCESS); } @@ -166,7 +197,7 @@ screen_draw(void) SDL_Rect r; (void) SDL_BlitSurface(img_border, NULL, screen_surface, NULL); - r = (struct SDL_Rect){ 798, 16, 0, 0 }; + r = (SDL_Rect){ 798, 16, 0, 0 }; (void) SDL_BlitSurface(img_textarea, NULL, screen_surface, &r); if (img_painting != NULL) { r = (SDL_Rect){ 16, 16, 0, 0 }; @@ -196,8 +227,8 @@ scene_switch(const char *img, const char *mus, int vol) if (strcasecmp(mus, music_file) != 0) { music_new = 1; if (music != NULL) { - (void) Mix_FadeOutMusic(2000); - SDL_Delay(2000); + (void) Mix_FadeOutMusic(FADEOUT_DELAY); + SDL_Delay(FADEOUT_DELAY); } (void) Mix_HaltMusic(); } @@ -255,6 +286,7 @@ scene_switch(const char *img, const char *mus, int vol) static void scene_next(void) { + SDL_Surface *s; if (scenes[curscene].img == NULL) curscene = 0; @@ -262,4 +294,47 @@ scene_next(void) scene_switch(scenes[curscene].img, scenes[curscene].mus, scenes[curscene].vol); curscene++; + + if ((s = TTF_RenderText_Blended(font_next(), "A Paradise Adventure!", + fontcol)) != NULL) { + SDL_Rect r; + + r = (SDL_Rect){ 798, 16, 0, 0 }; + (void) SDL_BlitSurface(img_textarea, NULL, screen_surface, &r); + r = (SDL_Rect){ 832, 32, 0, 0 }; + (void) SDL_BlitSurface(s, NULL, screen_surface, &r); + SDL_FreeSurface(s); + } +} + +static void +fonts_load(void) +{ + int i; + char path[1024]; + + if (TTF_Init() == -1) { + (void) fprintf(stderr, "fonts_load() - TTF_Init() - %s", + TTF_GetError()); + exit(EXIT_FAILURE); + } + + for (i = 0; fonts[i].name != NULL; i++) { + (void) snprintf(path, 1023, "font/%s.ttf", fonts[i].name); + if ((fonts[i].fnt = TTF_OpenFont(path, fonts[i].pt)) == NULL) { + (void) fprintf(stderr, + "fonts_load() - %s - %s", path, TTF_GetError()); + exit(EXIT_FAILURE); + } + } +} + +static TTF_Font * +font_next(void) +{ + + if (fonts[curfont].name == NULL) + curfont = 0; + + return fonts[curfont++].fnt; }